aboutsummaryrefslogtreecommitdiff
path: root/src/WindowState.hh
blob: ea9b63568165f8265812a4ae82640978261d7fc4 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// WindowState.hh
// Copyright (c) 2008 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 WINDOWSTATE_HH
#define WINDOWSTATE_HH

#include <X11/Xutil.h>

#include <string>

class SizeHints {
public:
    SizeHints():
        min_width(1), max_width(0), min_height(1), max_height(0),
        width_inc(1), height_inc(1), base_width(0), base_height(0),
        min_aspect_x(0), max_aspect_x(1),
        min_aspect_y(1), max_aspect_y(0),
        win_gravity(0) { }

    void reset(const XSizeHints &sizehint);

    void apply(unsigned int &w, unsigned int &h,
               bool maximizing = false) const;
    bool valid(unsigned int width, unsigned int height) const;
    void displaySize(unsigned int &i, unsigned int &j,
                     unsigned int width, unsigned int height) const;

    bool isResizable() const;

    unsigned int min_width, max_width, min_height, max_height,
                 width_inc, height_inc, base_width, base_height,
                 min_aspect_x, max_aspect_x, min_aspect_y, max_aspect_y;
    int win_gravity;
};

class WindowState {
public:

    /**
     * Types of maximization
     */
    enum MaximizeMode {
        MAX_NONE = 0, ///< normal state
        MAX_HORZ = 1, ///< maximize horizontal
        MAX_VERT = 2, ///< maximize vertical
        MAX_FULL = 3  ///< maximize full
    };

    /**
       This enumeration represents individual decoration
       attributes, they can be OR-d together to get a mask.
       Useful for saving.
    */
    enum DecorationMask {
        DECORM_TITLEBAR = (1<<0),
        DECORM_HANDLE   = (1<<1),
        DECORM_BORDER   = (1<<2),
        DECORM_ICONIFY  = (1<<3),
        DECORM_MAXIMIZE = (1<<4),
        DECORM_CLOSE    = (1<<5),
        DECORM_MENU     = (1<<6),
        DECORM_STICKY   = (1<<7),
        DECORM_SHADE    = (1<<8),
        DECORM_TAB      = (1<<9),
        DECORM_ENABLED  = (1<<10),
        DECORM_LAST     = (1<<11) // useful for getting "All"
    };

    enum Decoration {
        DECOR_NONE = 0,
        DECOR_NORMAL = DECORM_LAST - 1,
        DECOR_TINY = DECORM_TITLEBAR|DECORM_ICONIFY|DECORM_MENU|DECORM_TAB,
        DECOR_TOOL = DECORM_TITLEBAR|DECORM_MENU,
        DECOR_BORDER = DECORM_BORDER|DECORM_MENU,
        DECOR_TAB = DECORM_BORDER|DECORM_MENU|DECORM_TAB
    };

    WindowState():
        size_hints(),
        deco_mask(DECOR_NORMAL),
        focused(false),
        shaded(false), fullscreen(false), maximized(0),
        x(0), y(0), width(1), height(1) { }

    void saveGeometry(int x, int y, unsigned int width, unsigned int height,
                      bool force = false);

    // returns what the state should be set to, without actually setting it
    int queryToggleMaximized(int type) const;

    bool useBorder() const;
    bool useHandle() const;
    bool useTabs() const;
    bool useTitlebar() const;

    bool isMaximized() const { return maximized == MAX_FULL; }
    bool isMaximizedHorz() const { return (bool)(maximized & MAX_HORZ); }
    bool isMaximizedVert() const { return (bool)(maximized & MAX_VERT); }

    static int getDecoMaskFromString(const std::string &str);

    SizeHints size_hints;
    unsigned int deco_mask;
    bool focused, shaded, fullscreen;
    int maximized;
    int x, y;
    unsigned int width, height;
};

#endif // WINDOWSTATE_HH