]> icculus.org git repositories - mikachu/openbox.git/blob - src/Screen.h
make a new autoRaiseDelay value take effect without having to restart
[mikachu/openbox.git] / src / Screen.h
1 // Screen.h for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 #ifndef   __Screen_hh
24 #define   __Screen_hh
25
26 #include <X11/Xlib.h>
27 #include <X11/Xresource.h>
28
29 #ifdef    TIME_WITH_SYS_TIME
30 #  include <sys/time.h>
31 #  include <time.h>
32 #else // !TIME_WITH_SYS_TIME
33 #  ifdef    HAVE_SYS_TIME_H
34 #    include <sys/time.h>
35 #  else // !HAVE_SYS_TIME_H
36 #    include <time.h>
37 #  endif // HAVE_SYS_TIME_H
38 #endif // TIME_WITH_SYS_TIME
39
40 #include "BaseDisplay.h"
41 #include "Configmenu.h"
42 #include "Iconmenu.h"
43 #include "Netizen.h"
44 #include "Rootmenu.h"
45 #include "Timer.h"
46 #include "Workspace.h"
47 #include "Workspacemenu.h"
48 #include "openbox.h"
49 #ifdef    SLIT
50 #  include "Slit.h"
51 #endif // SLIT
52 #include "Image.h"
53 #include "Resource.h"
54 #include "Util.h"
55
56 #include <list>
57 #include <vector>
58
59 // forward declaration
60 class BScreen;
61
62 struct WindowStyle {
63   BColor f_focus, f_unfocus, l_text_focus, l_text_unfocus, b_pic_focus,
64     b_pic_unfocus;
65   BTexture t_focus, t_unfocus, l_focus, l_unfocus, h_focus, h_unfocus,
66     b_focus, b_unfocus, b_pressed, g_focus, g_unfocus;
67   GC l_text_focus_gc, l_text_unfocus_gc, b_pic_focus_gc, b_pic_unfocus_gc;
68
69   XFontSet fontset;
70   XFontSetExtents *fontset_extents;
71   XFontStruct *font;
72   
73   int justify;
74 };
75
76 struct ToolbarStyle {
77   BColor l_text, w_text, c_text, b_pic;
78   BTexture toolbar, label, window, button, pressed, clock;
79   GC l_text_gc, w_text_gc, c_text_gc, b_pic_gc;
80
81   XFontSet fontset;
82   XFontSetExtents *fontset_extents;
83   XFontStruct *font;
84   
85   int justify;
86 };
87
88 struct MenuStyle {
89   BColor t_text, f_text, h_text, d_text;
90   BTexture title, frame, hilite;
91   GC t_text_gc, f_text_gc, h_text_gc, d_text_gc, hilite_gc;
92
93   XFontSet t_fontset, f_fontset;
94   XFontSetExtents *t_fontset_extents, *f_fontset_extents;
95   XFontStruct *t_font, *f_font;
96
97   int t_justify, f_justify, bullet, bullet_pos;
98 };
99
100
101 class BScreen : public ScreenInfo {
102 private:
103   Bool root_colormap_installed, managed, geom_visible;
104   GC opGC;
105   Pixmap geom_pixmap;
106   Window geom_window;
107
108   Openbox &openbox;
109   Resource &config;
110   BImageControl *image_control;
111   Configmenu *configmenu;
112   Iconmenu *iconmenu;
113   Rootmenu *rootmenu;
114
115   typedef std::list<Rootmenu *> menuList;
116   menuList rootmenuList;
117   typedef std::list<Netizen *> netList;
118   netList netizenList;
119   typedef std::list<OpenboxWindow *> winList;
120   winList iconList;     // winList is declared in Workspace.h
121
122 #ifdef    SLIT
123   Slit *slit;
124 #endif // SLIT
125
126   Toolbar *toolbar;
127   Workspace *current_workspace;
128   Workspacemenu *workspacemenu;
129
130   unsigned int geom_w, geom_h;
131   unsigned long event_mask;
132
133   typedef std::vector<std::string> wkspNameList;
134   wkspNameList workspaceNames;
135   typedef std::vector<Workspace *> wkspList;
136   wkspList workspacesList;
137
138   struct resource {
139     WindowStyle wstyle;
140     ToolbarStyle tstyle;
141     MenuStyle mstyle;
142
143     bool sloppy_focus, auto_raise, auto_edge_balance, focus_last,
144       ordered_dither, opaque_move, hide_toolbar, full_max, focus_new;
145     BColor border_color;
146     Resource styleconfig;
147
148     int workspaces, placement_policy, edge_snap_threshold, row_direction,
149       col_direction;
150
151     unsigned int handle_width, bevel_width, frame_width, border_width;
152     int zones; // number of zones to be used when alt-resizing a window
153
154 #ifdef    HAVE_STRFTIME
155     char *strftime_format;
156 #else // !HAVE_STRFTIME
157     bool clock24hour;
158     int date_format;
159 #endif // HAVE_STRFTIME
160
161     char *root_command;
162   } resource;
163
164
165 protected:
166   Bool parseMenuFile(FILE *, Rootmenu *);
167
168   void readDatabaseTexture(const char *, const char *, BTexture *,
169                            unsigned long);
170   void readDatabaseColor(const char *, const char *, BColor *, unsigned long);
171
172   void readDatabaseFontSet(const char *, const char *, XFontSet *);
173   XFontSet createFontSet(const char *);
174   void readDatabaseFont(const char *, const char *, XFontStruct **);
175
176   void InitMenu();
177   void LoadStyle();
178
179
180 public:
181   BScreen(Openbox &, int, Resource &);
182   ~BScreen();
183
184   inline const Bool &isScreenManaged() const { return managed; }
185   inline const GC &getOpGC() const { return opGC; }
186
187   inline Openbox &getOpenbox() { return openbox; }
188   inline BColor *getBorderColor() { return &resource.border_color; }
189   inline BImageControl *getImageControl() { return image_control; }
190   inline Rootmenu *getRootmenu() { return rootmenu; }
191
192 #ifdef   SLIT
193   inline Slit *getSlit() { return slit; }
194 #endif // SLIT
195
196   inline Toolbar *getToolbar() { return toolbar; }
197
198   Rect availableArea() const;
199   
200   inline Workspace *getWorkspace(unsigned int w) {
201     ASSERT(w < workspacesList.size());
202     return workspacesList[w];
203   }
204   inline Workspace *getCurrentWorkspace() { return current_workspace; }
205
206   inline Workspacemenu *getWorkspacemenu() { return workspacemenu; }
207   
208   inline void iconUpdate() { iconmenu->update(); }
209
210   inline const unsigned int &getHandleWidth() const
211   { return resource.handle_width; }
212   inline const unsigned int &getBevelWidth() const
213   { return resource.bevel_width; }
214   inline const unsigned int &getFrameWidth() const
215   { return resource.frame_width; }
216   inline const unsigned int &getBorderWidth() const
217   { return resource.border_width; }
218
219   inline const int getCurrentWorkspaceID()
220   { return current_workspace->getWorkspaceID(); }
221   inline const int getWorkspaceCount() { return workspacesList.size(); }
222   inline const int getIconCount() { return iconList.size(); }
223
224   inline const Bool &isRootColormapInstalled() const
225     { return root_colormap_installed; }
226   inline void setRootColormapInstalled(Bool r) { root_colormap_installed = r; }
227   
228   inline bool sloppyFocus() const { return resource.sloppy_focus; }
229   void setSloppyFocus(bool s);
230   
231   inline bool autoRaise() const { return resource.auto_raise; }
232   void setAutoRaise(bool a);
233   
234   inline bool imageDither() const { return image_control->doDither(); }
235   void setImageDither(bool d, bool reconfig = true);
236   
237   inline bool orderedDither() const { return resource.ordered_dither; }
238   
239   inline bool opaqueMove() const { return resource.opaque_move; }
240   void setOpaqueMove(bool o);
241   
242   inline bool fullMax() const { return resource.full_max; }
243   void setFullMax(bool f);
244   
245   inline bool focusNew() const { return resource.focus_new; }
246   void setFocusNew(bool f);
247   
248   inline bool focusLast() const { return resource.focus_last; }
249   void setFocusLast(bool f);
250   
251   inline int getWindowZones() const { return resource.zones; }
252   void setWindowZones(int z);
253   
254   inline int workspaceCount() const { return resource.workspaces; }
255   void setWorkspaceCount(int w);
256
257   inline int placementPolicy() const { return resource.placement_policy; }
258   void setPlacementPolicy(int p);
259
260   inline int edgeSnapThreshold() const { return resource.edge_snap_threshold; }
261   void setEdgeSnapThreshold(int t);
262   
263   inline int rowPlacementDirection() const { return resource.row_direction; }
264   void setRowPlacementDirection(int d);
265   
266   inline int colPlacementDirection() const { return resource.col_direction; }
267   void setColPlacementDirection(int d);
268   
269   inline char *rootCommand() const { return resource.root_command; }
270   inline void setRootCommand(const char *cmd);
271   
272 #ifdef    HAVE_STRFTIME
273   inline char *strftimeFormat() { return resource.strftime_format; }
274   void setStrftimeFormat(const char *);
275 #else // !HAVE_STRFTIME
276   inline int dateFormat() { return resource.date_format; }
277   void setDateFormat(int f);
278   inline bool clock24Hour() { return resource.clock24hour; }
279   void setClock24Hour(Bool c);
280 #endif // HAVE_STRFTIME
281
282   inline bool hideToolbar() const { return resource.hide_toolbar; }
283   void setHideToolbar(bool);
284
285   inline WindowStyle *getWindowStyle() { return &resource.wstyle; }
286   inline MenuStyle *getMenuStyle() { return &resource.mstyle; }
287   inline ToolbarStyle *getToolbarStyle() { return &resource.tstyle; }
288
289   OpenboxWindow *getIcon(int);
290
291   int addWorkspace();
292   int removeLastWorkspace();
293
294   void removeWorkspaceNames();
295   void addWorkspaceName(const char *);
296   void saveWorkspaceNames();
297   void addNetizen(Netizen *);
298   void removeNetizen(Window);
299   void addIcon(OpenboxWindow *);
300   void removeIcon(OpenboxWindow *);
301   const char *getNameOfWorkspace(int);
302   void changeWorkspaceID(int);
303   void raiseWindows(Window *, int);
304   void reassociateWindow(OpenboxWindow *, int, Bool);
305   void prevFocus();
306   void nextFocus();
307   void raiseFocus();
308   void reconfigure();
309   void load();
310   void save();
311   void rereadMenu();
312   void shutdown();
313   void showPosition(int, int);
314   void showGeometry(unsigned int, unsigned int);
315   void hideGeometry();
316   void updateNetizenCurrentWorkspace();
317   void updateNetizenWorkspaceCount();
318   void updateNetizenWindowFocus();
319   void updateNetizenWindowAdd(Window, unsigned long);
320   void updateNetizenWindowDel(Window);
321   void updateNetizenConfigNotify(XEvent *);
322   void updateNetizenWindowRaise(Window);
323   void updateNetizenWindowLower(Window);
324
325   enum { RowSmartPlacement = 1, ColSmartPlacement, CascadePlacement,
326          BestFitPlacement, UnderMousePlacement, ClickMousePlacement,
327          LeftRight, RightLeft, TopBottom, BottomTop };
328   enum { LeftJustify = 1, RightJustify, CenterJustify };
329   enum { RoundBullet = 1, TriangleBullet, SquareBullet, NoBullet };
330   enum { Restart = 1, RestartOther, Exit, Shutdown, Execute, Reconfigure,
331          WindowShade, WindowIconify, WindowMaximize, WindowClose, WindowRaise,
332          WindowLower, WindowStick, WindowKill, SetStyle };
333 };
334
335
336 #endif // __Screen_hh