Mercurial > pidgin
annotate finch/libgnt/gntws.c @ 32751:6b80dbe29e0c
I'm really going to try to release Tuesday night. I'm going to try to
confirm that we still build on windows... but if anyone else wants to
test it, that would be good, too
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 12 Mar 2012 08:56:12 +0000 |
parents | 1a349e6a27da |
children |
rev | line source |
---|---|
28605
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
1 /* |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
3 * |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
6 * source distribution. |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
7 * |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
11 * (at your option) any later version. |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
12 * |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
16 * GNU General Public License for more details. |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
17 * |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
21 */ |
1a349e6a27da
Add missing copyright headers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28604
diff
changeset
|
22 |
17699 | 23 #include <gmodule.h> |
24 | |
28604
a18f421696dc
Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22763
diff
changeset
|
25 #include "gntinternal.h" |
17699 | 26 #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
|
27 #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
|
28 #include "gntwindow.h" |
17699 | 29 #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
|
30 #include "gntws.h" |
17699 | 31 |
32 static void | |
33 widget_hide(gpointer data, gpointer nodes) | |
34 { | |
35 GntWidget *widget = GNT_WIDGET(data); | |
36 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
|
37 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
|
38 gnt_window_workspace_hiding(GNT_WINDOW(widget)); |
22763
bec28e60aff6
Fix a possible crash when creating a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
39 if (node) |
bec28e60aff6
Fix a possible crash when creating a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
40 hide_panel(node->panel); |
17699 | 41 } |
42 | |
43 static void | |
44 widget_show(gpointer data, gpointer nodes) | |
45 { | |
46 GntNode *node = g_hash_table_lookup(nodes, data); | |
47 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(data), GNT_WIDGET_INVISIBLE); | |
48 if (node) { | |
49 show_panel(node->panel); | |
50 gnt_wm_copy_win(GNT_WIDGET(data), node); | |
51 } | |
52 } | |
53 | |
54 void | |
55 gnt_ws_draw_taskbar(GntWS *ws, gboolean reposition) | |
56 { | |
57 static WINDOW *taskbar = NULL; | |
58 GList *iter; | |
59 int n, width = 0; | |
60 int i; | |
61 | |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18416
diff
changeset
|
62 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
|
63 return; |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18416
diff
changeset
|
64 |
17699 | 65 if (taskbar == NULL) { |
66 taskbar = newwin(1, getmaxx(stdscr), getmaxy(stdscr) - 1, 0); | |
67 } else if (reposition) { | |
68 int Y_MAX = getmaxy(stdscr) - 1; | |
69 mvwin(taskbar, Y_MAX, 0); | |
70 } | |
71 | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18421
diff
changeset
|
72 wbkgdset(taskbar, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); |
17699 | 73 werase(taskbar); |
74 | |
75 n = g_list_length(ws->list); | |
76 if (n) | |
77 width = getmaxx(stdscr) / n; | |
78 | |
79 for (i = 0, iter = ws->list; iter; iter = iter->next, i++) { | |
80 GntWidget *w = iter->data; | |
81 int color; | |
82 const char *title; | |
83 | |
84 if (w == ws->ordered->data) { | |
85 /* This is the current window in focus */ | |
86 color = GNT_COLOR_TITLE; | |
87 } else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) { | |
88 /* This is a window with the URGENT hint set */ | |
89 color = GNT_COLOR_URGENT; | |
90 } else { | |
91 color = GNT_COLOR_NORMAL; | |
92 } | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18421
diff
changeset
|
93 wbkgdset(taskbar, '\0' | gnt_color_pair(color)); |
17699 | 94 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
|
95 mvwhline(taskbar, 0, width * i, ' ' | gnt_color_pair(color), width); |
17699 | 96 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
|
97 mvwhline(taskbar, 0, width * i, ' ' | gnt_color_pair(color), getmaxx(stdscr) - width * i); |
17699 | 98 title = GNT_BOX(w)->title; |
28604
a18f421696dc
Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22763
diff
changeset
|
99 mvwprintw(taskbar, 0, width * i, "%s", title ? C_(title) : "<gnt>"); |
17699 | 100 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
|
101 mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | gnt_color_pair(GNT_COLOR_NORMAL)); |
17699 | 102 } |
103 wrefresh(taskbar); | |
104 } | |
105 | |
106 static void | |
107 gnt_ws_init(GTypeInstance *instance, gpointer class) | |
108 { | |
109 GntWS *ws = GNT_WS(instance); | |
110 ws->list = NULL; | |
111 ws->ordered = NULL; | |
112 ws->name = NULL; | |
113 } | |
114 | |
115 void gnt_ws_add_widget(GntWS *ws, GntWidget* wid) | |
116 { | |
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
|
117 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
|
118 oldfocus = ws->ordered ? ws->ordered->data : NULL; |
17699 | 119 ws->list = g_list_append(ws->list, wid); |
120 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
|
121 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
|
122 gnt_widget_set_focus(oldfocus, FALSE); |
17699 | 123 } |
124 | |
125 void gnt_ws_remove_widget(GntWS *ws, GntWidget* wid) | |
126 { | |
127 ws->list = g_list_remove(ws->list, wid); | |
128 ws->ordered = g_list_remove(ws->ordered, wid); | |
129 } | |
130 | |
131 void | |
132 gnt_ws_set_name(GntWS *ws, const gchar *name) | |
133 { | |
134 g_free(ws->name); | |
135 ws->name = g_strdup(name); | |
136 } | |
137 | |
138 void | |
139 gnt_ws_hide(GntWS *ws, GHashTable *nodes) | |
140 { | |
141 g_list_foreach(ws->ordered, widget_hide, nodes); | |
142 } | |
143 | |
18416
93c5c785a811
Fix some focus issues.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
144 void gnt_ws_widget_hide(GntWidget *widget, GHashTable *nodes) |
93c5c785a811
Fix some focus issues.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
145 { |
17699 | 146 widget_hide(widget, nodes); |
147 } | |
148 | |
18416
93c5c785a811
Fix some focus issues.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
149 void gnt_ws_widget_show(GntWidget *widget, GHashTable *nodes) |
93c5c785a811
Fix some focus issues.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18223
diff
changeset
|
150 { |
17699 | 151 widget_show(widget, nodes); |
152 } | |
153 | |
154 void | |
155 gnt_ws_show(GntWS *ws, GHashTable *nodes) | |
156 { | |
157 GList *l; | |
158 for (l = g_list_last(ws->ordered); l; l = g_list_previous(l)) | |
159 widget_show(l->data, nodes); | |
160 } | |
161 | |
162 GType | |
163 gnt_ws_get_gtype(void) | |
164 { | |
165 static GType type = 0; | |
166 | |
167 if(type == 0) { | |
168 static const GTypeInfo info = { | |
169 sizeof(GntWSClass), | |
170 NULL, /* base_init */ | |
171 NULL, /* base_finalize */ | |
172 NULL, | |
173 /*(GClassInitFunc)gnt_ws_class_init,*/ | |
174 NULL, | |
175 NULL, /* class_data */ | |
176 sizeof(GntWS), | |
177 0, /* n_preallocs */ | |
178 gnt_ws_init, /* instance_init */ | |
179 NULL /* value_table */ | |
180 }; | |
181 | |
182 type = g_type_register_static(GNT_TYPE_BINDABLE, | |
183 "GntWS", | |
184 &info, 0); | |
185 } | |
186 | |
187 return type; | |
188 } | |
189 | |
18075
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
190 GntWS *gnt_ws_new(const char *name) |
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
191 { |
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
192 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
|
193 ws->name = g_strdup(name ? name : "(noname)"); |
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
194 return ws; |
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
195 } |
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
196 |
17702
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
197 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
|
198 { |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
199 return ws->name; |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
200 } |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
201 |