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