Wed, 07 May 2014 11:07:45 +0200
Merge release-2.x.y
|
28938
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
1 | /* |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
2 | * GNT - The GLib Ncurses Toolkit |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
3 | * |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
4 | * GNT is the legal property of its developers, whose names are too numerous |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
6 | * source distribution. |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
7 | * |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
8 | * This library is free software; you can redistribute it and/or modify |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
9 | * it under the terms of the GNU General Public License as published by |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
10 | * the Free Software Foundation; either version 2 of the License, or |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
11 | * (at your option) any later version. |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
12 | * |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
13 | * This program is distributed in the hope that it will be useful, |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
16 | * GNU General Public License for more details. |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
17 | * |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
19 | * along with this program; if not, write to the Free Software |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
21 | */ |
|
44d8d49a9293
Add missing copyright headers.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
28937
diff
changeset
|
22 | |
| 16520 | 23 | #include <gmodule.h> |
| 24 | ||
|
28937
5f87e66597d9
Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22907
diff
changeset
|
25 | #include "gntinternal.h" |
| 16520 | 26 | #include "gntbox.h" |
|
16779
006f50afb7a6
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
16523
diff
changeset
|
27 | #include "gntwidget.h" |
|
006f50afb7a6
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
16523
diff
changeset
|
28 | #include "gntwindow.h" |
| 16520 | 29 | #include "gntwm.h" |
|
16779
006f50afb7a6
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
16523
diff
changeset
|
30 | #include "gntws.h" |
| 16520 | 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); | |
|
16779
006f50afb7a6
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
16523
diff
changeset
|
37 | if (GNT_IS_WINDOW(widget)) |
|
006f50afb7a6
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
16523
diff
changeset
|
38 | gnt_window_workspace_hiding(GNT_WINDOW(widget)); |
|
22907
8186478f9ec3
Fix a possible crash when creating a new workspace.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21240
diff
changeset
|
39 | if (node) |
|
8186478f9ec3
Fix a possible crash when creating a new workspace.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21240
diff
changeset
|
40 | hide_panel(node->panel); |
| 16520 | 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 | ||
|
18599
7e31405a2cbb
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18567
diff
changeset
|
62 | if (gnt_is_refugee()) |
|
7e31405a2cbb
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18567
diff
changeset
|
63 | return; |
|
7e31405a2cbb
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18567
diff
changeset
|
64 | |
|
35992
34a67264df99
Fix some CWE-476 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
28938
diff
changeset
|
65 | g_return_if_fail(ws != NULL); |
|
34a67264df99
Fix some CWE-476 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
28938
diff
changeset
|
66 | |
| 16520 | 67 | if (taskbar == NULL) { |
| 68 | taskbar = newwin(1, getmaxx(stdscr), getmaxy(stdscr) - 1, 0); | |
| 69 | } else if (reposition) { | |
| 70 | int Y_MAX = getmaxy(stdscr) - 1; | |
| 71 | mvwin(taskbar, Y_MAX, 0); | |
| 72 | } | |
| 73 | ||
|
21240
b78eaddaae02
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18599
diff
changeset
|
74 | wbkgdset(taskbar, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); |
| 16520 | 75 | werase(taskbar); |
| 76 | ||
| 77 | n = g_list_length(ws->list); | |
| 78 | if (n) | |
| 79 | width = getmaxx(stdscr) / n; | |
| 80 | ||
| 81 | for (i = 0, iter = ws->list; iter; iter = iter->next, i++) { | |
| 82 | GntWidget *w = iter->data; | |
| 83 | int color; | |
| 84 | const char *title; | |
| 85 | ||
| 86 | if (w == ws->ordered->data) { | |
| 87 | /* This is the current window in focus */ | |
| 88 | color = GNT_COLOR_TITLE; | |
| 89 | } else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) { | |
| 90 | /* This is a window with the URGENT hint set */ | |
| 91 | color = GNT_COLOR_URGENT; | |
| 92 | } else { | |
| 93 | color = GNT_COLOR_NORMAL; | |
| 94 | } | |
|
21240
b78eaddaae02
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18599
diff
changeset
|
95 | wbkgdset(taskbar, '\0' | gnt_color_pair(color)); |
| 16520 | 96 | if (iter->next) |
|
21240
b78eaddaae02
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18599
diff
changeset
|
97 | mvwhline(taskbar, 0, width * i, ' ' | gnt_color_pair(color), width); |
| 16520 | 98 | else |
|
21240
b78eaddaae02
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18599
diff
changeset
|
99 | mvwhline(taskbar, 0, width * i, ' ' | gnt_color_pair(color), getmaxx(stdscr) - width * i); |
| 16520 | 100 | title = GNT_BOX(w)->title; |
|
28937
5f87e66597d9
Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22907
diff
changeset
|
101 | mvwprintw(taskbar, 0, width * i, "%s", title ? C_(title) : "<gnt>"); |
| 16520 | 102 | if (i) |
|
21240
b78eaddaae02
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18599
diff
changeset
|
103 | mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | gnt_color_pair(GNT_COLOR_NORMAL)); |
| 16520 | 104 | } |
| 105 | wrefresh(taskbar); | |
| 106 | } | |
| 107 | ||
| 108 | static void | |
| 109 | gnt_ws_init(GTypeInstance *instance, gpointer class) | |
| 110 | { | |
| 111 | GntWS *ws = GNT_WS(instance); | |
| 112 | ws->list = NULL; | |
| 113 | ws->ordered = NULL; | |
| 114 | ws->name = NULL; | |
| 115 | } | |
| 116 | ||
| 117 | void gnt_ws_add_widget(GntWS *ws, GntWidget* wid) | |
| 118 | { | |
|
18302
44267a021f2d
Notify a window when it loses focus because another window was moved to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18137
diff
changeset
|
119 | GntWidget *oldfocus; |
|
44267a021f2d
Notify a window when it loses focus because another window was moved to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18137
diff
changeset
|
120 | oldfocus = ws->ordered ? ws->ordered->data : NULL; |
| 16520 | 121 | ws->list = g_list_append(ws->list, wid); |
| 122 | ws->ordered = g_list_prepend(ws->ordered, wid); | |
|
18302
44267a021f2d
Notify a window when it loses focus because another window was moved to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18137
diff
changeset
|
123 | if (oldfocus) |
|
44267a021f2d
Notify a window when it loses focus because another window was moved to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18137
diff
changeset
|
124 | gnt_widget_set_focus(oldfocus, FALSE); |
| 16520 | 125 | } |
| 126 | ||
| 127 | void gnt_ws_remove_widget(GntWS *ws, GntWidget* wid) | |
| 128 | { | |
| 129 | ws->list = g_list_remove(ws->list, wid); | |
| 130 | ws->ordered = g_list_remove(ws->ordered, wid); | |
| 131 | } | |
| 132 | ||
| 133 | void | |
| 134 | gnt_ws_set_name(GntWS *ws, const gchar *name) | |
| 135 | { | |
| 136 | g_free(ws->name); | |
| 137 | ws->name = g_strdup(name); | |
| 138 | } | |
| 139 | ||
| 140 | void | |
| 141 | gnt_ws_hide(GntWS *ws, GHashTable *nodes) | |
| 142 | { | |
| 143 | g_list_foreach(ws->ordered, widget_hide, nodes); | |
| 144 | } | |
| 145 | ||
|
18567
8dd8eae7a1aa
Fix some focus issues.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18302
diff
changeset
|
146 | void gnt_ws_widget_hide(GntWidget *widget, GHashTable *nodes) |
|
8dd8eae7a1aa
Fix some focus issues.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18302
diff
changeset
|
147 | { |
| 16520 | 148 | widget_hide(widget, nodes); |
| 149 | } | |
| 150 | ||
|
18567
8dd8eae7a1aa
Fix some focus issues.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18302
diff
changeset
|
151 | void gnt_ws_widget_show(GntWidget *widget, GHashTable *nodes) |
|
8dd8eae7a1aa
Fix some focus issues.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18302
diff
changeset
|
152 | { |
| 16520 | 153 | widget_show(widget, nodes); |
| 154 | } | |
| 155 | ||
| 156 | void | |
| 157 | gnt_ws_show(GntWS *ws, GHashTable *nodes) | |
| 158 | { | |
| 159 | GList *l; | |
| 160 | for (l = g_list_last(ws->ordered); l; l = g_list_previous(l)) | |
| 161 | widget_show(l->data, nodes); | |
| 162 | } | |
| 163 | ||
| 164 | GType | |
|
35379
ea1a0327001e
Rename _get_gtype() functions in libgnt to _get_type()
Ankit Vani <a@nevitus.org>
parents:
28938
diff
changeset
|
165 | gnt_ws_get_type(void) |
| 16520 | 166 | { |
| 167 | static GType type = 0; | |
| 168 | ||
| 169 | if(type == 0) { | |
| 170 | static const GTypeInfo info = { | |
| 171 | sizeof(GntWSClass), | |
| 172 | NULL, /* base_init */ | |
| 173 | NULL, /* base_finalize */ | |
| 174 | NULL, | |
| 175 | /*(GClassInitFunc)gnt_ws_class_init,*/ | |
| 176 | NULL, | |
| 177 | NULL, /* class_data */ | |
| 178 | sizeof(GntWS), | |
| 179 | 0, /* n_preallocs */ | |
| 180 | gnt_ws_init, /* instance_init */ | |
| 181 | NULL /* value_table */ | |
| 182 | }; | |
| 183 | ||
| 184 | type = g_type_register_static(GNT_TYPE_BINDABLE, | |
| 185 | "GntWS", | |
| 186 | &info, 0); | |
| 187 | } | |
| 188 | ||
| 189 | return type; | |
| 190 | } | |
| 191 | ||
|
18137
a8c54ed05eee
F9 to create a new workspace.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16779
diff
changeset
|
192 | GntWS *gnt_ws_new(const char *name) |
|
a8c54ed05eee
F9 to create a new workspace.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16779
diff
changeset
|
193 | { |
|
a8c54ed05eee
F9 to create a new workspace.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16779
diff
changeset
|
194 | GntWS *ws = GNT_WS(g_object_new(GNT_TYPE_WS, NULL)); |
|
a8c54ed05eee
F9 to create a new workspace.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16779
diff
changeset
|
195 | ws->name = g_strdup(name ? name : "(noname)"); |
|
a8c54ed05eee
F9 to create a new workspace.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16779
diff
changeset
|
196 | return ws; |
|
a8c54ed05eee
F9 to create a new workspace.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16779
diff
changeset
|
197 | } |
|
a8c54ed05eee
F9 to create a new workspace.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16779
diff
changeset
|
198 | |
|
16523
d774ca89d340
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16520
diff
changeset
|
199 | const char * gnt_ws_get_name(GntWS *ws) |
|
d774ca89d340
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16520
diff
changeset
|
200 | { |
|
d774ca89d340
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16520
diff
changeset
|
201 | return ws->name; |
|
d774ca89d340
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16520
diff
changeset
|
202 | } |
|
d774ca89d340
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16520
diff
changeset
|
203 |