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, 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 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; }
267 inline const GC &getOpGC(void) const { return opGC; }
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; }
274 inline Slit *getSlit(void) { return slit; }
275 inline Toolbar *getToolbar(void) { return toolbar; }
277 Workspace *getWorkspace(unsigned int index) const;
279 inline Workspace *getCurrentWorkspace(void) { return current_workspace; }
281 inline Workspacemenu *getWorkspacemenu(void) { return workspacemenu; }
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; }
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; }
318 void changeWorkspaceCount(unsigned int new_count);
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(); }
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
363 inline WindowStyle *getWindowStyle(void) { return &resource.wstyle; }
364 inline MenuStyle *getMenuStyle(void) { return &resource.mstyle; }
365 inline ToolbarStyle *getToolbarStyle(void) { return &resource.tstyle; }
367 BlackboxWindow *getIcon(unsigned int index);
369 // allAvailableAreas should be used whenever possible instead of this function
370 // as then Xinerama will work correctly.
371 const Rect& availableArea(void) const;
373 const RectList& allAvailableAreas(void) const;
375 void updateAvailableArea(void);
376 void addStrut(Strut *strut);
377 void removeStrut(Strut *strut);
379 unsigned int addWorkspace(void);
380 unsigned int removeLastWorkspace(void);
381 void changeWorkspaceID(unsigned int id);
382 void saveWorkspaceNames(void);
384 void addNetizen(Netizen *n);
385 void removeNetizen(Window w);
387 void addSystrayWindow(Window window);
388 void removeSystrayWindow(Window window);
390 void addIcon(BlackboxWindow *w);
391 void removeIcon(BlackboxWindow *w);
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,
401 void propagateWindowName(const BlackboxWindow *bw);
402 void prevFocus(void) const;
403 void nextFocus(void) const;
404 void raiseFocus(void) const;
407 void reconfigure(void);
408 void toggleFocusModel(FocusModel model);
409 void rereadMenu(void);
411 void showPosition(int x, int y);
412 void showGeometry(unsigned int gx, unsigned int gy);
413 void hideGeometry(void);
415 void showWorkspaceMenu(int x, int y);
416 void showRootMenu(int x, int y);
418 void buttonPressEvent(const XButtonEvent *xbutton);
419 void propertyNotifyEvent(const XPropertyEvent *pe);
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);
432 #endif // __Screen_hh