gntwm.h

Go to the documentation of this file.
00001 
00005 /*
00006  * GNT - The GLib Ncurses Toolkit
00007  *
00008  * GNT is the legal property of its developers, whose names are too numerous
00009  * to list here.  Please refer to the COPYRIGHT file distributed with this
00010  * source distribution.
00011  *
00012  * This library is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
00025  */
00026 
00027 #ifndef GNTWM_H
00028 #define GNTWM_H
00029 
00030 #include "gntwidget.h"
00031 #include "gntmenu.h"
00032 #include "gntws.h"
00033 
00034 #include <panel.h>
00035 #include <time.h>
00036 
00037 #define GNT_TYPE_WM             (gnt_wm_get_gtype())
00038 #define GNT_WM(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_WM, GntWM))
00039 #define GNT_WM_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_WM, GntWMClass))
00040 #define GNT_IS_WM(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_WM))
00041 #define GNT_IS_WM_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_WM))
00042 #define GNT_WM_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_WM, GntWMClass))
00043 
00044 typedef enum _GntKeyPressMode
00045 {
00046     GNT_KP_MODE_NORMAL,
00047     GNT_KP_MODE_RESIZE,
00048     GNT_KP_MODE_MOVE,
00049     GNT_KP_MODE_WAIT_ON_CHILD
00050 } GntKeyPressMode;
00051 
00052 typedef struct _GntNode
00053 {
00054     GntWidget *me;
00055 
00056     WINDOW *window;
00057     int scroll;
00058     PANEL *panel;
00059     GntWS *ws;
00060 } GntNode;
00061 
00062 typedef struct _GntWM GntWM;
00063 
00064 typedef struct _GntPosition
00065 {
00066     int x;
00067     int y;
00068 } GntPosition;
00069 
00073 typedef struct _GntAction
00074 {
00075     const char *label;
00076     void (*callback)(void);
00077 } GntAction;
00078 
00079 struct _GntWM
00080 {
00081     GntBindable inherit;
00082 
00083     GMainLoop *loop;
00084 
00085     GList *workspaces;
00086     GList *tagged; /* tagged windows */
00087     GntWS *cws;
00088 
00089     struct {
00090         GntWidget *window;
00091         GntWidget *tree;
00092     } _list,
00093         *windows,         /* Window-list window */
00094         *actions;         /* Action-list window */
00095 
00096     GHashTable *nodes;    /* GntWidget -> GntNode */
00097     GHashTable *name_places;    /* window name -> ws*/
00098     GHashTable *title_places;    /* window title -> ws */
00099 
00100     GList *acts;          /* List of actions */
00101 
00108     GntMenu *menu;        /* Currently active menu */
00109 
00115     gboolean event_stack;
00116 
00117     GntKeyPressMode mode;
00118 
00119     GHashTable *positions;
00120 
00121     void *res1;
00122     void *res2;
00123     void *res3;
00124     void *res4;
00125 };
00126 
00127 typedef struct _GntWMClass GntWMClass;
00128 
00129 struct _GntWMClass
00130 {
00131     GntBindableClass parent;
00132 
00133     /* This is called when a new window is shown */
00134     void (*new_window)(GntWM *wm, GntWidget *win);
00135 
00136     void (*decorate_window)(GntWM *wm, GntWidget *win);
00137     /* This is called when a window is being closed */
00138     gboolean (*close_window)(GntWM *wm, GntWidget *win);
00139 
00140     /* The WM may want to confirm a size for a window first */
00141     gboolean (*window_resize_confirm)(GntWM *wm, GntWidget *win, int *w, int *h);
00142 
00143     void (*window_resized)(GntWM *wm, GntNode *node);
00144 
00145     /* The WM may want to confirm the position of a window */
00146     gboolean (*window_move_confirm)(GntWM *wm, GntWidget *win, int *x, int *y);
00147 
00148     void (*window_moved)(GntWM *wm, GntNode *node);
00149 
00150     /* This gets called when:
00151      *   - the title of the window changes
00152      *   - the 'urgency' of the window changes
00153      */
00154     void (*window_update)(GntWM *wm, GntNode *node);
00155 
00156     /* This should usually return NULL if the keys were processed by the WM.
00157      * If not, the WM can simply return the original string, which will be
00158      * processed by the default WM. The custom WM can also return a different
00159      * static string for the default WM to process.
00160      */
00161     gboolean (*key_pressed)(GntWM *wm, const char *key);
00162 
00163     gboolean (*mouse_clicked)(GntWM *wm, GntMouseEvent event, int x, int y, GntWidget *widget);
00164 
00165     /* Whatever the WM wants to do when a window is given focus */
00166     void (*give_focus)(GntWM *wm, GntWidget *widget);
00167 
00168     /* List of windows. Although the WM can keep a list of its own for the windows,
00169      * it'd be better if there was a way to share between the 'core' and the WM.
00170      */
00171     /*GList *(*window_list)();*/
00172 
00173     /* This is invoked whenever the terminal window is resized, or the
00174      * screen session is attached to a new terminal. (ie, from the
00175      * SIGWINCH callback)
00176      */
00177     void (*terminal_refresh)(GntWM *wm);
00178 
00179     void (*res1)(void);
00180     void (*res2)(void);
00181     void (*res3)(void);
00182 };
00183 
00184 G_BEGIN_DECLS
00185 
00189 GType gnt_wm_get_gtype(void);
00190 
00196 void gnt_wm_add_workspace(GntWM *wm, GntWS *ws);
00197 
00205 gboolean gnt_wm_switch_workspace(GntWM *wm, gint n);
00206 
00211 gboolean gnt_wm_switch_workspace_prev(GntWM *wm);
00212 
00217 gboolean gnt_wm_switch_workspace_next(GntWM *wm);
00218 
00225 void gnt_wm_widget_move_workspace(GntWM *wm, GntWS *neww, GntWidget *widget);
00226 
00232 void gnt_wm_set_workspaces(GntWM *wm, GList *workspaces);
00233 
00240 GntWS *gnt_wm_widget_find_workspace(GntWM *wm, GntWidget *widget);
00241 
00248 void gnt_wm_new_window(GntWM *wm, GntWidget *widget);
00249 
00255 void gnt_wm_window_decorate(GntWM *wm, GntWidget *widget);
00256 
00262 void gnt_wm_window_close(GntWM *wm, GntWidget *widget);
00263 
00272 gboolean gnt_wm_process_input(GntWM *wm, const char *string);
00273 
00284 gboolean gnt_wm_process_click(GntWM *wm, GntMouseEvent event, int x, int y, GntWidget *widget);
00285 
00293 void gnt_wm_resize_window(GntWM *wm, GntWidget *widget, int width, int height);
00294 
00302 void gnt_wm_move_window(GntWM *wm, GntWidget *widget, int x, int y);
00303 
00309 void gnt_wm_update_window(GntWM *wm, GntWidget *widget);
00310 
00316 void gnt_wm_raise_window(GntWM *wm, GntWidget *widget);
00317 
00321 void gnt_wm_set_event_stack(GntWM *wm, gboolean set);
00322 
00326 void gnt_wm_copy_win(GntWidget *widget, GntNode *node);
00327 
00331 time_t gnt_wm_get_idle_time(void);
00332 
00333 G_END_DECLS
00334 #endif