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)
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:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
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.
30 #ifdef TIME_WITH_SYS_TIME
31 # include <sys/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
38 # endif // HAVE_SYS_TIME_H
39 #endif // TIME_WITH_SYS_TIME
48 #include "Configmenu.hh"
49 #include "Iconmenu.hh"
51 #include "Rootmenu.hh"
53 #include "Workspace.hh"
54 #include "Workspacemenu.hh"
55 #include "blackbox.hh"
57 class Slit; // forward reference
62 enum TextJustify { LeftJustify = 1, RightJustify, CenterJustify };
69 #endif // BITMAPBUTTONS
72 BColor l_text_focus, l_text_unfocus, b_pic_focus,
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;
79 PixmapMask close_button, max_button, icon_button, stick_button;
80 #endif // BITMAPBUTTONS
85 void doJustify(const std::string &text, int &start_pos,
86 unsigned int max_length, unsigned int modifier) const;
90 BColor l_text, w_text, c_text, b_pic;
91 BTexture toolbar, label, window, button, pressed, clock;
94 PixmapMask left_button, right_button;
95 #endif // BITMAPBUTTONS
101 void doJustify(const std::string &text, int &start_pos,
102 unsigned int max_length, unsigned int modifier) const;
106 BColor t_text, f_text, h_text, d_text;
107 BTexture title, frame, hilite;
110 PixmapMask bullet_image, tick_image;
111 #endif // BITMAPBUTTONS
113 BFont *t_font, *f_font;
115 TextJustify t_justify, f_justify;
116 int bullet, bullet_pos;
119 class BScreen : public ScreenInfo {
121 bool root_colormap_installed, managed, geom_visible;
127 BImageControl *image_control;
128 Configmenu *configmenu;
131 Configuration *config;
134 typedef std::list<Rootmenu*> RootmenuList;
135 RootmenuList rootmenuList;
137 typedef std::list<Netizen*> NetizenList;
138 NetizenList netizenList;
139 BlackboxWindowList iconList, windowList;
141 typedef std::vector<Window> WindowList;
142 WindowList specialWindowList, desktopWindowList, systrayWindowList;
146 Workspace *current_workspace;
147 Workspacemenu *workspacemenu;
149 unsigned int geom_w, geom_h;
150 unsigned long event_mask;
154 RectList xineramaUsableArea;
157 typedef std::list<Strut*> StrutList;
159 typedef std::vector<Workspace*> WorkspaceList;
160 WorkspaceList workspacesList;
162 struct screen_resource {
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;
172 int snap_to_windows, snap_to_edges;
173 unsigned int snap_offset;
177 unsigned int workspaces;
178 int toolbar_placement, toolbar_width_percent, placement_policy,
179 snap_threshold, row_direction, col_direction, root_scroll,
182 unsigned int handle_width, bevel_width, frame_width, border_width,
185 unsigned int root_menu_button, workspace_menu_button;
188 std::string strftime_format;
189 #else // !HAVE_STRFTIME
192 #endif // HAVE_STRFTIME
195 std::string screenstr;
197 BScreen(const BScreen&);
198 BScreen& operator=(const BScreen&);
200 bool parseMenuFile(FILE *file, Rootmenu *menu);
203 void readDatabaseMask(const std::string &rname,
204 PixmapMask &pixmapMask,
205 const Configuration &style);
206 #endif // BITMAPBUTTONS
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);
219 void LoadStyle(void);
221 void updateWorkArea(void);
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 };
234 BScreen(Blackbox *bb, unsigned int scrn);
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; }
268 inline const GC &getOpGC(void) const { return opGC; }
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; }
275 inline Slit *getSlit(void) { return slit; }
276 inline Toolbar *getToolbar(void) { return toolbar; }
278 Workspace *getWorkspace(unsigned int index) const;
280 inline Workspace *getCurrentWorkspace(void) { return current_workspace; }
282 inline Workspacemenu *getWorkspacemenu(void) { return workspacemenu; }
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; }
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; }
319 void changeWorkspaceCount(unsigned int new_count);
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(); }
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
365 inline WindowStyle *getWindowStyle(void) { return &resource.wstyle; }
366 inline MenuStyle *getMenuStyle(void) { return &resource.mstyle; }
367 inline ToolbarStyle *getToolbarStyle(void) { return &resource.tstyle; }
369 BlackboxWindow *getIcon(unsigned int index);
371 // allAvailableAreas should be used whenever possible instead of this function
372 // as then Xinerama will work correctly.
373 const Rect& availableArea(void) const;
375 const RectList& allAvailableAreas(void) const;
377 void updateAvailableArea(void);
378 void addStrut(Strut *strut);
379 void removeStrut(Strut *strut);
381 unsigned int addWorkspace(void);
382 unsigned int removeLastWorkspace(void);
383 void changeWorkspaceID(unsigned int id);
384 void saveWorkspaceNames(void);
386 void addNetizen(Netizen *n);
387 void removeNetizen(Window w);
389 void addSystrayWindow(Window window);
390 void removeSystrayWindow(Window window);
392 void addIcon(BlackboxWindow *w);
393 void removeIcon(BlackboxWindow *w);
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,
403 void propagateWindowName(const BlackboxWindow *bw);
404 void prevFocus(void) const;
405 void nextFocus(void) const;
406 void raiseFocus(void) const;
409 void reconfigure(void);
410 void toggleFocusModel(FocusModel model);
411 void rereadMenu(void);
413 void showPosition(int x, int y);
414 void showGeometry(unsigned int gx, unsigned int gy);
415 void hideGeometry(void);
417 void showWorkspaceMenu(int x, int y);
418 void showRootMenu(int x, int y);
420 void buttonPressEvent(const XButtonEvent *xbutton);
421 void propertyNotifyEvent(const XPropertyEvent *pe);
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);
434 #endif // __Screen_hh