]> icculus.org git repositories - dana/openbox.git/blob - src/Screen.hh
Added an option to disable the window raise on alt-click. fonk.
[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 #ifdef    BITMAPBUTTONS
65 struct PixmapMask {
66   Pixmap mask;
67   unsigned int w, h;
68 };
69 #endif // BITMAPBUTTONS
70
71 struct WindowStyle {
72   BColor l_text_focus, l_text_unfocus, b_pic_focus,
73     b_pic_unfocus;
74   BTexture f_focus, f_unfocus, t_focus, t_unfocus, l_focus, l_unfocus,
75     h_focus, h_unfocus, b_focus, b_unfocus, b_pressed, b_pressed_focus,
76     b_pressed_unfocus, g_focus, g_unfocus;
77
78 #ifdef    BITMAPBUTTONS
79   PixmapMask close_button, max_button, icon_button, stick_button;
80 #endif // BITMAPBUTTONS
81   BFont *font;
82
83   TextJustify justify;
84
85   void doJustify(const std::string &text, int &start_pos,
86                  unsigned int max_length, unsigned int modifier) const;
87 };
88
89 struct ToolbarStyle {
90   BColor l_text, w_text, c_text, b_pic;
91   BTexture toolbar, label, window, button, pressed, clock;
92
93 #ifdef    BITMAPBUTTONS
94   PixmapMask left_button, right_button;
95 #endif // BITMAPBUTTONS
96   
97   BFont *font;
98
99   TextJustify justify;
100
101   void doJustify(const std::string &text, int &start_pos,
102                  unsigned int max_length, unsigned int modifier) const;
103 };
104
105 struct MenuStyle {
106   BColor t_text, f_text, h_text, d_text;
107   BTexture title, frame, hilite;
108   
109 #ifdef    BITMAPBUTTONS
110   PixmapMask bullet_image, tick_image;
111 #endif // BITMAPBUTTONS
112   
113   BFont *t_font, *f_font;
114
115   TextJustify t_justify, f_justify;
116   int bullet, bullet_pos;
117 };
118
119 class BScreen : public ScreenInfo {
120 private:
121   bool root_colormap_installed, managed, geom_visible;
122   GC opGC;
123   Pixmap geom_pixmap;
124   Window geom_window;
125
126   Blackbox *blackbox;
127   BImageControl *image_control;
128   Configmenu *configmenu;
129   Iconmenu *iconmenu;
130   Rootmenu *rootmenu;
131   Configuration *config;
132   XAtom *xatom;
133
134   typedef std::list<Rootmenu*> RootmenuList;
135   RootmenuList rootmenuList;
136
137   typedef std::list<Netizen*> NetizenList;
138   NetizenList netizenList;
139   BlackboxWindowList iconList, windowList;
140
141   typedef std::vector<Window> WindowList;
142   WindowList specialWindowList, desktopWindowList, systrayWindowList;
143
144   Slit *slit;
145   Toolbar *toolbar;
146   Workspace *current_workspace;
147   Workspacemenu *workspacemenu;
148
149   unsigned int geom_w, geom_h;
150   unsigned long event_mask;
151
152   Rect usableArea;
153 #ifdef    XINERAMA
154   RectList xineramaUsableArea;
155 #endif // XINERAMA
156
157   typedef std::list<Strut*> StrutList;
158   StrutList strutList;
159   typedef std::vector<Workspace*> WorkspaceList;
160   WorkspaceList workspacesList;
161
162   struct screen_resource {
163     WindowStyle wstyle;
164     ToolbarStyle tstyle;
165     MenuStyle mstyle;
166
167     bool sloppy_focus, auto_raise, auto_edge_balance, ordered_dither,
168       opaque_move, raise_on_move, full_max, focus_new, focus_last, click_raise,
169       allow_scroll_lock, hide_toolbar, window_corner_snap, aa_fonts,
170       ignore_shaded, ignore_maximized, workspace_warping, shadow_fonts;
171
172     int snap_to_windows, snap_to_edges;
173     unsigned int snap_offset;
174
175     BColor border_color;
176
177     unsigned int workspaces;
178     int toolbar_placement, toolbar_width_percent, placement_policy,
179       snap_threshold, row_direction, col_direction, root_scroll,
180       resistance_size;
181
182     unsigned int handle_width, bevel_width, frame_width, border_width,
183       resize_zones;
184
185     unsigned int root_menu_button, workspace_menu_button;
186
187 #ifdef    HAVE_STRFTIME
188     std::string strftime_format;
189 #else // !HAVE_STRFTIME
190     bool clock24hour;
191     int date_format;
192 #endif // HAVE_STRFTIME
193
194   } resource;
195   std::string screenstr;
196
197   BScreen(const BScreen&);
198   BScreen& operator=(const BScreen&);
199
200   bool parseMenuFile(FILE *file, Rootmenu *menu);
201
202 #ifdef    BITMAPBUTTONS
203   void readDatabaseMask(const std::string &rname,
204                         PixmapMask &pixmapMask,
205                         const Configuration &style);
206 #endif // BITMAPBUTTONS
207   
208   BTexture readDatabaseTexture(const std::string &rname,
209                                const std::string &default_color,
210                                const Configuration &style, 
211                                bool allowNoTexture = false);
212   BColor readDatabaseColor(const std::string &rname,
213                            const std::string &default_color,
214                            const Configuration &style);
215   BFont *readDatabaseFont(const std::string &rbasename,
216                           const Configuration &style);
217
218   void InitMenu(void);
219   void LoadStyle(void);
220
221   void updateWorkArea(void);
222 public:
223   enum { WindowNoSnap = 0, WindowSnap, WindowResistance };
224   enum { RowSmartPlacement = 1, ColSmartPlacement, CascadePlacement,
225          UnderMousePlacement, ClickMousePlacement, LeftRight, RightLeft,
226          TopBottom, BottomTop, IgnoreShaded, IgnoreMaximized };
227   enum { RoundBullet = 1, TriangleBullet, SquareBullet, NoBullet };
228   enum { Restart = 1, RestartOther, Exit, Shutdown, Execute, Reconfigure,
229          WindowShade, WindowIconify, WindowMaximize, WindowClose, WindowRaise,
230          WindowLower, WindowStick, WindowKill, SetStyle };
231   enum FocusModel { SloppyFocus, ClickToFocus };
232   enum RootScrollDirection { NoScroll = 0, NormalScroll, ReverseScroll };
233
234   BScreen(Blackbox *bb, unsigned int scrn);
235   ~BScreen(void);
236
237   inline bool isSloppyFocus(void) const { return resource.sloppy_focus; }
238   inline bool isRootColormapInstalled(void) const
239   { return root_colormap_installed; }
240   inline bool doAutoRaise(void) const { return resource.auto_raise; }
241   inline bool doClickRaise(void) const { return resource.click_raise; }
242   inline bool isScreenManaged(void) const { return managed; }
243   inline bool doShadowFonts(void) const { return resource.shadow_fonts; }
244   inline bool doAAFonts(void) const { return resource.aa_fonts; }
245   inline bool doImageDither(void) const { return image_control->doDither(); }
246   inline bool doOrderedDither(void) const { return resource.ordered_dither; }
247   inline bool doOpaqueMove(void) const { return resource.opaque_move; }
248   inline bool doRaiseOnMove(void) const { return resource.raise_on_move; }
249   inline bool doFullMax(void) const { return resource.full_max; }
250   inline bool doFocusNew(void) const { return resource.focus_new; }
251   inline bool doFocusLast(void) const { return resource.focus_last; }
252   inline bool doHideToolbar(void) const { return resource.hide_toolbar; }
253   inline int getWindowToWindowSnap(void) const
254     { return resource.snap_to_windows; }
255   inline int getWindowToEdgeSnap(void) const
256     { return resource.snap_to_edges; }
257   inline bool getWindowCornerSnap(void) const
258     { return resource.window_corner_snap; }
259   inline bool allowScrollLock(void) const { return resource.allow_scroll_lock; }
260   inline bool doWorkspaceWarping(void) const
261     { return resource.workspace_warping; }
262   inline int rootScrollDirection(void) const { return resource.root_scroll; }
263   inline unsigned int rootMenuButton(void) const
264     { return resource.root_menu_button; }
265   inline unsigned int workspaceMenuButton(void) const
266     { return resource.workspace_menu_button; }
267
268   inline const GC &getOpGC(void) const { return opGC; }
269
270   inline Blackbox *getBlackbox(void) { return blackbox; }
271   inline BColor *getBorderColor(void) { return &resource.border_color; }
272   inline BImageControl *getImageControl(void) { return image_control; }
273   inline Rootmenu *getRootmenu(void) { return rootmenu; }
274
275   inline Slit *getSlit(void) { return slit; }
276   inline Toolbar *getToolbar(void) { return toolbar; }
277
278   Workspace *getWorkspace(unsigned int index) const;
279
280   inline Workspace *getCurrentWorkspace(void) { return current_workspace; }
281
282   inline Workspacemenu *getWorkspacemenu(void) { return workspacemenu; }
283
284   inline unsigned int getHandleWidth(void) const
285   { return resource.handle_width; }
286   inline unsigned int getBevelWidth(void) const
287   { return resource.bevel_width; }
288   inline unsigned int getFrameWidth(void) const
289   { return resource.frame_width; }
290   inline unsigned int getBorderWidth(void) const
291   { return resource.border_width; }
292   inline unsigned int getResizeZones(void) const
293   { return resource.resize_zones; }
294   inline bool getPlaceIgnoreShaded(void) const
295   { return resource.ignore_shaded; }
296   inline bool getPlaceIgnoreMaximized(void) const
297   { return resource.ignore_maximized; }
298
299   inline unsigned int getCurrentWorkspaceID(void) const
300   { return current_workspace->getID(); }
301   inline unsigned int getWorkspaceCount(void) const
302   { return workspacesList.size(); }
303   inline unsigned int getIconCount(void) const { return iconList.size(); }
304   inline unsigned int getNumberOfWorkspaces(void) const
305   { return resource.workspaces; }
306   inline int getPlacementPolicy(void) const
307   { return resource.placement_policy; }
308   inline int getSnapOffset(void) const
309   { return resource.snap_offset; }
310   inline int getSnapThreshold(void) const
311   { return resource.snap_threshold; }
312   inline int getResistanceSize(void) const
313   { return resource.resistance_size; }
314   inline int getRowPlacementDirection(void) const
315   { return resource.row_direction; }
316   inline int getColPlacementDirection(void) const
317   { return resource.col_direction; }
318
319   void changeWorkspaceCount(unsigned int new_count);
320   
321   inline void setRootColormapInstalled(bool r) { root_colormap_installed = r; }
322   void saveSloppyFocus(bool s);
323   void saveAutoRaise(bool a);
324   void saveClickRaise(bool c);
325   void saveWorkspaces(unsigned int w);
326   void savePlacementPolicy(int p);
327   void saveRowPlacementDirection(int d);
328   void saveColPlacementDirection(int d);
329   void saveSnapThreshold(int t);
330   void saveSnapOffset(int o);
331   void saveResistanceSize(int s);
332   void saveImageDither(bool d);
333   void saveShadowFonts(bool f);
334   void saveAAFonts(bool f);
335   void saveOpaqueMove(bool o);
336   void saveRaiseOnMove(bool r);
337   void saveFullMax(bool f);
338   void saveFocusNew(bool f);
339   void saveFocusLast(bool f);
340   void saveHideToolbar(bool h);
341   void saveWindowToEdgeSnap(int s);
342   void saveWindowToWindowSnap(int s);
343   void saveWindowCornerSnap(bool s);
344   void saveResizeZones(unsigned int z);
345   void savePlaceIgnoreShaded(bool i);
346   void savePlaceIgnoreMaximized(bool i);
347   void saveAllowScrollLock(bool a);
348   void saveWorkspaceWarping(bool w);
349   void saveRootScrollDirection(int d);
350   void saveRootMenuButton(unsigned int b);
351   void saveWorkspaceMenuButton(unsigned int b);
352   inline void iconUpdate(void) { iconmenu->update(); }
353
354 #ifdef    HAVE_STRFTIME
355   inline const char *getStrftimeFormat(void)
356   { return resource.strftime_format.c_str(); }
357   void saveStrftimeFormat(const std::string& format);
358 #else // !HAVE_STRFTIME
359   inline int getDateFormat(void) { return resource.date_format; }
360   inline void saveDateFormat(int f);
361   inline bool isClock24Hour(void) { return resource.clock24hour; }
362   inline void saveClock24Hour(bool c);
363 #endif // HAVE_STRFTIME
364
365   inline WindowStyle *getWindowStyle(void) { return &resource.wstyle; }
366   inline MenuStyle *getMenuStyle(void) { return &resource.mstyle; }
367   inline ToolbarStyle *getToolbarStyle(void) { return &resource.tstyle; }
368
369   BlackboxWindow *getIcon(unsigned int index);
370
371   // allAvailableAreas should be used whenever possible instead of this function
372   // as then Xinerama will work correctly.
373   const Rect& availableArea(void) const;
374 #ifdef    XINERAMA
375   const RectList& allAvailableAreas(void) const;
376 #endif // XINERAMA
377   void updateAvailableArea(void);
378   void addStrut(Strut *strut);
379   void removeStrut(Strut *strut);
380
381   unsigned int addWorkspace(void);
382   unsigned int removeLastWorkspace(void);
383   void changeWorkspaceID(unsigned int id);
384   void saveWorkspaceNames(void);
385
386   void addNetizen(Netizen *n);
387   void removeNetizen(Window w);
388
389   void addSystrayWindow(Window window);
390   void removeSystrayWindow(Window window);
391
392   void addIcon(BlackboxWindow *w);
393   void removeIcon(BlackboxWindow *w);
394
395   void updateClientList(void);
396   void updateStackingList(void);
397   void manageWindow(Window w);
398   void unmanageWindow(BlackboxWindow *w, bool remap);
399   void raiseWindows(Window *workspace_stack, unsigned int num);
400   void lowerWindows(Window *workspace_stack, unsigned int num);
401   void reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
402                          bool ignore_sticky);
403   void propagateWindowName(const BlackboxWindow *bw);
404   void prevFocus(void) const;
405   void nextFocus(void) const;
406   void raiseFocus(void) const;
407   void load_rc(void);
408   void save_rc(void);
409   void reconfigure(void);
410   void toggleFocusModel(FocusModel model);
411   void rereadMenu(void);
412   void shutdown(void);
413   void showPosition(int x, int y);
414   void showGeometry(unsigned int gx, unsigned int gy);
415   void hideGeometry(void);
416
417   void showWorkspaceMenu(int x, int y);
418   void showRootMenu(int x, int y);
419
420   void buttonPressEvent(const XButtonEvent *xbutton);
421   void propertyNotifyEvent(const XPropertyEvent *pe);
422
423   void updateNetizenCurrentWorkspace(void);
424   void updateNetizenWorkspaceCount(void);
425   void updateNetizenWindowFocus(void);
426   void updateNetizenWindowAdd(Window w, unsigned long p);
427   void updateNetizenWindowDel(Window w);
428   void updateNetizenConfigNotify(XEvent *e);
429   void updateNetizenWindowRaise(Window w);
430   void updateNetizenWindowLower(Window w);
431 };
432
433
434 #endif // __Screen_hh