]> icculus.org git repositories - mikachu/openbox.git/blob - src/Screen.h
converted the remaining LinkedLists in Screen to STL objects.
[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 typedef std::list<Rootmenu *> menuList;
59 typedef std::list<Netizen *> netList;
60 typedef std::vector<Workspace *> wkspList;
61 typedef std::vector<std::string> wkspNameList;
62
63 // forward declaration
64 class BScreen;
65
66 struct WindowStyle {
67   BColor f_focus, f_unfocus, l_text_focus, l_text_unfocus, b_pic_focus,
68     b_pic_unfocus;
69   BTexture t_focus, t_unfocus, l_focus, l_unfocus, h_focus, h_unfocus,
70     b_focus, b_unfocus, b_pressed, g_focus, g_unfocus;
71   GC l_text_focus_gc, l_text_unfocus_gc, b_pic_focus_gc, b_pic_unfocus_gc;
72
73   XFontSet fontset;
74   XFontSetExtents *fontset_extents;
75   XFontStruct *font;
76   
77   int justify;
78 };
79
80 struct ToolbarStyle {
81   BColor l_text, w_text, c_text, b_pic;
82   BTexture toolbar, label, window, button, pressed, clock;
83   GC l_text_gc, w_text_gc, c_text_gc, b_pic_gc;
84
85   XFontSet fontset;
86   XFontSetExtents *fontset_extents;
87   XFontStruct *font;
88   
89   int justify;
90 };
91
92 struct MenuStyle {
93   BColor t_text, f_text, h_text, d_text;
94   BTexture title, frame, hilite;
95   GC t_text_gc, f_text_gc, h_text_gc, d_text_gc, hilite_gc;
96
97   XFontSet t_fontset, f_fontset;
98   XFontSetExtents *t_fontset_extents, *f_fontset_extents;
99   XFontStruct *t_font, *f_font;
100
101   int t_justify, f_justify, bullet, bullet_pos;
102 };
103
104
105 class BScreen : public ScreenInfo {
106 private:
107   Bool root_colormap_installed, managed, geom_visible;
108   GC opGC;
109   Pixmap geom_pixmap;
110   Window geom_window;
111
112   Openbox &openbox;
113   Resource &config;
114   BImageControl *image_control;
115   Configmenu *configmenu;
116   Iconmenu *iconmenu;
117   Rootmenu *rootmenu;
118
119   menuList rootmenuList;
120   netList netizenList;
121   winList iconList;     // winList is declared in Workspace.h
122
123 #ifdef    SLIT
124   Slit *slit;
125 #endif // SLIT
126
127   Toolbar *toolbar;
128   Workspace *current_workspace;
129   Workspacemenu *workspacemenu;
130
131   unsigned int geom_w, geom_h;
132   unsigned long event_mask;
133
134   wkspNameList workspaceNames;
135   wkspList workspacesList;
136
137   struct resource {
138     WindowStyle wstyle;
139     ToolbarStyle tstyle;
140     MenuStyle mstyle;
141
142     bool sloppy_focus, auto_raise, auto_edge_balance, focus_last,
143       ordered_dither, opaque_move, hide_toolbar, full_max, focus_new;
144     BColor border_color;
145     Resource styleconfig;
146
147     int workspaces, placement_policy, edge_snap_threshold, row_direction,
148       col_direction;
149
150     unsigned int handle_width, bevel_width, frame_width, border_width;
151     int zones; // number of zones to be used when alt-resizing a window
152
153 #ifdef    HAVE_STRFTIME
154     char *strftime_format;
155 #else // !HAVE_STRFTIME
156     bool clock24hour;
157     int date_format;
158 #endif // HAVE_STRFTIME
159
160     char *root_command;
161   } resource;
162
163
164 protected:
165   Bool parseMenuFile(FILE *, Rootmenu *);
166
167   void readDatabaseTexture(const char *, const char *, BTexture *,
168                            unsigned long);
169   void readDatabaseColor(const char *, const char *, BColor *, unsigned long);
170
171   void readDatabaseFontSet(const char *, const char *, XFontSet *);
172   XFontSet createFontSet(const char *);
173   void readDatabaseFont(const char *, const char *, XFontStruct **);
174
175   void InitMenu();
176   void LoadStyle();
177
178
179 public:
180   BScreen(Openbox &, int, Resource &);
181   ~BScreen();
182
183   inline const Bool &isScreenManaged() const { return managed; }
184   inline const GC &getOpGC() const { return opGC; }
185
186   inline Openbox &getOpenbox() { return openbox; }
187   inline BColor *getBorderColor() { return &resource.border_color; }
188   inline BImageControl *getImageControl() { return image_control; }
189   inline Rootmenu *getRootmenu() { return rootmenu; }
190
191 #ifdef   SLIT
192   inline Slit *getSlit() { return slit; }
193 #endif // SLIT
194
195   inline Toolbar *getToolbar() { return toolbar; }
196
197   Rect availableArea() const;
198   
199   inline Workspace *getWorkspace(int w) {
200     ASSERT(w < workspacesList.size());
201     return workspacesList[w];
202   }
203   inline Workspace *getCurrentWorkspace() { return current_workspace; }
204
205   inline Workspacemenu *getWorkspacemenu() { return workspacemenu; }
206   
207   inline void iconUpdate() { iconmenu->update(); }
208
209   inline const unsigned int &getHandleWidth() const
210   { return resource.handle_width; }
211   inline const unsigned int &getBevelWidth() const
212   { return resource.bevel_width; }
213   inline const unsigned int &getFrameWidth() const
214   { return resource.frame_width; }
215   inline const unsigned int &getBorderWidth() const
216   { return resource.border_width; }
217
218   inline const int getCurrentWorkspaceID()
219   { return current_workspace->getWorkspaceID(); }
220   inline const int getWorkspaceCount() { return workspacesList.size(); }
221   inline const int getIconCount() { return iconList.size(); }
222
223   inline const Bool &isRootColormapInstalled() const
224     { return root_colormap_installed; }
225   inline void setRootColormapInstalled(Bool r) { root_colormap_installed = r; }
226   
227   inline bool sloppyFocus() const { return resource.sloppy_focus; }
228   void setSloppyFocus(bool s);
229   
230   inline bool autoRaise() const { return resource.auto_raise; }
231   void setAutoRaise(bool a);
232   
233   inline bool imageDither() const { return image_control->doDither(); }
234   void setImageDither(bool d, bool reconfig = true);
235   
236   inline bool orderedDither() const { return resource.ordered_dither; }
237   
238   inline bool opaqueMove() const { return resource.opaque_move; }
239   void setOpaqueMove(bool o);
240   
241   inline bool fullMax() const { return resource.full_max; }
242   void setFullMax(bool f);
243   
244   inline bool focusNew() const { return resource.focus_new; }
245   void setFocusNew(bool f);
246   
247   inline bool focusLast() const { return resource.focus_last; }
248   void setFocusLast(bool f);
249   
250   inline int getWindowZones() const { return resource.zones; }
251   void setWindowZones(int z);
252   
253   inline int workspaceCount() const { return resource.workspaces; }
254   void setWorkspaceCount(int w);
255
256   inline int placementPolicy() const { return resource.placement_policy; }
257   void setPlacementPolicy(int p);
258
259   inline int edgeSnapThreshold() const { return resource.edge_snap_threshold; }
260   void setEdgeSnapThreshold(int t);
261   
262   inline int rowPlacementDirection() const { return resource.row_direction; }
263   void setRowPlacementDirection(int d);
264   
265   inline int colPlacementDirection() const { return resource.col_direction; }
266   void setColPlacementDirection(int d);
267   
268   inline char *rootCommand() const { return resource.root_command; }
269   inline void setRootCommand(const char *cmd);
270   
271 #ifdef    HAVE_STRFTIME
272   inline char *strftimeFormat() { return resource.strftime_format; }
273   void setStrftimeFormat(const char *);
274 #else // !HAVE_STRFTIME
275   inline int dateFormat() { return resource.date_format; }
276   void setDateFormat(int f);
277   inline bool clock24Hour() { return resource.clock24hour; }
278   void setClock24Hour(Bool c);
279 #endif // HAVE_STRFTIME
280
281   inline bool hideToolbar() const { return resource.hide_toolbar; }
282   void setHideToolbar(bool);
283
284   inline WindowStyle *getWindowStyle() { return &resource.wstyle; }
285   inline MenuStyle *getMenuStyle() { return &resource.mstyle; }
286   inline ToolbarStyle *getToolbarStyle() { return &resource.tstyle; }
287
288   OpenboxWindow *getIcon(int);
289
290   int addWorkspace();
291   int removeLastWorkspace();
292
293   void removeWorkspaceNames();
294   void addWorkspaceName(const char *);
295   void saveWorkspaceNames();
296   void addNetizen(Netizen *);
297   void removeNetizen(Window);
298   void addIcon(OpenboxWindow *);
299   void removeIcon(OpenboxWindow *);
300   const char *getNameOfWorkspace(int);
301   void changeWorkspaceID(int);
302   void raiseWindows(Window *, int);
303   void reassociateWindow(OpenboxWindow *, int, Bool);
304   void prevFocus();
305   void nextFocus();
306   void raiseFocus();
307   void reconfigure();
308   void load();
309   void save();
310   void rereadMenu();
311   void shutdown();
312   void showPosition(int, int);
313   void showGeometry(unsigned int, unsigned int);
314   void hideGeometry();
315   void updateNetizenCurrentWorkspace();
316   void updateNetizenWorkspaceCount();
317   void updateNetizenWindowFocus();
318   void updateNetizenWindowAdd(Window, unsigned long);
319   void updateNetizenWindowDel(Window);
320   void updateNetizenConfigNotify(XEvent *);
321   void updateNetizenWindowRaise(Window);
322   void updateNetizenWindowLower(Window);
323
324   enum { RowSmartPlacement = 1, ColSmartPlacement, CascadePlacement,
325          BestFitPlacement, UnderMousePlacement, ClickMousePlacement,
326          LeftRight, RightLeft, TopBottom, BottomTop };
327   enum { LeftJustify = 1, RightJustify, CenterJustify };
328   enum { RoundBullet = 1, TriangleBullet, SquareBullet, NoBullet };
329   enum { Restart = 1, RestartOther, Exit, Shutdown, Execute, Reconfigure,
330          WindowShade, WindowIconify, WindowMaximize, WindowClose, WindowRaise,
331          WindowLower, WindowStick, WindowKill, SetStyle };
332 };
333
334
335 #endif // __Screen_hh