]> icculus.org git repositories - mikachu/openbox.git/blob - src/Screen.h
Toolbar saves its settings as their changed
[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,
136       auto_edge_balance, image_dither, ordered_dither, opaque_move, full_max,
137       focus_new, focus_last;
138     bool hide_toolbar;
139     BColor border_color;
140     Resource styleconfig;
141
142     int workspaces, toolbar_placement, toolbar_width_percent, placement_policy,
143       edge_snap_threshold, row_direction, col_direction;
144
145     unsigned int handle_width, bevel_width, frame_width, border_width;
146     unsigned int zones; // number of zones to be used when alt-resizing a window
147
148 #ifdef    HAVE_STRFTIME
149     char *strftime_format;
150 #else // !HAVE_STRFTIME
151     Bool clock24hour;
152     int date_format;
153 #endif // HAVE_STRFTIME
154
155     char *root_command;
156   } resource;
157
158
159 protected:
160   Bool parseMenuFile(FILE *, Rootmenu *);
161
162   void readDatabaseTexture(const char *, const char *, BTexture *,
163                            unsigned long);
164   void readDatabaseColor(const char *, const char *, BColor *, unsigned long);
165
166   void readDatabaseFontSet(const char *, const char *, XFontSet *);
167   XFontSet createFontSet(const char *);
168   void readDatabaseFont(const char *, const char *, XFontStruct **);
169
170   void InitMenu();
171   void LoadStyle();
172
173
174 public:
175   BScreen(Openbox &, int, Resource &);
176   ~BScreen();
177
178   inline const Bool &isSloppyFocus() const
179   { return resource.sloppy_focus; }
180   inline const Bool &isRootColormapInstalled() const
181   { return root_colormap_installed; }
182   inline const Bool &doAutoRaise() const { return resource.auto_raise; }
183   inline const Bool &isScreenManaged() const { return managed; }
184   inline const Bool &doImageDither() const
185   { return resource.image_dither; }
186   inline const Bool &doOrderedDither() const
187   { return resource.ordered_dither; }
188   inline const Bool &doOpaqueMove() const { return resource.opaque_move; }
189   inline const Bool &doFullMax() const { return resource.full_max; }
190   inline const Bool &doFocusNew() const { return resource.focus_new; }
191   inline const Bool &doFocusLast() const { return resource.focus_last; }
192
193   inline const GC &getOpGC() const { return opGC; }
194
195   inline Openbox &getOpenbox() { return openbox; }
196   inline BColor *getBorderColor() { return &resource.border_color; }
197   inline BImageControl *getImageControl() { return image_control; }
198   inline Rootmenu *getRootmenu() { return rootmenu; }
199
200 #ifdef   SLIT
201   inline Slit *getSlit() { return slit; }
202 #endif // SLIT
203
204   inline int getWindowZones() const
205   { return resource.zones; }
206   inline void saveWindowZones(int z) { resource.zones = z; }
207   
208   inline Toolbar *getToolbar() { return toolbar; }
209
210   inline Workspace *getWorkspace(int w) { return workspacesList->find(w); }
211   inline Workspace *getCurrentWorkspace() { return current_workspace; }
212
213   inline Workspacemenu *getWorkspacemenu() { return workspacemenu; }
214
215   inline const unsigned int &getHandleWidth() const
216   { return resource.handle_width; }
217   inline const unsigned int &getBevelWidth() const
218   { return resource.bevel_width; }
219   inline const unsigned int &getFrameWidth() const
220   { return resource.frame_width; }
221   inline const unsigned int &getBorderWidth() const
222   { return resource.border_width; }
223
224   inline const int getCurrentWorkspaceID()
225   { return current_workspace->getWorkspaceID(); }
226   inline const int getWorkspaceCount() { return workspacesList->count(); }
227   inline const int getIconCount() { return iconList->count(); }
228   inline const int &getNumberOfWorkspaces() const
229   { return resource.workspaces; }
230   inline const int &getPlacementPolicy() const
231   { return resource.placement_policy; }
232   inline const int &getEdgeSnapThreshold() const
233   { return resource.edge_snap_threshold; }
234   inline const int &getRowPlacementDirection() const
235   { return resource.row_direction; }
236   inline const int &getColPlacementDirection() const
237   { return resource.col_direction; }
238
239   inline void saveRootCommand(const char *cmd) {
240     if (resource.root_command != NULL)
241       delete [] resource.root_command;
242     if (cmd != NULL)
243       resource.root_command = bstrdup(cmd);
244     else
245       resource.root_command = NULL;
246   }
247   inline const char *getRootCommand() const
248   { return resource.root_command; }
249   
250   inline void setRootColormapInstalled(Bool r) { root_colormap_installed = r; }
251   inline void saveSloppyFocus(Bool s) { resource.sloppy_focus = s; }
252   inline void saveAutoRaise(Bool a) { resource.auto_raise = a; }
253   inline void saveWorkspaces(int w) { resource.workspaces = w; }
254   inline void savePlacementPolicy(int p) { resource.placement_policy = p; }
255   inline void saveRowPlacementDirection(int d) { resource.row_direction = d; }
256   inline void saveColPlacementDirection(int d) { resource.col_direction = d; }
257   inline void saveEdgeSnapThreshold(int t)
258   { resource.edge_snap_threshold = t; }
259   inline void saveImageDither(Bool d) { resource.image_dither = d; }
260   inline void saveOpaqueMove(Bool o) { resource.opaque_move = o; }
261   inline void saveFullMax(Bool f) { resource.full_max = f; }
262   inline void saveFocusNew(Bool f) { resource.focus_new = f; }
263   inline void saveFocusLast(Bool f) { resource.focus_last = f; }
264   inline void iconUpdate() { iconmenu->update(); }
265 #ifdef    HAVE_STRFTIME
266   inline char *getStrftimeFormat() { return resource.strftime_format; }
267   void saveStrftimeFormat(const char *);
268 #else // !HAVE_STRFTIME
269   inline int getDateFormat() { return resource.date_format; }
270   inline void saveDateFormat(int f) { resource.date_format = f; }
271   inline Bool isClock24Hour() { return resource.clock24hour; }
272   inline void saveClock24Hour(Bool c) { resource.clock24hour = 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 addNetizen(Netizen *);
290   void removeNetizen(Window);
291   void addIcon(OpenboxWindow *);
292   void removeIcon(OpenboxWindow *);
293   char* getNameOfWorkspace(int);
294   void changeWorkspaceID(int);
295   void raiseWindows(Window *, int);
296   void reassociateWindow(OpenboxWindow *, int, Bool);
297   void prevFocus();
298   void nextFocus();
299   void raiseFocus();
300   void reconfigure();
301   void load();
302   void rereadMenu();
303   void shutdown();
304   void showPosition(int, int);
305   void showGeometry(unsigned int, unsigned int);
306   void hideGeometry();
307   void updateNetizenCurrentWorkspace();
308   void updateNetizenWorkspaceCount();
309   void updateNetizenWindowFocus();
310   void updateNetizenWindowAdd(Window, unsigned long);
311   void updateNetizenWindowDel(Window);
312   void updateNetizenConfigNotify(XEvent *);
313   void updateNetizenWindowRaise(Window);
314   void updateNetizenWindowLower(Window);
315
316   enum { RowSmartPlacement = 1, ColSmartPlacement, CascadePlacement,
317          BestFitPlacement, LeftRight, RightLeft, TopBottom, BottomTop };
318   enum { LeftJustify = 1, RightJustify, CenterJustify };
319   enum { RoundBullet = 1, TriangleBullet, SquareBullet, NoBullet };
320   enum { Restart = 1, RestartOther, Exit, Shutdown, Execute, Reconfigure,
321          WindowShade, WindowIconify, WindowMaximize, WindowClose, WindowRaise,
322          WindowLower, WindowStick, WindowKill, SetStyle };
323 };
324
325
326 #endif // __Screen_hh