]> icculus.org git repositories - mikachu/openbox.git/blob - src/screen.hh
rename, remove bullshit. ya
[mikachu/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, 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 doFullMax(void) const { return resource.full_max; }
249   inline bool doFocusNew(void) const { return resource.focus_new; }
250   inline bool doFocusLast(void) const { return resource.focus_last; }
251   inline bool doHideToolbar(void) const { return resource.hide_toolbar; }
252   inline int getWindowToWindowSnap(void) const
253     { return resource.snap_to_windows; }
254   inline int getWindowToEdgeSnap(void) const
255     { return resource.snap_to_edges; }
256   inline bool getWindowCornerSnap(void) const
257     { return resource.window_corner_snap; }
258   inline bool allowScrollLock(void) const { return resource.allow_scroll_lock; }
259   inline bool doWorkspaceWarping(void) const
260     { return resource.workspace_warping; }
261   inline int rootScrollDirection(void) const { return resource.root_scroll; }
262   inline unsigned int rootMenuButton(void) const
263     { return resource.root_menu_button; }
264   inline unsigned int workspaceMenuButton(void) const
265     { return resource.workspace_menu_button; }
266
267   inline const GC &getOpGC(void) const { return opGC; }
268
269   inline Blackbox *getBlackbox(void) { return blackbox; }
270   inline BColor *getBorderColor(void) { return &resource.border_color; }
271   inline BImageControl *getImageControl(void) { return image_control; }
272   inline Rootmenu *getRootmenu(void) { return rootmenu; }
273
274   inline Slit *getSlit(void) { return slit; }
275   inline Toolbar *getToolbar(void) { return toolbar; }
276
277   Workspace *getWorkspace(unsigned int index) const;
278
279   inline Workspace *getCurrentWorkspace(void) { return current_workspace; }
280
281   inline Workspacemenu *getWorkspacemenu(void) { return workspacemenu; }
282
283   inline unsigned int getHandleWidth(void) const
284   { return resource.handle_width; }
285   inline unsigned int getBevelWidth(void) const
286   { return resource.bevel_width; }
287   inline unsigned int getFrameWidth(void) const
288   { return resource.frame_width; }
289   inline unsigned int getBorderWidth(void) const
290   { return resource.border_width; }
291   inline unsigned int getResizeZones(void) const
292   { return resource.resize_zones; }
293   inline bool getPlaceIgnoreShaded(void) const
294   { return resource.ignore_shaded; }
295   inline bool getPlaceIgnoreMaximized(void) const
296   { return resource.ignore_maximized; }
297
298   inline unsigned int getCurrentWorkspaceID(void) const
299   { return current_workspace->getID(); }
300   inline unsigned int getWorkspaceCount(void) const
301   { return workspacesList.size(); }
302   inline unsigned int getIconCount(void) const { return iconList.size(); }
303   inline unsigned int getNumberOfWorkspaces(void) const
304   { return resource.workspaces; }
305   inline int getPlacementPolicy(void) const
306   { return resource.placement_policy; }
307   inline int getSnapOffset(void) const
308   { return resource.snap_offset; }
309   inline int getSnapThreshold(void) const
310   { return resource.snap_threshold; }
311   inline int getResistanceSize(void) const
312   { return resource.resistance_size; }
313   inline int getRowPlacementDirection(void) const
314   { return resource.row_direction; }
315   inline int getColPlacementDirection(void) const
316   { return resource.col_direction; }
317
318   void changeWorkspaceCount(unsigned int new_count);
319   
320   inline void setRootColormapInstalled(bool r) { root_colormap_installed = r; }
321   void saveSloppyFocus(bool s);
322   void saveAutoRaise(bool a);
323   void saveClickRaise(bool c);
324   void saveWorkspaces(unsigned int w);
325   void savePlacementPolicy(int p);
326   void saveRowPlacementDirection(int d);
327   void saveColPlacementDirection(int d);
328   void saveSnapThreshold(int t);
329   void saveSnapOffset(int o);
330   void saveResistanceSize(int s);
331   void saveImageDither(bool d);
332   void saveShadowFonts(bool f);
333   void saveAAFonts(bool f);
334   void saveOpaqueMove(bool o);
335   void saveFullMax(bool f);
336   void saveFocusNew(bool f);
337   void saveFocusLast(bool f);
338   void saveHideToolbar(bool h);
339   void saveWindowToEdgeSnap(int s);
340   void saveWindowToWindowSnap(int s);
341   void saveWindowCornerSnap(bool s);
342   void saveResizeZones(unsigned int z);
343   void savePlaceIgnoreShaded(bool i);
344   void savePlaceIgnoreMaximized(bool i);
345   void saveAllowScrollLock(bool a);
346   void saveWorkspaceWarping(bool w);
347   void saveRootScrollDirection(int d);
348   void saveRootMenuButton(unsigned int b);
349   void saveWorkspaceMenuButton(unsigned int b);
350   inline void iconUpdate(void) { iconmenu->update(); }
351
352 #ifdef    HAVE_STRFTIME
353   inline const char *getStrftimeFormat(void)
354   { return resource.strftime_format.c_str(); }
355   void saveStrftimeFormat(const std::string& format);
356 #else // !HAVE_STRFTIME
357   inline int getDateFormat(void) { return resource.date_format; }
358   inline void saveDateFormat(int f);
359   inline bool isClock24Hour(void) { return resource.clock24hour; }
360   inline void saveClock24Hour(bool c);
361 #endif // HAVE_STRFTIME
362
363   inline WindowStyle *getWindowStyle(void) { return &resource.wstyle; }
364   inline MenuStyle *getMenuStyle(void) { return &resource.mstyle; }
365   inline ToolbarStyle *getToolbarStyle(void) { return &resource.tstyle; }
366
367   BlackboxWindow *getIcon(unsigned int index);
368
369   // allAvailableAreas should be used whenever possible instead of this function
370   // as then Xinerama will work correctly.
371   const Rect& availableArea(void) const;
372 #ifdef    XINERAMA
373   const RectList& allAvailableAreas(void) const;
374 #endif // XINERAMA
375   void updateAvailableArea(void);
376   void addStrut(Strut *strut);
377   void removeStrut(Strut *strut);
378
379   unsigned int addWorkspace(void);
380   unsigned int removeLastWorkspace(void);
381   void changeWorkspaceID(unsigned int id);
382   void saveWorkspaceNames(void);
383
384   void addNetizen(Netizen *n);
385   void removeNetizen(Window w);
386
387   void addSystrayWindow(Window window);
388   void removeSystrayWindow(Window window);
389
390   void addIcon(BlackboxWindow *w);
391   void removeIcon(BlackboxWindow *w);
392
393   void updateClientList(void);
394   void updateStackingList(void);
395   void manageWindow(Window w);
396   void unmanageWindow(BlackboxWindow *w, bool remap);
397   void raiseWindows(Window *workspace_stack, unsigned int num);
398   void lowerWindows(Window *workspace_stack, unsigned int num);
399   void reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
400                          bool ignore_sticky);
401   void propagateWindowName(const BlackboxWindow *bw);
402   void prevFocus(void) const;
403   void nextFocus(void) const;
404   void raiseFocus(void) const;
405   void load_rc(void);
406   void save_rc(void);
407   void reconfigure(void);
408   void toggleFocusModel(FocusModel model);
409   void rereadMenu(void);
410   void shutdown(void);
411   void showPosition(int x, int y);
412   void showGeometry(unsigned int gx, unsigned int gy);
413   void hideGeometry(void);
414
415   void showWorkspaceMenu(int x, int y);
416   void showRootMenu(int x, int y);
417
418   void buttonPressEvent(const XButtonEvent *xbutton);
419   void propertyNotifyEvent(const XPropertyEvent *pe);
420
421   void updateNetizenCurrentWorkspace(void);
422   void updateNetizenWorkspaceCount(void);
423   void updateNetizenWindowFocus(void);
424   void updateNetizenWindowAdd(Window w, unsigned long p);
425   void updateNetizenWindowDel(Window w);
426   void updateNetizenConfigNotify(XEvent *e);
427   void updateNetizenWindowRaise(Window w);
428   void updateNetizenWindowLower(Window w);
429 };
430
431
432 #endif // __Screen_hh