1 // WindowState.hh 2 // Copyright (c) 2008 Fluxbox Team (fluxgen at fluxbox dot org) 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 22 #ifndef WINDOWSTATE_HH 23 #define WINDOWSTATE_HH 24 25 #include "Layer.hh" 26 27 #include <X11/Xlib.h> 28 #include <X11/Xutil.h> 29 30 #include <string> 31 32 class SizeHints { 33 public: SizeHints()34 SizeHints(): 35 min_width(1), max_width(0), min_height(1), max_height(0), 36 width_inc(1), height_inc(1), base_width(0), base_height(0), 37 min_aspect_x(0), max_aspect_x(1), 38 min_aspect_y(1), max_aspect_y(0), 39 win_gravity(0) { } 40 41 void reset(const XSizeHints &sizehint); 42 43 void apply(unsigned int &w, unsigned int &h, 44 bool maximizing = false) const; 45 bool valid(unsigned int width, unsigned int height) const; 46 void displaySize(unsigned int &i, unsigned int &j, 47 unsigned int width, unsigned int height) const; 48 49 bool isResizable() const; 50 51 unsigned int min_width, max_width, min_height, max_height, 52 width_inc, height_inc, base_width, base_height, 53 min_aspect_x, max_aspect_x, min_aspect_y, max_aspect_y; 54 int win_gravity; 55 }; 56 57 class WindowState { 58 public: 59 60 /** 61 * Types of maximization 62 */ 63 enum MaximizeMode { 64 MAX_NONE = 0, ///< normal state 65 MAX_HORZ = 1, ///< maximize horizontal 66 MAX_VERT = 2, ///< maximize vertical 67 MAX_FULL = 3 ///< maximize full 68 }; 69 70 /** 71 This enumeration represents individual decoration 72 attributes, they can be OR-d together to get a mask. 73 Useful for saving. 74 */ 75 enum DecorationMask { 76 DECORM_TITLEBAR = (1<<0), 77 DECORM_HANDLE = (1<<1), 78 DECORM_BORDER = (1<<2), 79 DECORM_ICONIFY = (1<<3), 80 DECORM_MAXIMIZE = (1<<4), 81 DECORM_CLOSE = (1<<5), 82 DECORM_MENU = (1<<6), 83 DECORM_STICKY = (1<<7), 84 DECORM_SHADE = (1<<8), 85 DECORM_TAB = (1<<9), 86 DECORM_ENABLED = (1<<10), 87 DECORM_LAST = (1<<11) // useful for getting "All" 88 }; 89 90 enum Decoration { 91 DECOR_NONE = 0, 92 DECOR_NORMAL = DECORM_LAST - 1, 93 DECOR_TINY = DECORM_TITLEBAR|DECORM_ICONIFY, 94 DECOR_TOOL = DECORM_TITLEBAR, 95 DECOR_BORDER = DECORM_BORDER, 96 DECOR_TAB = DECORM_BORDER|DECORM_TAB 97 }; 98 99 enum WindowType { 100 TYPE_NORMAL, 101 TYPE_DOCK, 102 TYPE_DESKTOP, 103 TYPE_SPLASH, 104 TYPE_DIALOG, 105 TYPE_MENU, 106 TYPE_TOOLBAR 107 }; 108 WindowState()109 WindowState(): 110 size_hints(), 111 deco_mask(DECOR_NORMAL), 112 type(TYPE_NORMAL), 113 focused(false), 114 shaded(false), fullscreen(false), stuck(false), iconic(false), 115 focus_hidden(false), icon_hidden(false), 116 maximized(0), layernum(ResourceLayer::NORMAL), 117 x(0), y(0), width(1), height(1) { } 118 119 void saveGeometry(int x, int y, unsigned int width, unsigned int height, 120 bool force = false); 121 122 // returns what the state should be set to, without actually setting it 123 int queryToggleMaximized(int type) const; 124 125 bool useBorder() const; 126 bool useHandle() const; 127 bool useTabs() const; 128 bool useTitlebar() const; 129 isMaximized() const130 bool isMaximized() const { return maximized == MAX_FULL; } isMaximizedHorz() const131 bool isMaximizedHorz() const { return maximized & MAX_HORZ; } isMaximizedVert() const132 bool isMaximizedVert() const { return maximized & MAX_VERT; } 133 134 static int getDecoMaskFromString(const std::string &str); 135 136 SizeHints size_hints; 137 unsigned int deco_mask; 138 WindowType type; 139 bool focused, shaded, fullscreen, stuck, iconic, focus_hidden, icon_hidden; 140 int maximized, layernum; 141 int x, y; 142 unsigned int width, height; 143 }; 144 145 #endif // WINDOWSTATE_HH 146