]> icculus.org git repositories - dana/openbox.git/blob - src/Screen.hh
merged bitmap buttons
[dana/openbox.git] / src / Screen.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Screen.hh for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23
24 #ifndef   __Screen_hh
25 #define   __Screen_hh
26
27 extern "C" {
28 #include <X11/Xlib.h>
29
30 #ifdef    TIME_WITH_SYS_TIME
31 #  include <sys/time.h>
32 #  include <time.h>
33 #else // !TIME_WITH_SYS_TIME
34 #  ifdef    HAVE_SYS_TIME_H
35 #    include <sys/time.h>
36 #  else // !HAVE_SYS_TIME_H
37 #    include <time.h>
38 #  endif // HAVE_SYS_TIME_H
39 #endif // TIME_WITH_SYS_TIME
40 }
41
42 #include <list>
43 #include <vector>
44
45 #include "Color.hh"
46 #include "Texture.hh"
47 #include "Image.hh"
48 #include "Configmenu.hh"
49 #include "Iconmenu.hh"
50 #include "Netizen.hh"
51 #include "Rootmenu.hh"
52 #include "Timer.hh"
53 #include "Workspace.hh"
54 #include "Workspacemenu.hh"
55 #include "blackbox.hh"
56
57 class Slit; // forward reference
58 class BFont;
59 class XAtom;
60 struct Strut;
61
62 enum TextJustify { LeftJustify = 1, RightJustify, CenterJustify };
63
64 struct PixmapMask {
65   Pixmap mask;
66   unsigned int w, h;
67 };
68
69 struct WindowStyle {
70   BColor l_text_focus, l_text_unfocus, b_pic_focus,
71     b_pic_unfocus;
72   BTexture f_focus, f_unfocus, t_focus, t_unfocus, l_focus, l_unfocus,
73     h_focus, h_unfocus, b_focus, b_unfocus, b_pressed, g_focus, g_unfocus;
74
75   PixmapMask close_button, max_button, icon_button, stick_button;
76
77   BFont *font;
78
79   TextJustify justify;
80
81   void doJustify(const std::string &text, int &start_pos,
82                  unsigned int max_length, unsigned int modifier) const;
83 };
84
85 struct ToolbarStyle {
86   BColor l_text, w_text, c_text, b_pic;
87   BTexture toolbar, label, window, button, pressed, clock;
88
89   PixmapMask left_button, right_button; //these should probably be the same
90   
91   BFont *font;
92
93   TextJustify justify;
94
95   void doJustify(const std::string &text, int &start_pos,
96                  unsigned int max_length, unsigned int modifier) const;
97 };
98
99 struct MenuStyle {
100   BColor t_text, f_text, h_text, d_text;
101   BTexture title, frame, hilite;
102
103   PixmapMask bullet_image, tick_image;
104   
105   BFont *t_font, *f_font;
106
107   TextJustify t_justify, f_justify;
108   int bullet, bullet_pos;
109 };
110
111 class BScreen : public ScreenInfo {
112 private:
113   bool root_colormap_installed, managed, geom_visible;
114   GC opGC;
115   Pixmap geom_pixmap;
116   Window geom_window;
117
118   Blackbox *blackbox;
119   BImageControl *image_control;
120   Configmenu *configmenu;
121   Iconmenu *iconmenu;
122   Rootmenu *rootmenu;
123   Configuration *config;
124   XAtom *xatom;
125
126   typedef std::list<Rootmenu*> RootmenuList;
127   RootmenuList rootmenuList;
128
129   typedef std::list<Netizen*> NetizenList;
130   NetizenList netizenList;
131   BlackboxWindowList iconList, windowList;
132
133   typedef std::vector<Window> WindowList;
134   WindowList specialWindowList, desktopWindowList, systrayWindowList;
135
136   Slit *slit;
137   Toolbar *toolbar;
138   Workspace *current_workspace;
139   Workspacemenu *workspacemenu;
140
141   unsigned int geom_w, geom_h;
142   unsigned long event_mask;
143
144   Rect usableArea;
145 #ifdef    XINERAMA
146   RectList xineramaUsableArea;
147 #endif // XINERAMA
148
149   typedef std::list<Strut*> StrutList;
150   StrutList strutList;
151   typedef std::vector<Workspace*> WorkspaceList;
152   WorkspaceList workspacesList;
153
154   struct screen_resource {
155     WindowStyle wstyle;
156     ToolbarStyle tstyle;
157     MenuStyle mstyle;
158
159     bool sloppy_focus, auto_raise, auto_edge_balance, ordered_dither,
160       opaque_move, full_max, focus_new, focus_last, click_raise,
161       allow_scroll_lock, hide_toolbar, window_corner_snap, aa_fonts,
162       ignore_shaded, ignore_maximized, workspace_warping, shadow_fonts;
163
164     int snap_to_windows, snap_to_edges;
165     unsigned int snap_offset;
166
167     BColor border_color;
168
169     unsigned int workspaces;
170     int toolbar_placement, toolbar_width_percent, placement_policy,
171       snap_threshold, row_direction, col_direction, root_scroll,
172       resistance_size;
173
174     unsigned int handle_width, bevel_width, frame_width, border_width,
175       resize_zones;
176
177     unsigned int root_menu_button, workspace_menu_button;
178
179 #ifdef    HAVE_STRFTIME
180     std::string strftime_format;
181 #else // !HAVE_STRFTIME
182     bool clock24hour;
183     int date_format;
184 #endif // HAVE_STRFTIME
185
186   } resource;
187   std::string screenstr;
188
189   BScreen(const BScreen&);
190   BScreen& operator=(const BScreen&);
191
192   bool parseMenuFile(FILE *file, Rootmenu *menu);
193
194   void readDatabaseMask(const string &rname,
195                         PixmapMask &pixmapMask,
196                         const Configuration &style);
197   BTexture readDatabaseTexture(const std::string &rname,
198                                const std::string &default_color,
199                                const Configuration &style);
200   BColor readDatabaseColor(const std::string &rname,
201                            const std::string &default_color,
202                            const Configuration &style);
203   BFont *readDatabaseFont(const std::string &rbasename,
204                           const Configuration &style);
205
206   void InitMenu(void);
207   void LoadStyle(void);
208
209   void updateWorkArea(void);
210 public:
211   enum { WindowNoSnap = 0, WindowSnap, WindowResistance };
212   enum { RowSmartPlacement = 1, ColSmartPlacement, CascadePlacement,
213          UnderMousePlacement, ClickMousePlacement, LeftRight, RightLeft,
214          TopBottom, BottomTop, IgnoreShaded, IgnoreMaximized };
215   enum { RoundBullet = 1, TriangleBullet, SquareBullet, NoBullet };
216   enum { Restart = 1, RestartOther, Exit, Shutdown, Execute, Reconfigure,
217          WindowShade, WindowIconify, WindowMaximize, WindowClose, WindowRaise,
218          WindowLower, WindowStick, WindowKill, SetStyle };
219   enum FocusModel { SloppyFocus, ClickToFocus };
220   enum RootScrollDirection { NoScroll = 0, NormalScroll, ReverseScroll };
221
222   BScreen(Blackbox *bb, unsigned int scrn);
223   ~BScreen(void);
224
225   inline bool isSloppyFocus(void) const { return resource.sloppy_focus; }
226   inline bool isRootColormapInstalled(void) const
227   { return root_colormap_installed; }
228   inline bool doAutoRaise(void) const { return resource.auto_raise; }
229   inline bool doClickRaise(void) const { return resource.click_raise; }
230   inline bool isScreenManaged(void) const { return managed; }
231   inline bool doShadowFonts(void) const { return resource.shadow_fonts; }
232   inline bool doAAFonts(void) const { return resource.aa_fonts; }
233   inline bool doImageDither(void) const { return image_control->doDither(); }
234   inline bool doOrderedDither(void) const { return resource.ordered_dither; }
235   inline bool doOpaqueMove(void) const { return resource.opaque_move; }
236   inline bool doFullMax(void) const { return resource.full_max; }
237   inline bool doFocusNew(void) const { return resource.focus_new; }
238   inline bool doFocusLast(void) const { return resource.focus_last; }
239   inline bool doHideToolbar(void) const { return resource.hide_toolbar; }
240   inline int getWindowToWindowSnap(void) const
241     { return resource.snap_to_windows; }
242   inline int getWindowToEdgeSnap(void) const
243     { return resource.snap_to_edges; }
244   inline bool getWindowCornerSnap(void) const
245     { return resource.window_corner_snap; }
246   inline bool allowScrollLock(void) const { return resource.allow_scroll_lock; }
247   inline bool doWorkspaceWarping(void) const
248     { return resource.workspace_warping; }
249   inline int rootScrollDirection(void) const { return resource.root_scroll; }
250   inline unsigned int rootMenuButton(void) const
251     { return resource.root_menu_button; }
252   inline unsigned int workspaceMenuButton(void) const
253     { return resource.workspace_menu_button; }
254
255   inline const GC &getOpGC(void) const { return opGC; }
256
257   inline Blackbox *getBlackbox(void) { return blackbox; }
258   inline BColor *getBorderColor(void) { return &resource.border_color; }
259   inline BImageControl *getImageControl(void) { return image_control; }
260   inline Rootmenu *getRootmenu(void) { return rootmenu; }
261
262   inline Slit *getSlit(void) { return slit; }
263   inline Toolbar *getToolbar(void) { return toolbar; }
264
265   Workspace *getWorkspace(unsigned int index);
266
267   inline Workspace *getCurrentWorkspace(void) { return current_workspace; }
268
269   inline Workspacemenu *getWorkspacemenu(void) { return workspacemenu; }
270
271   inline unsigned int getHandleWidth(void) const
272   { return resource.handle_width; }
273   inline unsigned int getBevelWidth(void) const
274   { return resource.bevel_width; }
275   inline unsigned int getFrameWidth(void) const
276   { return resource.frame_width; }
277   inline unsigned int getBorderWidth(void) const
278   { return resource.border_width; }
279   inline unsigned int getResizeZones(void) const
280   { return resource.resize_zones; }
281   inline bool getPlaceIgnoreShaded(void) const
282   { return resource.ignore_shaded; }
283   inline bool getPlaceIgnoreMaximized(void) const
284   { return resource.ignore_maximized; }
285
286   inline unsigned int getCurrentWorkspaceID(void) const
287   { return current_workspace->getID(); }
288   inline unsigned int getWorkspaceCount(void) const
289   { return workspacesList.size(); }
290   inline unsigned int getIconCount(void) const { return iconList.size(); }
291   inline unsigned int getNumberOfWorkspaces(void) const
292   { return resource.workspaces; }
293   inline int getPlacementPolicy(void) const
294   { return resource.placement_policy; }
295   inline int getSnapOffset(void) const
296   { return resource.snap_offset; }
297   inline int getSnapThreshold(void) const
298   { return resource.snap_threshold; }
299   inline int getResistanceSize(void) const
300   { return resource.resistance_size; }
301   inline int getRowPlacementDirection(void) const
302   { return resource.row_direction; }
303   inline int getColPlacementDirection(void) const
304   { return resource.col_direction; }
305
306   void changeWorkspaceCount(unsigned int new_count);
307   
308   inline void setRootColormapInstalled(bool r) { root_colormap_installed = r; }
309   void saveSloppyFocus(bool s);
310   void saveAutoRaise(bool a);
311   void saveClickRaise(bool c);
312   void saveWorkspaces(unsigned int w);
313   void savePlacementPolicy(int p);
314   void saveRowPlacementDirection(int d);
315   void saveColPlacementDirection(int d);
316   void saveSnapThreshold(int t);
317   void saveSnapOffset(int o);
318   void saveResistanceSize(int s);
319   void saveImageDither(bool d);
320   void saveShadowFonts(bool f);
321   void saveAAFonts(bool f);
322   void saveOpaqueMove(bool o);
323   void saveFullMax(bool f);
324   void saveFocusNew(bool f);
325   void saveFocusLast(bool f);
326   void saveHideToolbar(bool h);
327   void saveWindowToEdgeSnap(int s);
328   void saveWindowToWindowSnap(int s);
329   void saveWindowCornerSnap(bool s);
330   void saveResizeZones(unsigned int z);
331   void savePlaceIgnoreShaded(bool i);
332   void savePlaceIgnoreMaximized(bool i);
333   void saveAllowScrollLock(bool a);
334   void saveWorkspaceWarping(bool w);
335   void saveRootScrollDirection(int d);
336   void saveRootMenuButton(unsigned int b);
337   void saveWorkspaceMenuButton(unsigned int b);
338   inline void iconUpdate(void) { iconmenu->update(); }
339
340 #ifdef    HAVE_STRFTIME
341   inline const char *getStrftimeFormat(void)
342   { return resource.strftime_format.c_str(); }
343   void saveStrftimeFormat(const std::string& format);
344 #else // !HAVE_STRFTIME
345   inline int getDateFormat(void) { return resource.date_format; }
346   inline void saveDateFormat(int f);
347   inline bool isClock24Hour(void) { return resource.clock24hour; }
348   inline void saveClock24Hour(bool c);
349 #endif // HAVE_STRFTIME
350
351   inline WindowStyle *getWindowStyle(void) { return &resource.wstyle; }
352   inline MenuStyle *getMenuStyle(void) { return &resource.mstyle; }
353   inline ToolbarStyle *getToolbarStyle(void) { return &resource.tstyle; }
354
355   BlackboxWindow *getIcon(unsigned int index);
356
357   // allAvailableAreas should be used whenever possible instead of this function
358   // as then Xinerama will work correctly.
359   const Rect& availableArea(void) const;
360 #ifdef    XINERAMA
361   const RectList& allAvailableAreas(void) const;
362 #endif // XINERAMA
363   void updateAvailableArea(void);
364   void addStrut(Strut *strut);
365   void removeStrut(Strut *strut);
366
367   unsigned int addWorkspace(void);
368   unsigned int removeLastWorkspace(void);
369   void changeWorkspaceID(unsigned int id);
370   void saveWorkspaceNames(void);
371
372   void addNetizen(Netizen *n);
373   void removeNetizen(Window w);
374
375   void addSystrayWindow(Window window);
376   void removeSystrayWindow(Window window);
377
378   void addIcon(BlackboxWindow *w);
379   void removeIcon(BlackboxWindow *w);
380
381   void updateClientList(void);
382   void updateStackingList(void);
383   void manageWindow(Window w);
384   void unmanageWindow(BlackboxWindow *w, bool remap);
385   void raiseWindows(Window *workspace_stack, unsigned int num);
386   void lowerWindows(Window *workspace_stack, unsigned int num);
387   void reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
388                          bool ignore_sticky);
389   void propagateWindowName(const BlackboxWindow *bw);
390   void prevFocus(void);
391   void nextFocus(void);
392   void raiseFocus(void);
393   void load_rc(void);
394   void save_rc(void);
395   void reconfigure(void);
396   void toggleFocusModel(FocusModel model);
397   void rereadMenu(void);
398   void shutdown(void);
399   void showPosition(int x, int y);
400   void showGeometry(unsigned int gx, unsigned int gy);
401   void hideGeometry(void);
402
403   void showWorkspaceMenu(int x, int y);
404   void showRootMenu(int x, int y);
405
406   void buttonPressEvent(const XButtonEvent *xbutton);
407   void propertyNotifyEvent(const XPropertyEvent *pe);
408
409   void updateNetizenCurrentWorkspace(void);
410   void updateNetizenWorkspaceCount(void);
411   void updateNetizenWindowFocus(void);
412   void updateNetizenWindowAdd(Window w, unsigned long p);
413   void updateNetizenWindowDel(Window w);
414   void updateNetizenConfigNotify(XEvent *e);
415   void updateNetizenWindowRaise(Window w);
416   void updateNetizenWindowLower(Window w);
417 };
418
419
420 #endif // __Screen_hh