kernel.h (5922B)
1 // Copyright (c) 2003 - 2009 Anselm R Garbe <anselm@garbe.us> 2 // See LICENSE for license details. 3 4 #ifndef __KERNEL_H 5 #define __KERNEL_H 6 7 #include "singleton.h" 8 9 extern "C" { 10 #include <X11/Xlib.h> 11 } 12 13 // STL list 14 #include <list> 15 #include <string> 16 #include <map> 17 18 #include "wmi.h" 19 20 // forward declaration 21 class Action; 22 class Bar; 23 class Box; 24 class Client; 25 template <class P, class LT, class LTI, class T> class Container; 26 class Frame; 27 class Kernel; 28 class Menu; 29 class Monitor; 30 class Prompt; 31 class Rectangle; 32 class Shortcut; 33 #ifdef SLOT_SUPPORT 34 class Slot; 35 #endif // SLOT_SUPPORT 36 class Thing; 37 class Workspace; 38 39 typedef list<Action *> LAction; 40 typedef list<Monitor *> LMonitor; 41 typedef map<string, string, less<string> > MSettings; 42 typedef map<string, Action *, less<string> > MBindings; 43 typedef Container<Kernel, LMonitor, LMonitor::iterator, Monitor> CMonitor; 44 45 /** 46 * Main controller of WMI. Contains all base functionality 47 * of a window manager. 48 */ 49 class Kernel : public Singleton<Kernel> 50 { 51 52 public: 53 54 /** Constructs a new window manager instance. */ 55 Kernel(); 56 57 ~Kernel(); 58 59 /** Returns settings. */ 60 MSettings *themeSettings(); 61 62 MSettings *commonSettings(); 63 64 MSettings *actionSettings(); 65 66 MSettings *sessionSettings(); 67 68 /** Returns the display. */ 69 Display *display() const; 70 71 /** Returns the currently focused monitor. */ 72 Monitor *focusedMonitor() const; 73 74 /** Returns wether input mode is active. */ 75 bool isInputMode(); 76 77 /** Returns focused client. */ 78 Client *focusedClient(); 79 80 void killClient(Client *client); 81 82 /** Returns the root window. */ 83 Window rootWindow(); 84 85 /** Returns the default root window (of deafault monitor). */ 86 Window defaultRootWindow(); 87 88 /** Runlevel enum. */ 89 enum Runlevel {START, RUN, STOP, RESTART}; 90 91 Runlevel runlevel() const; 92 93 /** Start method. */ 94 int start(char *argv[], 95 Display *display, 96 MSettings *themeSettings, 97 MSettings *commonSettings, 98 MSettings *actionSettings, 99 MSettings *sessionSettings, 100 bool isFirstRun = false); 101 102 void stop(); 103 void restart(); 104 105 /** Updates all bars.*/ 106 void updateBars(); 107 108 /** Saves session settings. */ 109 void saveSettings(); 110 111 MBindings *actionBindings() const; 112 113 /** Returns <code>true</code> if window is a root window. */ 114 bool isRootWindow(Window window); 115 116 /** Returns bar if window is a barwindow. */ 117 Bar *barWindow(Window window); 118 119 /** Returns box if window is a boxwindow. */ 120 Box *boxWindow(Window window); 121 122 /** Returns menu if window is a menu window. */ 123 Menu *menuWindow(Window window); 124 125 #ifdef SLOT_SUPPORT 126 /** Returns slot if window is a slot window. */ 127 Slot *slotWindow(Window window); 128 #endif // SLOT_SUPPORT 129 130 /** Returns frame if window is a frame window. */ 131 Thing *thingWindow(Window window); 132 133 /** Returns <code>true</code> if window is a WMI window. */ 134 bool isWMIWindow(Window window); 135 136 /** Returns client for this window. */ 137 Client *clientForWindow(Window window); 138 139 /** Binds the shortcut for the given <action id>=<key> pair. */ 140 void bindShortcut(string argument); 141 142 void installCursor(Cursor cursor, Window window); 143 144 /** Adds client. */ 145 void addClient(Client *client); 146 147 /** Main event loop. */ 148 int run(); 149 150 /** Resize event loop. */ 151 void runResizeMode(Thing *thing, XButtonEvent *buttonEvent, 152 Direction dir, bool resize = false); 153 154 bool isRecording() const; 155 156 LAction *recordedActions(); 157 158 void beginRecording(); 159 void endChainRecording(string name); 160 void endScriptRecording(string name); 161 void cancelRecording(); 162 163 164 unsigned int borderWidth() const; 165 166 void cleanup(); 167 168 Prompt *defaultPrompt() const; 169 170 void setMenuMode(bool isMenuMode); 171 172 void toggleSloppyMode(); 173 174 bool isStackedTabbing() const; 175 176 void toggleShortcuts(); 177 178 CMonitor *monitors() const; 179 void selectMonitor(string displayString); 180 181 /** Enters runResizeMode for moving focussed clients with a 182 faked XButtonEvent. */ 183 void grabMove(); 184 185 private: 186 187 /** event handler. */ 188 void handleButtonPress(XButtonEvent *event); 189 void handleButtonRelease(XButtonEvent *event); 190 void handleConfigureRequest(XConfigureRequestEvent *event); 191 void handleClientMessage(XClientMessageEvent *event); 192 void handleCreateNotify(XCreateWindowEvent *event); 193 void handleDestroyNotify(XDestroyWindowEvent *event); 194 void handleExpose(XExposeEvent *event); 195 void handleKeyPress(XKeyEvent *event); 196 void handleMapRequest(XMapRequestEvent *event); 197 void handleMotionNotify(XMotionEvent *event); 198 void handlePropertyNotify(XPropertyEvent *event); 199 void handleUnmapNotify(XUnmapEvent *event); 200 201 /** Atom initialization. */ 202 void initAtoms(); 203 204 /** Inits all monitors. */ 205 void initMonitors(); 206 207 /** Inits all existing windows. */ 208 void initWindows(); 209 210 /** Inits the bind map for all actions. */ 211 void initActionBindings(); 212 213 /** Inits keys on all monitors. */ 214 void initKeys(); 215 216 /** Grabs shortcut on all monitors. */ 217 void grabShortcutOnAllMonitors(Shortcut *shortcut); 218 219 /** Ungrabs shortcut on all monitors. */ 220 void ungrabShortcutOnAllMonitors(Shortcut *shortcut); 221 222 /** 223 * Serializes and updates all settings. 224 */ 225 void serialize(); 226 227 bool isSloppyMode_; 228 bool isRecording_; 229 LAction recordedActions_; 230 Display *display_; 231 CMonitor *monitors_; 232 233 unsigned int borderWidth_; 234 bool isMenuMode_; 235 bool isStackedTabbing_; 236 237 // default rc settings 238 MSettings *themeSettings_; 239 MSettings *commonSettings_; 240 MSettings *actionSettings_; 241 MSettings *sessionSettings_; 242 243 // bind map 244 MBindings *actionBindings_; 245 246 Runlevel runlevel_; 247 Prompt *defaultPrompt_; 248 249 }; 250 251 #endif // __KERNEL_H