summaryrefslogtreecommitdiff
path: root/src/ScreenPlacement.hh
blob: 05db90d70ad6d550f963dfe9712b32b1c3f8df5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// ScreenPlacement.hh
// Copyright (c) 2006 Fluxbox Team (fluxgen at fluxbox dot org)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

#ifndef SCREENPLACEMENT_HH
#define SCREENPLACEMENT_HH

#include "PlacementStrategy.hh"
#include "FbTk/Resource.hh"

#include <memory>

namespace FbTk {
    class Menu;
}
class BScreen;

/**
 * Main class for strategy handling
 * This is a bridge between screen and 
 * the real placement strategy (rowcol, undermouse etc)
 * The placeWindow function in this class is guaranteed to succeed.
 * It holds a pointer to the real placement strategy which is
 * called upon placeWindow, it also holds the placement resources
 */
class ScreenPlacement: public PlacementStrategy {
public:
    enum PlacementPolicy { 
        ROWSMARTPLACEMENT, 
        COLSMARTPLACEMENT,
        COLMINOVERLAPPLACEMENT,
        ROWMINOVERLAPPLACEMENT,
        CASCADEPLACEMENT,
        UNDERMOUSEPLACEMENT
    };

    enum RowDirection { 
        LEFTRIGHT, ///< from left to right
        RIGHTLEFT  ///< from right to left
    };
    enum ColumnDirection { 
        TOPBOTTOM,  ///< from top to bottom
        BOTTOMTOP   ///< from bottom to top
    };

    explicit ScreenPlacement(BScreen &screen);

    virtual ~ScreenPlacement() {}
    /// placeWindow is guaranteed to succeed, ignore return value
    /// @return true
    bool placeWindow(const FluxboxWindow &window, int head,
                     int &place_x, int &place_y);

    // places and show 'menu' at 'x','y'
    void placeAndShowMenu(FbTk::Menu& menu, int x, int y, bool respect_struts);

    PlacementPolicy placementPolicy() const { return *m_placement_policy; }
    RowDirection rowDirection() const { return *m_row_direction; }
    ColumnDirection colDirection() const { return *m_col_direction; }

private:
    FbTk::Resource<RowDirection> m_row_direction; ///< row direction resource
    FbTk::Resource<ColumnDirection> m_col_direction; ///< column direction resource
    FbTk::Resource<PlacementPolicy> m_placement_policy; ///< placement policy resource
    PlacementPolicy m_old_policy; ///< holds old policy, used to determine if resources has changed
    std::auto_ptr<PlacementStrategy> m_strategy; ///< main strategy
    std::auto_ptr<PlacementStrategy> m_fallback_strategy; ///< a fallback strategy if the main strategy fails
    BScreen& m_screen;
};

#endif // SCREENPLACEMENT_HH