Update to 24f58c58bb8d22c0e8e6c5ce43c536c47b719bc6
[gnt.git] / gntwm.h
blob4d8ace2428482af28fad2c3fee39af5fd1802706
1 /**
2 * @file gntwm.h Window-manager API
3 * @ingroup gnt
4 */
5 /*
6 * GNT - The GLib Ncurses Toolkit
8 * GNT is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This library is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 #ifndef GNTWM_H
28 #define GNTWM_H
30 #include "gntwidget.h"
31 #include "gntmenu.h"
32 #include "gntws.h"
34 #include <panel.h>
35 #include <time.h>
37 #define GNT_TYPE_WM (gnt_wm_get_gtype())
38 #define GNT_WM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_WM, GntWM))
39 #define GNT_WM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_WM, GntWMClass))
40 #define GNT_IS_WM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_WM))
41 #define GNT_IS_WM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_WM))
42 #define GNT_WM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_WM, GntWMClass))
44 typedef enum _GntKeyPressMode
46 GNT_KP_MODE_NORMAL,
47 GNT_KP_MODE_RESIZE,
48 GNT_KP_MODE_MOVE,
49 GNT_KP_MODE_WAIT_ON_CHILD
50 } GntKeyPressMode;
52 typedef struct _GntNode
54 GntWidget *me;
56 WINDOW *window;
57 int scroll;
58 PANEL *panel;
59 GntWS *ws;
60 } GntNode;
62 typedef struct _GntWM GntWM;
64 typedef struct _GntPosition
66 int x;
67 int y;
68 } GntPosition;
70 /**
71 * An application can register actions which will show up in a 'start-menu' like popup
73 typedef struct _GntAction
75 const char *label;
76 void (*callback)(void);
77 } GntAction;
79 struct _GntWM
81 GntBindable inherit;
83 GMainLoop *loop;
85 GList *workspaces;
86 GList *tagged; /* tagged windows */
87 GntWS *cws;
89 struct {
90 GntWidget *window;
91 GntWidget *tree;
92 } _list,
93 *windows, /* Window-list window */
94 *actions; /* Action-list window */
96 GHashTable *nodes; /* GntWidget -> GntNode */
97 GHashTable *name_places; /* window name -> ws*/
98 GHashTable *title_places; /* window title -> ws */
100 GList *acts; /* List of actions */
103 * There can be at most one menu at a time on the screen.
104 * If there is a menu being displayed, then all the keystrokes will be sent to
105 * the menu until it is closed, either when the user activates a menuitem, or
106 * presses Escape to cancel the menu.
108 GntMenu *menu; /* Currently active menu */
111 * 'event_stack' will be set to TRUE when a user-event, ie. a mouse-click
112 * or a key-press is being processed. This variable will be used to determine
113 * whether to give focus to a new window.
115 gboolean event_stack;
117 GntKeyPressMode mode;
119 GHashTable *positions;
121 void *res1;
122 void *res2;
123 void *res3;
124 void *res4;
127 typedef struct _GntWMClass GntWMClass;
129 struct _GntWMClass
131 GntBindableClass parent;
133 /* This is called when a new window is shown */
134 void (*new_window)(GntWM *wm, GntWidget *win);
136 void (*decorate_window)(GntWM *wm, GntWidget *win);
137 /* This is called when a window is being closed */
138 gboolean (*close_window)(GntWM *wm, GntWidget *win);
140 /* The WM may want to confirm a size for a window first */
141 gboolean (*window_resize_confirm)(GntWM *wm, GntWidget *win, int *w, int *h);
143 void (*window_resized)(GntWM *wm, GntNode *node);
145 /* The WM may want to confirm the position of a window */
146 gboolean (*window_move_confirm)(GntWM *wm, GntWidget *win, int *x, int *y);
148 void (*window_moved)(GntWM *wm, GntNode *node);
150 /* This gets called when:
151 * - the title of the window changes
152 * - the 'urgency' of the window changes
154 void (*window_update)(GntWM *wm, GntNode *node);
156 /* This should usually return NULL if the keys were processed by the WM.
157 * If not, the WM can simply return the original string, which will be
158 * processed by the default WM. The custom WM can also return a different
159 * static string for the default WM to process.
161 gboolean (*key_pressed)(GntWM *wm, const char *key);
163 gboolean (*mouse_clicked)(GntWM *wm, GntMouseEvent event, int x, int y, GntWidget *widget);
165 /* Whatever the WM wants to do when a window is given focus */
166 void (*give_focus)(GntWM *wm, GntWidget *widget);
168 /* List of windows. Although the WM can keep a list of its own for the windows,
169 * it'd be better if there was a way to share between the 'core' and the WM.
171 /*GList *(*window_list)();*/
173 /* This is invoked whenever the terminal window is resized, or the
174 * screen session is attached to a new terminal. (ie, from the
175 * SIGWINCH callback)
177 void (*terminal_refresh)(GntWM *wm);
179 void (*res1)(void);
180 void (*res2)(void);
181 void (*res3)(void);
184 G_BEGIN_DECLS
187 * @return GType for GntWM.
189 GType gnt_wm_get_gtype(void);
192 * Add a workspace.
193 * @param wm The window-manager.
194 * @param ws The workspace to add.
196 void gnt_wm_add_workspace(GntWM *wm, GntWS *ws);
199 * Switch to a workspace.
200 * @param wm The window-manager.
201 * @param n Index of the workspace to switch to.
203 * @return @c TRUE if the switch was successful.
205 gboolean gnt_wm_switch_workspace(GntWM *wm, gint n);
208 * Switch to the previous workspace from the current one.
209 * @param wm The window-manager.
211 gboolean gnt_wm_switch_workspace_prev(GntWM *wm);
214 * Switch to the next workspace from the current one.
215 * @param wm The window-manager.
217 gboolean gnt_wm_switch_workspace_next(GntWM *wm);
220 * Move a window to a specific workspace.
221 * @param wm The window manager.
222 * @param neww The new workspace.
223 * @param widget The widget to move.
225 void gnt_wm_widget_move_workspace(GntWM *wm, GntWS *neww, GntWidget *widget);
228 * Set the list of workspaces .
229 * @param wm The window manager.
230 * @param workspaces The list of workspaces.
232 void gnt_wm_set_workspaces(GntWM *wm, GList *workspaces);
235 * Find the workspace that contains a specific widget.
236 * @param wm The window-manager.
237 * @param widget The widget to find.
238 * @return The workspace that has the widget.
240 GntWS *gnt_wm_widget_find_workspace(GntWM *wm, GntWidget *widget);
243 * Process a new window.
245 * @param wm The window-manager.
246 * @param widget The new window.
248 void gnt_wm_new_window(GntWM *wm, GntWidget *widget);
251 * Decorate a window.
252 * @param wm The window-manager.
253 * @param widget The widget to decorate.
255 void gnt_wm_window_decorate(GntWM *wm, GntWidget *widget);
258 * Close a window.
259 * @param wm The window-manager.
260 * @param widget The window to close.
262 void gnt_wm_window_close(GntWM *wm, GntWidget *widget);
265 * Process input.
267 * @param wm The window-manager.
268 * @param string The input string to process.
270 * @return @c TRUE of the string was processed, @c FALSE otherwise.
272 gboolean gnt_wm_process_input(GntWM *wm, const char *string);
275 * Process a click event.
276 * @param wm The window manager.
277 * @param event The mouse event.
278 * @param x The x-coordinate of the mouse.
279 * @param y The y-coordinate of the mouse.
280 * @param widget The widget under the mouse.
282 * @return @c TRUE if the event was handled, @c FALSE otherwise.
284 gboolean gnt_wm_process_click(GntWM *wm, GntMouseEvent event, int x, int y, GntWidget *widget);
287 * Resize a window.
288 * @param wm The window manager.
289 * @param widget The window to resize.
290 * @param width The desired width of the window.
291 * @param height The desired height of the window.
293 void gnt_wm_resize_window(GntWM *wm, GntWidget *widget, int width, int height);
296 * Move a window.
297 * @param wm The window manager.
298 * @param widget The window to move.
299 * @param x The desired x-coordinate of the window.
300 * @param y The desired y-coordinate of the window.
302 void gnt_wm_move_window(GntWM *wm, GntWidget *widget, int x, int y);
305 * Update a window.
306 * @param wm The window-manager.
307 * @param widget The window to update.
309 void gnt_wm_update_window(GntWM *wm, GntWidget *widget);
312 * Raise a window.
313 * @param wm The window-manager.
314 * @param widget The window to raise.
316 void gnt_wm_raise_window(GntWM *wm, GntWidget *widget);
319 * @internal
321 void gnt_wm_set_event_stack(GntWM *wm, gboolean set);
324 * @internal
326 void gnt_wm_copy_win(GntWidget *widget, GntNode *node);
329 * @return The idle time of the user.
331 time_t gnt_wm_get_idle_time(void);
333 G_END_DECLS
334 #endif