Mercurial > pidgin
annotate finch/libgnt/gntws.c @ 22217:ad357ca94de9
We will probably eventually use purple_object_[get|set]_ui_data. Until then, this will do.
| author | Sadrul Habib Chowdhury <imadil@gmail.com> |
|---|---|
| date | Sat, 26 Jan 2008 22:33:08 +0000 |
| parents | 9187d331aebe |
| children | bec28e60aff6 |
| rev | line source |
|---|---|
| 17699 | 1 #include <gmodule.h> |
| 2 | |
| 3 #include "gntbox.h" | |
|
17707
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
17702
diff
changeset
|
4 #include "gntwidget.h" |
|
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
17702
diff
changeset
|
5 #include "gntwindow.h" |
| 17699 | 6 #include "gntwm.h" |
|
17707
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
17702
diff
changeset
|
7 #include "gntws.h" |
| 17699 | 8 |
| 9 static void | |
| 10 widget_hide(gpointer data, gpointer nodes) | |
| 11 { | |
| 12 GntWidget *widget = GNT_WIDGET(data); | |
| 13 GntNode *node = g_hash_table_lookup(nodes, widget); | |
|
17707
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
17702
diff
changeset
|
14 if (GNT_IS_WINDOW(widget)) |
|
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
17702
diff
changeset
|
15 gnt_window_workspace_hiding(GNT_WINDOW(widget)); |
| 17699 | 16 hide_panel(node->panel); |
| 17 } | |
| 18 | |
| 19 static void | |
| 20 widget_show(gpointer data, gpointer nodes) | |
| 21 { | |
| 22 GntNode *node = g_hash_table_lookup(nodes, data); | |
| 23 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(data), GNT_WIDGET_INVISIBLE); | |
| 24 if (node) { | |
| 25 show_panel(node->panel); | |
| 26 gnt_wm_copy_win(GNT_WIDGET(data), node); | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 void | |
| 31 gnt_ws_draw_taskbar(GntWS *ws, gboolean reposition) | |
| 32 { | |
| 33 static WINDOW *taskbar = NULL; | |
| 34 GList *iter; | |
| 35 int n, width = 0; | |
| 36 int i; | |
| 37 | |
|
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18416
diff
changeset
|
38 if (gnt_is_refugee()) |
|
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18416
diff
changeset
|
39 return; |
|
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18416
diff
changeset
|
40 |
| 17699 | 41 if (taskbar == NULL) { |
| 42 taskbar = newwin(1, getmaxx(stdscr), getmaxy(stdscr) - 1, 0); | |
| 43 } else if (reposition) { | |
| 44 int Y_MAX = getmaxy(stdscr) - 1; | |
| 45 mvwin(taskbar, Y_MAX, 0); | |
| 46 } | |
| 47 | |
|
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18421
diff
changeset
|
48 wbkgdset(taskbar, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); |
| 17699 | 49 werase(taskbar); |
| 50 | |
| 51 n = g_list_length(ws->list); | |
| 52 if (n) | |
| 53 width = getmaxx(stdscr) / n; | |
| 54 | |
| 55 for (i = 0, iter = ws->list; iter; iter = iter->next, i++) { | |
| 56 GntWidget *w = iter->data; | |
| 57 int color; | |
| 58 const char *title; | |
| 59 | |
| 60 if (w == ws->ordered->data) { | |
| 61 /* This is the current window in focus */ | |
| 62 color = GNT_COLOR_TITLE; | |
| 63 } else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) { | |
| 64 /* This is a window with the URGENT hint set */ | |
| 65 color = GNT_COLOR_URGENT; | |
| 66 } else { | |
| 67 color = GNT_COLOR_NORMAL; | |
| 68 } | |
|
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18421
diff
changeset
|
69 wbkgdset(taskbar, '\0' | gnt_color_pair(color)); |
| 17699 | 70 if (iter->next) |
|
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18421
diff
changeset
|
71 mvwhline(taskbar, 0, width * i, ' ' | gnt_color_pair(color), width); |
| 17699 | 72 else |
|
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18421
diff
changeset
|
73 mvwhline(taskbar, 0, width * i, ' ' | gnt_color_pair(color), getmaxx(stdscr) - width * i); |
| 17699 | 74 title = GNT_BOX(w)->title; |
| 75 mvwprintw(taskbar, 0, width * i, "%s", title ? title : "<gnt>"); | |
| 76 if (i) | |
|
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18421
diff
changeset
|
77 mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | gnt_color_pair(GNT_COLOR_NORMAL)); |
| 17699 | 78 } |
| 79 wrefresh(taskbar); | |
| 80 } | |
| 81 | |
| 82 static void | |
| 83 gnt_ws_init(GTypeInstance *instance, gpointer class) | |
| 84 { | |
| 85 GntWS *ws = GNT_WS(instance); | |
| 86 ws->list = NULL; | |
| 87 ws->ordered = NULL; | |
| 88 ws->name = NULL; | |
| 89 } | |
| 90 | |
| 91 void gnt_ws_add_widget(GntWS *ws, GntWidget* wid) | |
| 92 { | |
|
18223
5023ad94ebc9
Notify a window when it loses focus because another window was moved to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18075
diff
changeset
|
93 GntWidget *oldfocus; |
|
5023ad94ebc9
Notify a window when it loses focus because another window was moved to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18075
diff
changeset
|
94 oldfocus = ws->ordered ? ws->ordered->data : NULL; |
| 17699 | 95 ws->list = g_list_append(ws->list, wid); |
| 96 ws->ordered = g_list_prepend(ws->ordered, wid); | |
|
18223
5023ad94ebc9
Notify a window when it loses focus because another window was moved to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18075
diff
changeset
|
97 if (oldfocus) |
|
5023ad94ebc9
Notify a window when it loses focus because another window was moved to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18075
diff
changeset
|
98 gnt_widget_set_focus(oldfocus, FALSE); |
| 17699 | 99 } |
| 100 | |
| 101 void gnt_ws_remove_widget(GntWS *ws, GntWidget* wid) | |
| 102 { | |
| 103 ws->list = g_list_remove(ws->list, wid); | |
| 104 ws->ordered = g_list_remove(ws->ordered, wid); | |
| 105 } | |
| 106 | |
| 107 void | |
| 108 gnt_ws_set_name(GntWS *ws, const gchar *name) | |
| 109 { | |
| 110 g_free(ws->name); | |
| 111 ws->name = g_strdup(name); | |
| 112 } | |
| 113 | |
| 114 void | |
| 115 gnt_ws_hide(GntWS *ws, GHashTable *nodes) | |
| 116 { | |
| 117 g_list_foreach(ws->ordered, widget_hide, nodes); | |
| 118 } | |
| 119 | |
|
18416
93c5c785a811
Fix some focus issues.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
120 void gnt_ws_widget_hide(GntWidget *widget, GHashTable *nodes) |
|
93c5c785a811
Fix some focus issues.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
121 { |
| 17699 | 122 widget_hide(widget, nodes); |
| 123 } | |
| 124 | |
|
18416
93c5c785a811
Fix some focus issues.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
125 void gnt_ws_widget_show(GntWidget *widget, GHashTable *nodes) |
|
93c5c785a811
Fix some focus issues.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
126 { |
| 17699 | 127 widget_show(widget, nodes); |
| 128 } | |
| 129 | |
| 130 void | |
| 131 gnt_ws_show(GntWS *ws, GHashTable *nodes) | |
| 132 { | |
| 133 GList *l; | |
| 134 for (l = g_list_last(ws->ordered); l; l = g_list_previous(l)) | |
| 135 widget_show(l->data, nodes); | |
| 136 } | |
| 137 | |
| 138 GType | |
| 139 gnt_ws_get_gtype(void) | |
| 140 { | |
| 141 static GType type = 0; | |
| 142 | |
| 143 if(type == 0) { | |
| 144 static const GTypeInfo info = { | |
| 145 sizeof(GntWSClass), | |
| 146 NULL, /* base_init */ | |
| 147 NULL, /* base_finalize */ | |
| 148 NULL, | |
| 149 /*(GClassInitFunc)gnt_ws_class_init,*/ | |
| 150 NULL, | |
| 151 NULL, /* class_data */ | |
| 152 sizeof(GntWS), | |
| 153 0, /* n_preallocs */ | |
| 154 gnt_ws_init, /* instance_init */ | |
| 155 NULL /* value_table */ | |
| 156 }; | |
| 157 | |
| 158 type = g_type_register_static(GNT_TYPE_BINDABLE, | |
| 159 "GntWS", | |
| 160 &info, 0); | |
| 161 } | |
| 162 | |
| 163 return type; | |
| 164 } | |
| 165 | |
|
18075
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
166 GntWS *gnt_ws_new(const char *name) |
|
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
167 { |
|
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
168 GntWS *ws = GNT_WS(g_object_new(GNT_TYPE_WS, NULL)); |
|
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
169 ws->name = g_strdup(name ? name : "(noname)"); |
|
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
170 return ws; |
|
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
171 } |
|
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
172 |
|
17702
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
173 const char * gnt_ws_get_name(GntWS *ws) |
|
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
174 { |
|
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
175 return ws->name; |
|
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
176 } |
|
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
177 |
