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.
29 #include <X11/Xresource.h>
31 #ifdef TIME_WITH_SYS_TIME
32 # include <sys/time.h>
34 #else // !TIME_WITH_SYS_TIME
35 # ifdef HAVE_SYS_TIME_H
36 # include <sys/time.h>
37 # else // !HAVE_SYS_TIME_H
39 # endif // HAVE_SYS_TIME_H
40 #endif // TIME_WITH_SYS_TIME
49 #include "Configmenu.hh"
50 #include "Iconmenu.hh"
52 #include "Rootmenu.hh"
54 #include "Workspace.hh"
55 #include "Workspacemenu.hh"
56 #include "blackbox.hh"
57 class Slit; // forward reference
59 enum TextJustify { LeftJustify = 1, RightJustify, CenterJustify };
62 BColor f_focus, f_unfocus, l_text_focus, l_text_unfocus, b_pic_focus,
64 BTexture t_focus, t_unfocus, l_focus, l_unfocus, h_focus, h_unfocus,
65 b_focus, b_unfocus, b_pressed, g_focus, g_unfocus;
68 XFontSetExtents *fontset_extents;
73 int doJustify(const char *text, int &start_pos, unsigned int max_length,
74 unsigned int modifier, bool multibyte) const;
78 BColor l_text, w_text, c_text, b_pic;
79 BTexture toolbar, label, window, button, pressed, clock;
82 XFontSetExtents *fontset_extents;
87 int doJustify(const char *text, int &start_pos, unsigned int max_length,
88 unsigned int modifier, bool multibyte) const;
92 BColor t_text, f_text, h_text, d_text;
93 BTexture title, frame, hilite;
95 XFontSet t_fontset, f_fontset;
96 XFontSetExtents *t_fontset_extents, *f_fontset_extents;
97 XFontStruct *t_font, *f_font;
99 TextJustify t_justify, f_justify;
100 int bullet, bullet_pos;
104 unsigned int top, bottom, left, right;
106 Strut(void): top(0), bottom(0), left(0), right(0) {}
109 class BScreen : public ScreenInfo {
111 bool root_colormap_installed, managed, geom_visible;
117 BImageControl *image_control;
118 Configmenu *configmenu;
121 Configuration *config;
123 typedef std::list<Rootmenu*> RootmenuList;
124 RootmenuList rootmenuList;
126 typedef std::list<Netizen*> NetizenList;
127 NetizenList netizenList;
128 BlackboxWindowList iconList, windowList;
132 Workspace *current_workspace;
133 Workspacemenu *workspacemenu;
135 unsigned int geom_w, geom_h;
136 unsigned long event_mask;
140 typedef std::list<Strut*> StrutList;
142 typedef std::vector<std::string> WorkspaceNamesList;
143 WorkspaceNamesList workspaceNames;
144 typedef std::vector<Workspace*> WorkspaceList;
145 WorkspaceList workspacesList;
147 struct screen_resource {
152 bool sloppy_focus, auto_raise, auto_edge_balance, ordered_dither,
153 opaque_move, full_max, focus_new, focus_last, click_raise,
157 unsigned int workspaces;
158 int toolbar_placement, toolbar_width_percent, placement_policy,
159 edge_snap_threshold, row_direction, col_direction;
161 unsigned int handle_width, bevel_width, frame_width, border_width;
164 std::string strftime_format;
165 #else // !HAVE_STRFTIME
168 #endif // HAVE_STRFTIME
171 std::string screenstr;
173 BScreen(const BScreen&);
174 BScreen& operator=(const BScreen&);
176 bool parseMenuFile(FILE *file, Rootmenu *menu);
178 BTexture readDatabaseTexture(const std::string &rname,
179 const std::string &default_color,
180 Configuration &style);
181 BColor readDatabaseColor(const std::string &rname,
182 const std::string &default_color,
183 Configuration &style);
184 XFontSet readDatabaseFontSet(const std::string &rname, Configuration &style);
185 XFontStruct *readDatabaseFont(const std::string &rname, Configuration &style);
186 XFontSet createFontSet(const std::string &fontname);
189 void LoadStyle(void);
193 enum { RowSmartPlacement = 1, ColSmartPlacement, CascadePlacement,
194 UnderMousePlacement, LeftRight, RightLeft, TopBottom, BottomTop };
195 enum { RoundBullet = 1, TriangleBullet, SquareBullet, NoBullet };
196 enum { Restart = 1, RestartOther, Exit, Shutdown, Execute, Reconfigure,
197 WindowShade, WindowIconify, WindowMaximize, WindowClose, WindowRaise,
198 WindowLower, WindowStick, WindowKill, SetStyle };
199 enum FocusModel { SloppyFocus, ClickToFocus };
201 BScreen(Blackbox *bb, unsigned int scrn);
204 inline bool isSloppyFocus(void) const { return resource.sloppy_focus; }
205 inline bool isRootColormapInstalled(void) const
206 { return root_colormap_installed; }
207 inline bool doAutoRaise(void) const { return resource.auto_raise; }
208 inline bool doClickRaise(void) const { return resource.click_raise; }
209 inline bool isScreenManaged(void) const { return managed; }
210 inline bool doImageDither(void) const { return image_control->doDither(); }
211 inline bool doOrderedDither(void) const { return resource.ordered_dither; }
212 inline bool doOpaqueMove(void) const { return resource.opaque_move; }
213 inline bool doFullMax(void) const { return resource.full_max; }
214 inline bool doFocusNew(void) const { return resource.focus_new; }
215 inline bool doFocusLast(void) const { return resource.focus_last; }
216 inline bool doHideToolbar(void) const { return resource.hide_toolbar; }
218 inline const GC &getOpGC(void) const { return opGC; }
220 inline Blackbox *getBlackbox(void) { return blackbox; }
221 inline BColor *getBorderColor(void) { return &resource.border_color; }
222 inline BImageControl *getImageControl(void) { return image_control; }
223 inline Rootmenu *getRootmenu(void) { return rootmenu; }
225 inline Slit *getSlit(void) { return slit; }
226 inline Toolbar *getToolbar(void) { return toolbar; }
228 Workspace *getWorkspace(unsigned int index);
230 inline Workspace *getCurrentWorkspace(void) { return current_workspace; }
232 inline Workspacemenu *getWorkspacemenu(void) { return workspacemenu; }
234 inline unsigned int getHandleWidth(void) const
235 { return resource.handle_width; }
236 inline unsigned int getBevelWidth(void) const
237 { return resource.bevel_width; }
238 inline unsigned int getFrameWidth(void) const
239 { return resource.frame_width; }
240 inline unsigned int getBorderWidth(void) const
241 { return resource.border_width; }
243 inline unsigned int getCurrentWorkspaceID(void)
244 { return current_workspace->getID(); }
245 inline unsigned int getWorkspaceCount(void)
246 { return workspacesList.size(); }
247 inline unsigned int getIconCount(void) { return iconList.size(); }
248 inline unsigned int getNumberOfWorkspaces(void) const
249 { return resource.workspaces; }
250 inline int getPlacementPolicy(void) const
251 { return resource.placement_policy; }
252 inline int getEdgeSnapThreshold(void) const
253 { return resource.edge_snap_threshold; }
254 inline int getRowPlacementDirection(void) const
255 { return resource.row_direction; }
256 inline int getColPlacementDirection(void) const
257 { return resource.col_direction; }
259 inline void setRootColormapInstalled(bool r) { root_colormap_installed = r; }
260 void saveSloppyFocus(bool s);
261 void saveAutoRaise(bool a);
262 void saveClickRaise(bool c);
263 void saveWorkspaces(unsigned int w);
264 void savePlacementPolicy(int p);
265 void saveRowPlacementDirection(int d);
266 void saveColPlacementDirection(int d);
267 void saveEdgeSnapThreshold(int t);
268 void saveImageDither(bool d);
269 void saveOpaqueMove(bool o);
270 void saveFullMax(bool f);
271 void saveFocusNew(bool f);
272 void saveFocusLast(bool f);
273 void saveHideToolbar(bool h);
274 inline void iconUpdate(void) { iconmenu->update(); }
277 inline const char *getStrftimeFormat(void)
278 { return resource.strftime_format.c_str(); }
279 void saveStrftimeFormat(const std::string& format);
280 #else // !HAVE_STRFTIME
281 inline int getDateFormat(void) { return resource.date_format; }
282 inline void saveDateFormat(int f);
283 inline bool isClock24Hour(void) { return resource.clock24hour; }
284 inline void saveClock24Hour(bool c);
285 #endif // HAVE_STRFTIME
287 inline WindowStyle *getWindowStyle(void) { return &resource.wstyle; }
288 inline MenuStyle *getMenuStyle(void) { return &resource.mstyle; }
289 inline ToolbarStyle *getToolbarStyle(void) { return &resource.tstyle; }
291 BlackboxWindow *getIcon(unsigned int index);
293 const Rect& availableArea(void) const;
294 void updateAvailableArea(void);
295 void addStrut(Strut *strut);
296 void removeStrut(Strut *strut);
298 unsigned int addWorkspace(void);
299 unsigned int removeLastWorkspace(void);
300 void removeWorkspaceNames(void);
301 void addWorkspaceName(const std::string& name);
302 const std::string getNameOfWorkspace(unsigned int id);
303 void changeWorkspaceID(unsigned int id);
304 void saveWorkspaceNames(void);
306 void addNetizen(Netizen *n);
307 void removeNetizen(Window w);
309 void addIcon(BlackboxWindow *w);
310 void removeIcon(BlackboxWindow *w);
312 void manageWindow(Window w);
313 void unmanageWindow(BlackboxWindow *w, bool remap);
314 void raiseWindows(Window *workspace_stack, unsigned int num);
315 void reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
317 void propagateWindowName(const BlackboxWindow *bw);
318 void prevFocus(void);
319 void nextFocus(void);
320 void raiseFocus(void);
323 void reconfigure(void);
324 void toggleFocusModel(FocusModel model);
325 void updateFocusModel(void);
326 void rereadMenu(void);
328 void showPosition(int x, int y);
329 void showGeometry(unsigned int gx, unsigned int gy);
330 void hideGeometry(void);
332 void buttonPressEvent(XButtonEvent *xbutton);
334 void updateNetizenCurrentWorkspace(void);
335 void updateNetizenWorkspaceCount(void);
336 void updateNetizenWindowFocus(void);
337 void updateNetizenWindowAdd(Window w, unsigned long p);
338 void updateNetizenWindowDel(Window w);
339 void updateNetizenConfigNotify(XEvent *e);
340 void updateNetizenWindowRaise(Window w);
341 void updateNetizenWindowLower(Window w);
345 #endif // __Screen_hh