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