Mercurial > pidgin.yaz
annotate finch/libgnt/gntwm.c @ 17075:4d4a396a478c
propagate from branch 'im.pidgin.pidgin' (head 6f6e8345100a2f026e20c28fa52592fadd9c8193)
to branch 'im.pidgin.finch.workspaces' (head a54e86b400cf8e4b692ae83a4e4976843855b1f6)
author | Richard Nelson <wabz@pidgin.im> |
---|---|
date | Sun, 13 May 2007 00:21:15 +0000 |
parents | f1abdde52538 3af867ef5a15 |
children | 08776fc5c06f |
rev | line source |
---|---|
15818 | 1 #define _GNU_SOURCE |
2 #if defined(__APPLE__) | |
3 #define _XOPEN_SOURCE_EXTENDED | |
4 #endif | |
5 | |
6 #include "config.h" | |
7 | |
8 #include <ctype.h> | |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
9 #include <glib/gprintf.h> |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
10 #include <gmodule.h> |
15818 | 11 #include <stdlib.h> |
12 #include <string.h> | |
13 #include <time.h> | |
14 | |
15 #include "gntwm.h" | |
16 #include "gntstyle.h" | |
17 #include "gntmarshal.h" | |
18 #include "gnt.h" | |
19 #include "gntbox.h" | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
20 #include "gntlabel.h" |
15818 | 21 #include "gntmenu.h" |
22 #include "gnttextview.h" | |
23 #include "gnttree.h" | |
24 #include "gntutils.h" | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
25 #include "gntwindow.h" |
15818 | 26 |
27 #define IDLE_CHECK_INTERVAL 5 /* 5 seconds */ | |
28 | |
29 enum | |
30 { | |
31 SIG_NEW_WIN, | |
32 SIG_DECORATE_WIN, | |
33 SIG_CLOSE_WIN, | |
34 SIG_CONFIRM_RESIZE, | |
35 SIG_RESIZED, | |
36 SIG_CONFIRM_MOVE, | |
37 SIG_MOVED, | |
38 SIG_UPDATE_WIN, | |
39 SIG_GIVE_FOCUS, | |
40 SIG_KEY_PRESS, | |
41 SIG_MOUSE_CLICK, | |
42 SIGS | |
43 }; | |
44 | |
45 static guint signals[SIGS] = { 0 }; | |
46 static void gnt_wm_new_window_real(GntWM *wm, GntWidget *widget); | |
47 static void gnt_wm_win_resized(GntWM *wm, GntNode *node); | |
48 static void gnt_wm_win_moved(GntWM *wm, GntNode *node); | |
49 static void gnt_wm_give_focus(GntWM *wm, GntWidget *widget); | |
50 static void update_window_in_list(GntWM *wm, GntWidget *wid); | |
51 static void shift_window(GntWM *wm, GntWidget *widget, int dir); | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
52 static gboolean workspace_next(GntBindable *wm, GList *n); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
53 static gboolean workspace_prev(GntBindable *wm, GList *n); |
15818 | 54 |
17059
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
55 #ifndef NO_WIDECHAR |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
56 static int widestringwidth(wchar_t *wide); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
57 #endif |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
58 |
15818 | 59 static gboolean write_already(gpointer data); |
60 static int write_timeout; | |
61 static time_t last_active_time; | |
62 static gboolean idle_update; | |
16472
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
63 static GList *act = NULL; /* list of WS with unseen activitiy */ |
15818 | 64 |
65 static GList * | |
66 g_list_bring_to_front(GList *list, gpointer data) | |
67 { | |
68 list = g_list_remove(list, data); | |
69 list = g_list_prepend(list, data); | |
70 return list; | |
71 } | |
72 | |
73 static void | |
74 free_node(gpointer data) | |
75 { | |
76 GntNode *node = data; | |
77 hide_panel(node->panel); | |
78 del_panel(node->panel); | |
79 g_free(node); | |
80 } | |
81 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
82 void |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
83 gnt_wm_copy_win(GntWidget *widget, GntNode *node) |
15818 | 84 { |
85 WINDOW *src, *dst; | |
86 int shadow; | |
87 if (!node) | |
88 return; | |
89 src = widget->window; | |
90 dst = node->window; | |
91 shadow = gnt_widget_has_shadow(widget) ? 1 : 0; | |
92 copywin(src, dst, node->scroll, 0, 0, 0, getmaxy(dst) - 1, getmaxx(dst) - 1, 0); | |
93 } | |
94 | |
17059
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
95 /** |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
96 * The following is a workaround for a bug in most versions of ncursesw. |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
97 * Read about it in: http://article.gmane.org/gmane.comp.lib.ncurses.bugs/2751 |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
98 * |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
99 * In short, if a panel hides one cell of a multi-cell character, then the rest |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
100 * of the characters in that line get screwed. The workaround here is to erase |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
101 * any such character preemptively. |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
102 * |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
103 * Caveat: If a wide character is erased, and the panel above it is moved enough |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
104 * to expose the entire character, it is not always redrawn. |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
105 */ |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
106 static void |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
107 work_around_for_ncurses_bug() |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
108 { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
109 #ifndef NO_WIDECHAR |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
110 PANEL *panel = NULL; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
111 while ((panel = panel_below(panel)) != NULL) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
112 int sx, ex, sy, ey, w, y; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
113 cchar_t ch; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
114 PANEL *below = panel; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
115 |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
116 sx = panel->win->_begx; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
117 ex = panel->win->_maxx + sx; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
118 sy = panel->win->_begy; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
119 ey = panel->win->_maxy + sy; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
120 |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
121 while ((below = panel_below(below)) != NULL) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
122 if (sy > below->win->_begy + below->win->_maxy || |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
123 ey < below->win->_begy) |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
124 continue; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
125 if (sx > below->win->_begx + below->win->_maxx || |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
126 ex < below->win->_begx) |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
127 continue; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
128 for (y = MAX(sy, below->win->_begy); y <= MIN(ey, below->win->_begy + below->win->_maxy); y++) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
129 if (mvwin_wch(below->win, y - below->win->_begy, sx - 1 - below->win->_begx, &ch) != OK) |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
130 goto right; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
131 w = widestringwidth(ch.chars); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
132 if (w > 1 && (ch.attr & 1)) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
133 ch.chars[0] = ' '; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
134 ch.attr &= ~ A_CHARTEXT; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
135 mvwadd_wch(below->win, y - below->win->_begy, sx - 1 - below->win->_begx, &ch); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
136 touchline(below->win, y - below->win->_begy, 1); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
137 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
138 right: |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
139 if (mvwin_wch(below->win, y - below->win->_begy, ex + 1 - below->win->_begx, &ch) != OK) |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
140 continue; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
141 w = widestringwidth(ch.chars); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
142 if (w > 1 && !(ch.attr & 1)) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
143 ch.chars[0] = ' '; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
144 ch.attr &= ~ A_CHARTEXT; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
145 mvwadd_wch(below->win, y - below->win->_begy, ex + 1 - below->win->_begx, &ch); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
146 touchline(below->win, y - below->win->_begy, 1); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
147 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
148 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
149 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
150 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
151 #endif |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
152 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
153 |
16472
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
154 static void |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
155 update_act_msg() |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
156 { |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
157 GntWidget *label; |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
158 GList *iter; |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
159 static GntWidget *message = NULL; |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
160 GString *text = g_string_new("act: "); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
161 if (message) |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
162 gnt_widget_destroy(message); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
163 if (g_list_length(act) == 0) |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
164 return; |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
165 for (iter = act; iter; iter = iter->next) { |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
166 GntWS *ws = iter->data; |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
167 g_string_sprintfa(text, "%s, ", gnt_ws_get_name(ws)); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
168 } |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
169 g_string_erase(text, text->len - 2, 2); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
170 message = gnt_vbox_new(FALSE); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
171 label = gnt_label_new_with_format(text->str, GNT_TEXT_FLAG_BOLD | GNT_TEXT_FLAG_HIGHLIGHT); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
172 GNT_WIDGET_UNSET_FLAGS(GNT_BOX(message), GNT_WIDGET_CAN_TAKE_FOCUS); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
173 GNT_WIDGET_SET_FLAGS(GNT_BOX(message), GNT_WIDGET_TRANSIENT); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
174 gnt_box_add_widget(GNT_BOX(message), label); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
175 gnt_widget_set_name(message, "wm-message"); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
176 gnt_widget_set_position(message, 0, 0); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
177 gnt_widget_draw(message); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
178 g_string_free(text, TRUE); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
179 } |
17075
4d4a396a478c
propagate from branch 'im.pidgin.pidgin' (head 6f6e8345100a2f026e20c28fa52592fadd9c8193)
Richard Nelson <wabz@pidgin.im>
diff
changeset
|
180 |
15818 | 181 static gboolean |
182 update_screen(GntWM *wm) | |
183 { | |
184 if (wm->menu) { | |
185 GntMenu *top = wm->menu; | |
186 while (top) { | |
187 GntNode *node = g_hash_table_lookup(wm->nodes, top); | |
188 if (node) | |
189 top_panel(node->panel); | |
190 top = top->submenu; | |
191 } | |
192 } | |
17059
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
193 work_around_for_ncurses_bug(); |
15818 | 194 update_panels(); |
195 doupdate(); | |
196 return TRUE; | |
197 } | |
198 | |
199 static gboolean | |
200 sanitize_position(GntWidget *widget, int *x, int *y) | |
201 { | |
202 int X_MAX = getmaxx(stdscr); | |
203 int Y_MAX = getmaxy(stdscr) - 1; | |
204 int w, h; | |
205 int nx, ny; | |
206 gboolean changed = FALSE; | |
207 | |
208 gnt_widget_get_size(widget, &w, &h); | |
209 if (x) { | |
210 if (*x + w > X_MAX) { | |
211 nx = MAX(0, X_MAX - w); | |
212 if (nx != *x) { | |
213 *x = nx; | |
214 changed = TRUE; | |
215 } | |
216 } | |
217 } | |
218 if (y) { | |
219 if (*y + h > Y_MAX) { | |
220 ny = MAX(0, Y_MAX - h); | |
221 if (ny != *y) { | |
222 *y = ny; | |
223 changed = TRUE; | |
224 } | |
225 } | |
226 } | |
227 return changed; | |
228 } | |
229 | |
230 static void | |
231 refresh_node(GntWidget *widget, GntNode *node, gpointer null) | |
232 { | |
233 int x, y, w, h; | |
234 int nw, nh; | |
235 | |
236 int X_MAX = getmaxx(stdscr); | |
237 int Y_MAX = getmaxy(stdscr) - 1; | |
238 | |
239 gnt_widget_get_position(widget, &x, &y); | |
240 gnt_widget_get_size(widget, &w, &h); | |
241 | |
242 if (sanitize_position(widget, &x, &y)) | |
243 gnt_screen_move_widget(widget, x, y); | |
244 | |
245 nw = MIN(w, X_MAX); | |
246 nh = MIN(h, Y_MAX); | |
247 if (nw != w || nh != h) | |
248 gnt_screen_resize_widget(widget, nw, nh); | |
249 } | |
250 | |
251 static void | |
252 read_window_positions(GntWM *wm) | |
253 { | |
254 #if GLIB_CHECK_VERSION(2,6,0) | |
255 GKeyFile *gfile = g_key_file_new(); | |
256 char *filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL); | |
257 GError *error = NULL; | |
258 char **keys; | |
259 gsize nk; | |
260 | |
261 if (!g_key_file_load_from_file(gfile, filename, G_KEY_FILE_NONE, &error)) { | |
262 g_printerr("GntWM: %s\n", error->message); | |
263 g_error_free(error); | |
264 g_free(filename); | |
265 return; | |
266 } | |
267 | |
268 keys = g_key_file_get_keys(gfile, "positions", &nk, &error); | |
269 if (error) { | |
270 g_printerr("GntWM: %s\n", error->message); | |
271 g_error_free(error); | |
272 error = NULL; | |
273 } else { | |
274 while (nk--) { | |
275 char *title = keys[nk]; | |
276 gsize l; | |
277 char **coords = g_key_file_get_string_list(gfile, "positions", title, &l, NULL); | |
278 if (l == 2) { | |
279 int x = atoi(coords[0]); | |
280 int y = atoi(coords[1]); | |
281 GntPosition *p = g_new0(GntPosition, 1); | |
282 p->x = x; | |
283 p->y = y; | |
284 g_hash_table_replace(wm->positions, g_strdup(title + 1), p); | |
285 } else { | |
286 g_printerr("GntWM: Invalid number of arguments for positioing a window.\n"); | |
287 } | |
288 g_strfreev(coords); | |
289 } | |
290 g_strfreev(keys); | |
291 } | |
292 | |
293 g_free(filename); | |
15964 | 294 g_key_file_free(gfile); |
15818 | 295 #endif |
296 } | |
297 | |
298 static gboolean check_idle(gpointer n) | |
299 { | |
300 if (idle_update) { | |
301 time(&last_active_time); | |
302 idle_update = FALSE; | |
303 } | |
304 return TRUE; | |
305 } | |
306 | |
307 static void | |
308 gnt_wm_init(GTypeInstance *instance, gpointer class) | |
309 { | |
310 GntWM *wm = GNT_WM(instance); | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
311 wm->workspaces = NULL; |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
312 wm->name_places = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
313 wm->title_places = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
314 gnt_style_read_workspaces(wm); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
315 if (wm->workspaces == NULL) { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
316 wm->cws = g_object_new(GNT_TYPE_WS, NULL); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
317 gnt_ws_set_name(wm->cws, "default"); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
318 gnt_wm_add_workspace(wm, wm->cws); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
319 } else { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
320 wm->cws = wm->workspaces->data; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
321 } |
15818 | 322 wm->event_stack = FALSE; |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
323 wm->tagged = NULL; |
15818 | 324 wm->windows = NULL; |
325 wm->actions = NULL; | |
326 wm->nodes = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_node); | |
327 wm->positions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
328 if (gnt_style_get_bool(GNT_STYLE_REMPOS, TRUE)) | |
329 read_window_positions(wm); | |
330 g_timeout_add(IDLE_CHECK_INTERVAL * 1000, check_idle, NULL); | |
331 time(&last_active_time); | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
332 gnt_wm_switch_workspace(wm, 0); |
15818 | 333 } |
334 | |
335 static void | |
336 switch_window(GntWM *wm, int direction) | |
337 { | |
338 GntWidget *w = NULL, *wid = NULL; | |
339 int pos; | |
340 | |
341 if (wm->_list.window || wm->menu) | |
342 return; | |
343 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
344 if (!wm->cws->ordered || !wm->cws->ordered->next) |
15818 | 345 return; |
346 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
347 w = wm->cws->ordered->data; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
348 pos = g_list_index(wm->cws->list, w); |
15818 | 349 pos += direction; |
350 | |
351 if (pos < 0) | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
352 wid = g_list_last(wm->cws->list)->data; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
353 else if (pos >= g_list_length(wm->cws->list)) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
354 wid = wm->cws->list->data; |
15818 | 355 else if (pos >= 0) |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
356 wid = g_list_nth_data(wm->cws->list, pos); |
15818 | 357 |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
358 wm->cws->ordered = g_list_bring_to_front(wm->cws->ordered, wid); |
15818 | 359 |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
360 gnt_wm_raise_window(wm, wm->cws->ordered->data); |
15818 | 361 |
362 if (w != wid) { | |
363 gnt_widget_set_focus(w, FALSE); | |
364 } | |
365 } | |
366 | |
367 static gboolean | |
368 window_next(GntBindable *bindable, GList *null) | |
369 { | |
370 GntWM *wm = GNT_WM(bindable); | |
371 switch_window(wm, 1); | |
372 return TRUE; | |
373 } | |
374 | |
375 static gboolean | |
376 window_prev(GntBindable *bindable, GList *null) | |
377 { | |
378 GntWM *wm = GNT_WM(bindable); | |
379 switch_window(wm, -1); | |
380 return TRUE; | |
381 } | |
382 | |
383 static gboolean | |
384 switch_window_n(GntBindable *bind, GList *list) | |
385 { | |
386 GntWM *wm = GNT_WM(bind); | |
387 GntWidget *w = NULL; | |
388 GList *l; | |
389 int n; | |
390 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
391 if (!wm->cws->ordered) |
15818 | 392 return TRUE; |
393 | |
394 if (list) | |
395 n = GPOINTER_TO_INT(list->data); | |
396 else | |
397 n = 0; | |
398 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
399 w = wm->cws->ordered->data; |
15818 | 400 |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
401 if ((l = g_list_nth(wm->cws->list, n)) != NULL) |
15818 | 402 { |
403 gnt_wm_raise_window(wm, l->data); | |
404 } | |
405 | |
406 if (l && w != l->data) | |
407 { | |
408 gnt_widget_set_focus(w, FALSE); | |
409 } | |
410 return TRUE; | |
411 } | |
412 | |
413 static gboolean | |
414 window_scroll_up(GntBindable *bindable, GList *null) | |
415 { | |
416 GntWM *wm = GNT_WM(bindable); | |
417 GntWidget *window; | |
418 GntNode *node; | |
419 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
420 if (!wm->cws->ordered) |
15818 | 421 return TRUE; |
422 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
423 window = wm->cws->ordered->data; |
15818 | 424 node = g_hash_table_lookup(wm->nodes, window); |
425 if (!node) | |
426 return TRUE; | |
427 | |
428 if (node->scroll) { | |
429 node->scroll--; | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
430 gnt_wm_copy_win(window, node); |
15818 | 431 update_screen(wm); |
432 } | |
433 return TRUE; | |
434 } | |
435 | |
436 static gboolean | |
437 window_scroll_down(GntBindable *bindable, GList *null) | |
438 { | |
439 GntWM *wm = GNT_WM(bindable); | |
440 GntWidget *window; | |
441 GntNode *node; | |
442 int w, h; | |
443 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
444 if (!wm->cws->ordered) |
15818 | 445 return TRUE; |
446 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
447 window = wm->cws->ordered->data; |
15818 | 448 node = g_hash_table_lookup(wm->nodes, window); |
449 if (!node) | |
450 return TRUE; | |
451 | |
452 gnt_widget_get_size(window, &w, &h); | |
453 if (h - node->scroll > getmaxy(node->window)) { | |
454 node->scroll++; | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
455 gnt_wm_copy_win(window, node); |
15818 | 456 update_screen(wm); |
457 } | |
458 return TRUE; | |
459 } | |
460 | |
461 static gboolean | |
462 window_close(GntBindable *bindable, GList *null) | |
463 { | |
464 GntWM *wm = GNT_WM(bindable); | |
465 | |
466 if (wm->_list.window) | |
467 return TRUE; | |
468 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
469 if (wm->cws->ordered) { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
470 gnt_widget_destroy(wm->cws->ordered->data); |
15818 | 471 } |
472 | |
473 return TRUE; | |
474 } | |
475 | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
476 static gboolean |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
477 help_for_widget(GntBindable *bindable, GList *null) |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
478 { |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
479 GntWM *wm = GNT_WM(bindable); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
480 GntWidget *widget, *tree, *win, *active; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
481 char *title; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
482 |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
483 if (!wm->cws->ordered) |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
484 return TRUE; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
485 |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
486 widget = wm->cws->ordered->data; |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
487 if (!GNT_IS_BOX(widget)) |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
488 return TRUE; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
489 active = GNT_BOX(widget)->active; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
490 |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
491 tree = gnt_widget_bindings_view(active); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
492 win = gnt_window_new(); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
493 title = g_strdup_printf("Bindings for %s", g_type_name(G_OBJECT_TYPE(active))); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
494 gnt_box_set_title(GNT_BOX(win), title); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
495 if (tree) |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
496 gnt_box_add_widget(GNT_BOX(win), tree); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
497 else |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
498 gnt_box_add_widget(GNT_BOX(win), gnt_label_new("This widget has no customizable bindings.")); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
499 |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
500 gnt_widget_show(win); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
501 |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
502 return TRUE; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
503 } |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
504 |
15818 | 505 static void |
506 destroy__list(GntWidget *widget, GntWM *wm) | |
507 { | |
508 wm->_list.window = NULL; | |
509 wm->_list.tree = NULL; | |
510 wm->windows = NULL; | |
511 wm->actions = NULL; | |
512 update_screen(wm); | |
513 } | |
514 | |
515 static void | |
516 setup__list(GntWM *wm) | |
517 { | |
518 GntWidget *tree, *win; | |
519 win = wm->_list.window = gnt_box_new(FALSE, FALSE); | |
520 gnt_box_set_toplevel(GNT_BOX(win), TRUE); | |
521 gnt_box_set_pad(GNT_BOX(win), 0); | |
522 GNT_WIDGET_SET_FLAGS(win, GNT_WIDGET_TRANSIENT); | |
523 | |
524 tree = wm->_list.tree = gnt_tree_new(); | |
525 gnt_box_add_widget(GNT_BOX(win), tree); | |
526 | |
527 g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(destroy__list), wm); | |
528 } | |
529 | |
530 static void | |
531 window_list_activate(GntTree *tree, GntWM *wm) | |
532 { | |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
533 GntBindable *sel = gnt_tree_get_selection_data(GNT_TREE(tree)); |
15818 | 534 |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
535 gnt_widget_destroy(wm->_list.window); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
536 |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
537 if (!sel) |
15818 | 538 return; |
539 | |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
540 if (GNT_IS_WS(sel)) { |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
541 gnt_wm_switch_workspace(wm, g_list_index(wm->workspaces, sel)); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
542 } else { |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
543 GntNode *node = g_hash_table_lookup(wm->nodes, sel); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
544 if (node && node->ws != wm->cws) |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
545 gnt_wm_switch_workspace(wm, g_list_index(wm->workspaces, node->ws)); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
546 gnt_wm_raise_window(wm, GNT_WIDGET(sel)); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
547 } |
15818 | 548 } |
549 | |
550 static void | |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
551 populate_window_list(GntWM *wm, gboolean workspace) |
15818 | 552 { |
553 GList *iter; | |
554 GntTree *tree = GNT_TREE(wm->windows->tree); | |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
555 if (!workspace) { |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
556 for (iter = wm->cws->list; iter; iter = iter->next) { |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
557 GntBox *box = GNT_BOX(iter->data); |
15818 | 558 |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
559 gnt_tree_add_row_last(tree, box, |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
560 gnt_tree_create_row(tree, box->title), NULL); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
561 update_window_in_list(wm, GNT_WIDGET(box)); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
562 } |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
563 } else { |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
564 GList *ws = wm->workspaces; |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
565 for (; ws; ws = ws->next) { |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
566 gnt_tree_add_row_last(tree, ws->data, |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
567 gnt_tree_create_row(tree, gnt_ws_get_name(GNT_WS(ws->data))), NULL); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
568 for (iter = GNT_WS(ws->data)->list; iter; iter = iter->next) { |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
569 GntBox *box = GNT_BOX(iter->data); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
570 |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
571 gnt_tree_add_row_last(tree, box, |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
572 gnt_tree_create_row(tree, box->title), ws->data); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
573 update_window_in_list(wm, GNT_WIDGET(box)); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
574 } |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
575 } |
15818 | 576 } |
577 } | |
578 | |
579 static gboolean | |
580 window_list_key_pressed(GntWidget *widget, const char *text, GntWM *wm) | |
581 { | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
582 if (text[1] == 0 && wm->cws->ordered) { |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
583 GntBindable *sel = gnt_tree_get_selection_data(GNT_TREE(widget)); |
15818 | 584 switch (text[0]) { |
585 case '-': | |
16127
063274e9cb27
These bindings are easier for changing window order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16126
diff
changeset
|
586 case ',': |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
587 if (GNT_IS_WS(sel)) { |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
588 /* reorder the workspace. */ |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
589 } else |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
590 shift_window(wm, GNT_WIDGET(sel), -1); |
15818 | 591 break; |
16127
063274e9cb27
These bindings are easier for changing window order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16126
diff
changeset
|
592 case '=': |
063274e9cb27
These bindings are easier for changing window order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16126
diff
changeset
|
593 case '.': |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
594 if (GNT_IS_WS(sel)) { |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
595 /* reorder the workspace. */ |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
596 } else |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
597 shift_window(wm, GNT_WIDGET(sel), 1); |
15818 | 598 break; |
599 default: | |
600 return FALSE; | |
601 } | |
602 gnt_tree_remove_all(GNT_TREE(widget)); | |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
603 populate_window_list(wm, GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "workspace"))); |
15818 | 604 gnt_tree_set_selected(GNT_TREE(widget), sel); |
605 return TRUE; | |
606 } | |
607 return FALSE; | |
608 } | |
609 | |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
610 static void |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
611 list_of_windows(GntWM *wm, gboolean workspace) |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
612 { |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
613 GntWidget *tree, *win; |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
614 setup__list(wm); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
615 wm->windows = &wm->_list; |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
616 |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
617 win = wm->windows->window; |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
618 tree = wm->windows->tree; |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
619 |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
620 gnt_box_set_title(GNT_BOX(win), workspace ? "Workspace List" : "Window List"); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
621 |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
622 populate_window_list(wm, workspace); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
623 |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
624 if (wm->cws->ordered) |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
625 gnt_tree_set_selected(GNT_TREE(tree), wm->cws->ordered->data); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
626 else if (workspace) |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
627 gnt_tree_set_selected(GNT_TREE(tree), wm->cws); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
628 |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
629 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(window_list_activate), wm); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
630 g_signal_connect(G_OBJECT(tree), "key_pressed", G_CALLBACK(window_list_key_pressed), wm); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
631 g_object_set_data(G_OBJECT(tree), "workspace", GINT_TO_POINTER(workspace)); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
632 |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
633 gnt_tree_set_col_width(GNT_TREE(tree), 0, getmaxx(stdscr) / 3); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
634 gnt_widget_set_size(tree, 0, getmaxy(stdscr) / 2); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
635 gnt_widget_set_position(win, getmaxx(stdscr) / 3, getmaxy(stdscr) / 4); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
636 |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
637 gnt_widget_show(win); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
638 } |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
639 |
15818 | 640 static gboolean |
641 window_list(GntBindable *bindable, GList *null) | |
642 { | |
643 GntWM *wm = GNT_WM(bindable); | |
644 | |
645 if (wm->_list.window || wm->menu) | |
646 return TRUE; | |
647 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
648 if (!wm->cws->ordered) |
15818 | 649 return TRUE; |
650 | |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
651 list_of_windows(wm, FALSE); |
15818 | 652 |
653 return TRUE; | |
654 } | |
655 | |
656 static gboolean | |
657 dump_screen(GntBindable *bindable, GList *null) | |
658 { | |
659 int x, y; | |
660 chtype old = 0, now = 0; | |
661 FILE *file = fopen("dump.html", "w"); | |
662 | |
663 fprintf(file, "<pre>"); | |
664 for (y = 0; y < getmaxy(stdscr); y++) { | |
665 for (x = 0; x < getmaxx(stdscr); x++) { | |
666 char ch; | |
667 now = mvwinch(curscr, y, x); | |
668 ch = now & A_CHARTEXT; | |
669 now ^= ch; | |
670 | |
671 #define CHECK(attr, start, end) \ | |
672 do \ | |
673 { \ | |
674 if (now & attr) \ | |
675 { \ | |
676 if (!(old & attr)) \ | |
677 fprintf(file, "%s", start); \ | |
678 } \ | |
679 else if (old & attr) \ | |
680 { \ | |
681 fprintf(file, "%s", end); \ | |
682 } \ | |
683 } while (0) | |
684 | |
685 CHECK(A_BOLD, "<b>", "</b>"); | |
686 CHECK(A_UNDERLINE, "<u>", "</u>"); | |
687 CHECK(A_BLINK, "<blink>", "</blink>"); | |
688 | |
689 if ((now & A_COLOR) != (old & A_COLOR) || | |
690 (now & A_REVERSE) != (old & A_REVERSE)) | |
691 { | |
692 int ret; | |
693 short fgp, bgp, r, g, b; | |
694 struct | |
695 { | |
696 int r, g, b; | |
697 } fg, bg; | |
698 | |
699 ret = pair_content(PAIR_NUMBER(now & A_COLOR), &fgp, &bgp); | |
700 if (fgp == -1) | |
701 fgp = COLOR_BLACK; | |
702 if (bgp == -1) | |
703 bgp = COLOR_WHITE; | |
704 if (now & A_REVERSE) | |
705 fgp ^= bgp ^= fgp ^= bgp; /* *wink* */ | |
706 ret = color_content(fgp, &r, &g, &b); | |
707 fg.r = r; fg.b = b; fg.g = g; | |
708 ret = color_content(bgp, &r, &g, &b); | |
709 bg.r = r; bg.b = b; bg.g = g; | |
710 #define ADJUST(x) (x = x * 255 / 1000) | |
711 ADJUST(fg.r); | |
712 ADJUST(fg.g); | |
713 ADJUST(fg.b); | |
714 ADJUST(bg.r); | |
715 ADJUST(bg.b); | |
716 ADJUST(bg.g); | |
717 | |
718 if (x) fprintf(file, "</span>"); | |
719 fprintf(file, "<span style=\"background:#%02x%02x%02x;color:#%02x%02x%02x\">", | |
720 bg.r, bg.g, bg.b, fg.r, fg.g, fg.b); | |
721 } | |
722 if (now & A_ALTCHARSET) | |
723 { | |
724 switch (ch) | |
725 { | |
726 case 'q': | |
727 ch = '-'; break; | |
728 case 't': | |
729 case 'u': | |
730 case 'x': | |
731 ch = '|'; break; | |
732 case 'v': | |
733 case 'w': | |
734 case 'l': | |
735 case 'm': | |
736 case 'k': | |
737 case 'j': | |
738 case 'n': | |
739 ch = '+'; break; | |
740 case '-': | |
741 ch = '^'; break; | |
742 case '.': | |
743 ch = 'v'; break; | |
744 case 'a': | |
745 ch = '#'; break; | |
746 default: | |
747 ch = ' '; break; | |
748 } | |
749 } | |
750 if (ch == '&') | |
751 fprintf(file, "&"); | |
752 else if (ch == '<') | |
753 fprintf(file, "<"); | |
754 else if (ch == '>') | |
755 fprintf(file, ">"); | |
756 else | |
757 fprintf(file, "%c", ch); | |
758 old = now; | |
759 } | |
760 fprintf(file, "</span>\n"); | |
761 old = 0; | |
762 } | |
763 fprintf(file, "</pre>"); | |
764 fclose(file); | |
765 return TRUE; | |
766 } | |
767 | |
768 static void | |
769 shift_window(GntWM *wm, GntWidget *widget, int dir) | |
770 { | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
771 GList *all = wm->cws->list; |
15818 | 772 GList *list = g_list_find(all, widget); |
773 int length, pos; | |
774 if (!list) | |
775 return; | |
776 | |
777 length = g_list_length(all); | |
778 pos = g_list_position(all, list); | |
779 | |
780 pos += dir; | |
781 if (dir > 0) | |
782 pos++; | |
783 | |
784 if (pos < 0) | |
785 pos = length; | |
786 else if (pos > length) | |
787 pos = 0; | |
788 | |
789 all = g_list_insert(all, widget, pos); | |
790 all = g_list_delete_link(all, list); | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
791 wm->cws->list = all; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
792 gnt_ws_draw_taskbar(wm->cws, FALSE); |
15818 | 793 } |
794 | |
795 static gboolean | |
796 shift_left(GntBindable *bindable, GList *null) | |
797 { | |
798 GntWM *wm = GNT_WM(bindable); | |
799 if (wm->_list.window) | |
800 return TRUE; | |
801 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
802 shift_window(wm, wm->cws->ordered->data, -1); |
15818 | 803 return TRUE; |
804 } | |
805 | |
806 static gboolean | |
807 shift_right(GntBindable *bindable, GList *null) | |
808 { | |
809 GntWM *wm = GNT_WM(bindable); | |
810 if (wm->_list.window) | |
811 return TRUE; | |
812 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
813 shift_window(wm, wm->cws->ordered->data, 1); |
15818 | 814 return TRUE; |
815 } | |
816 | |
817 static void | |
818 action_list_activate(GntTree *tree, GntWM *wm) | |
819 { | |
820 GntAction *action = gnt_tree_get_selection_data(tree); | |
821 action->callback(); | |
822 gnt_widget_destroy(wm->_list.window); | |
823 } | |
824 | |
825 static int | |
826 compare_action(gconstpointer p1, gconstpointer p2) | |
827 { | |
828 const GntAction *a1 = p1; | |
829 const GntAction *a2 = p2; | |
830 | |
831 return g_utf8_collate(a1->label, a2->label); | |
832 } | |
833 | |
834 static gboolean | |
835 list_actions(GntBindable *bindable, GList *null) | |
836 { | |
837 GntWidget *tree, *win; | |
838 GList *iter; | |
839 GntWM *wm = GNT_WM(bindable); | |
840 if (wm->_list.window || wm->menu) | |
841 return TRUE; | |
842 | |
843 if (wm->acts == NULL) | |
844 return TRUE; | |
845 | |
846 setup__list(wm); | |
847 wm->actions = &wm->_list; | |
848 | |
849 win = wm->actions->window; | |
850 tree = wm->actions->tree; | |
851 | |
852 gnt_box_set_title(GNT_BOX(win), "Actions"); | |
853 GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER); | |
854 /* XXX: Do we really want this? */ | |
855 gnt_tree_set_compare_func(GNT_TREE(tree), compare_action); | |
856 | |
857 for (iter = wm->acts; iter; iter = iter->next) { | |
858 GntAction *action = iter->data; | |
859 gnt_tree_add_row_last(GNT_TREE(tree), action, | |
860 gnt_tree_create_row(GNT_TREE(tree), action->label), NULL); | |
861 } | |
862 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(action_list_activate), wm); | |
863 gnt_widget_set_size(tree, 0, g_list_length(wm->acts)); | |
864 gnt_widget_set_position(win, 0, getmaxy(stdscr) - 3 - g_list_length(wm->acts)); | |
865 | |
866 gnt_widget_show(win); | |
867 return TRUE; | |
868 } | |
869 | |
870 #ifndef NO_WIDECHAR | |
871 static int | |
872 widestringwidth(wchar_t *wide) | |
873 { | |
874 int len, ret; | |
875 char *string; | |
876 | |
877 len = wcstombs(NULL, wide, 0) + 1; | |
878 string = g_new0(char, len); | |
879 wcstombs(string, wide, len); | |
880 ret = gnt_util_onscreen_width(string, NULL); | |
881 g_free(string); | |
882 return ret; | |
883 } | |
884 #endif | |
885 | |
886 /* Returns the onscreen width of the character at the position */ | |
887 static int | |
888 reverse_char(WINDOW *d, int y, int x, gboolean set) | |
889 { | |
890 #define DECIDE(ch) (set ? ((ch) | A_REVERSE) : ((ch) & ~A_REVERSE)) | |
891 | |
892 #ifdef NO_WIDECHAR | |
893 chtype ch; | |
894 ch = mvwinch(d, y, x); | |
895 mvwaddch(d, y, x, DECIDE(ch)); | |
896 return 1; | |
897 #else | |
898 cchar_t ch; | |
899 int wc = 1; | |
900 if (mvwin_wch(d, y, x, &ch) == OK) { | |
901 wc = widestringwidth(ch.chars); | |
902 ch.attr = DECIDE(ch.attr); | |
903 ch.attr &= WA_ATTRIBUTES; /* XXX: This is a workaround for a bug */ | |
904 mvwadd_wch(d, y, x, &ch); | |
905 } | |
906 | |
907 return wc; | |
908 #endif | |
909 } | |
910 | |
911 static void | |
912 window_reverse(GntWidget *win, gboolean set, GntWM *wm) | |
913 { | |
914 int i; | |
915 int w, h; | |
916 WINDOW *d; | |
917 | |
918 if (GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_NO_BORDER)) | |
919 return; | |
920 | |
921 d = win->window; | |
922 gnt_widget_get_size(win, &w, &h); | |
923 | |
924 if (gnt_widget_has_shadow(win)) { | |
925 --w; | |
926 --h; | |
927 } | |
928 | |
929 /* the top and bottom */ | |
930 for (i = 0; i < w; i += reverse_char(d, 0, i, set)); | |
931 for (i = 0; i < w; i += reverse_char(d, h-1, i, set)); | |
932 | |
933 /* the left and right */ | |
934 for (i = 0; i < h; i += reverse_char(d, i, 0, set)); | |
935 for (i = 0; i < h; i += reverse_char(d, i, w-1, set)); | |
936 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
937 gnt_wm_copy_win(win, g_hash_table_lookup(wm->nodes, win)); |
15818 | 938 update_screen(wm); |
939 } | |
940 | |
941 static gboolean | |
942 start_move(GntBindable *bindable, GList *null) | |
943 { | |
944 GntWM *wm = GNT_WM(bindable); | |
945 if (wm->_list.window || wm->menu) | |
946 return TRUE; | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
947 if (!wm->cws->ordered) |
15818 | 948 return TRUE; |
949 | |
950 wm->mode = GNT_KP_MODE_MOVE; | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
951 window_reverse(GNT_WIDGET(wm->cws->ordered->data), TRUE, wm); |
15818 | 952 |
953 return TRUE; | |
954 } | |
955 | |
956 static gboolean | |
957 start_resize(GntBindable *bindable, GList *null) | |
958 { | |
959 GntWM *wm = GNT_WM(bindable); | |
960 if (wm->_list.window || wm->menu) | |
961 return TRUE; | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
962 if (!wm->cws->ordered) |
15818 | 963 return TRUE; |
964 | |
965 wm->mode = GNT_KP_MODE_RESIZE; | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
966 window_reverse(GNT_WIDGET(wm->cws->ordered->data), TRUE, wm); |
15818 | 967 |
968 return TRUE; | |
969 } | |
970 | |
971 static gboolean | |
972 wm_quit(GntBindable *bindable, GList *list) | |
973 { | |
974 GntWM *wm = GNT_WM(bindable); | |
975 if (write_timeout) | |
976 write_already(wm); | |
977 g_main_loop_quit(wm->loop); | |
978 return TRUE; | |
979 } | |
980 | |
981 static gboolean | |
982 return_true(GntWM *wm, GntWidget *w, int *a, int *b) | |
983 { | |
984 return TRUE; | |
985 } | |
986 | |
987 static gboolean | |
988 refresh_screen(GntBindable *bindable, GList *null) | |
989 { | |
990 GntWM *wm = GNT_WM(bindable); | |
991 | |
992 endwin(); | |
993 refresh(); | |
994 curs_set(0); /* endwin resets the cursor to normal */ | |
995 | |
996 g_hash_table_foreach(wm->nodes, (GHFunc)refresh_node, NULL); | |
997 update_screen(wm); | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
998 gnt_ws_draw_taskbar(wm->cws, TRUE); |
15818 | 999 |
1000 return FALSE; | |
1001 } | |
1002 | |
16526
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1003 static gboolean |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1004 toggle_clipboard(GntBindable *bindable, GList *n) |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1005 { |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1006 static GntWidget *clip; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1007 gchar *text; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1008 int maxx, maxy; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1009 if (clip) { |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1010 gnt_widget_destroy(clip); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1011 clip = NULL; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1012 return TRUE; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1013 } |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1014 getmaxyx(stdscr, maxy, maxx); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1015 text = gnt_get_clipboard_string(); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1016 clip = gnt_hwindow_new(FALSE); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1017 GNT_WIDGET_SET_FLAGS(clip, GNT_WIDGET_TRANSIENT); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1018 GNT_WIDGET_SET_FLAGS(clip, GNT_WIDGET_NO_BORDER); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1019 gnt_box_set_pad(GNT_BOX(clip), 0); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1020 gnt_box_add_widget(GNT_BOX(clip), gnt_label_new(" ")); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1021 gnt_box_add_widget(GNT_BOX(clip), gnt_label_new(text)); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1022 gnt_box_add_widget(GNT_BOX(clip), gnt_label_new(" ")); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1023 gnt_widget_set_position(clip, 0, 0); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1024 gnt_widget_draw(clip); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1025 g_free(text); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1026 return TRUE; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1027 } |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1028 |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1029 static void remove_tag(gpointer wid, gpointer wim) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1030 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1031 GntWM *wm = GNT_WM(wim); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1032 GntWidget *w = GNT_WIDGET(wid); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1033 wm->tagged = g_list_remove(wm->tagged, w); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1034 mvwhline(w->window, 0, 1, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL), 3); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1035 gnt_widget_draw(w); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1036 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1037 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1038 static gboolean |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1039 tag_widget(GntBindable *b, GList *params) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1040 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1041 GntWM *wm = GNT_WM(b); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1042 GntWidget *widget; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1043 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1044 if (!wm->cws->ordered) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1045 return FALSE; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1046 widget = wm->cws->ordered->data; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1047 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1048 if (g_list_find(wm->tagged, widget)) { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1049 remove_tag(widget, wm); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1050 return TRUE; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1051 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1052 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1053 wm->tagged = g_list_prepend(wm->tagged, widget); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1054 wbkgdset(widget->window, ' ' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1055 mvwprintw(widget->window, 0, 1, "[T]"); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1056 gnt_widget_draw(widget); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1057 return TRUE; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1058 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1059 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1060 static void |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1061 widget_move_ws(gpointer wid, gpointer w) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1062 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1063 GntWM *wm = GNT_WM(w); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1064 gnt_wm_widget_move_workspace(wm, wm->cws, GNT_WIDGET(wid)); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1065 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1066 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1067 static gboolean |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1068 place_tagged(GntBindable *b, GList *params) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1069 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1070 GntWM *wm = GNT_WM(b); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1071 g_list_foreach(wm->tagged, widget_move_ws, wm); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1072 g_list_foreach(wm->tagged, remove_tag, wm); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1073 g_list_free(wm->tagged); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1074 wm->tagged = NULL; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1075 return TRUE; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1076 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1077 |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1078 static gboolean |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1079 workspace_list(GntBindable *b, GList *params) |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1080 { |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1081 GntWM *wm = GNT_WM(b); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1082 |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1083 if (wm->_list.window || wm->menu) |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1084 return TRUE; |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1085 |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1086 list_of_windows(wm, TRUE); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1087 |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1088 return TRUE; |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1089 } |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1090 |
15818 | 1091 static void |
1092 gnt_wm_class_init(GntWMClass *klass) | |
1093 { | |
1094 int i; | |
1095 | |
1096 klass->new_window = gnt_wm_new_window_real; | |
1097 klass->decorate_window = NULL; | |
1098 klass->close_window = NULL; | |
1099 klass->window_resize_confirm = return_true; | |
1100 klass->window_resized = gnt_wm_win_resized; | |
1101 klass->window_move_confirm = return_true; | |
1102 klass->window_moved = gnt_wm_win_moved; | |
1103 klass->window_update = NULL; | |
1104 klass->key_pressed = NULL; | |
1105 klass->mouse_clicked = NULL; | |
1106 klass->give_focus = gnt_wm_give_focus; | |
1107 | |
1108 signals[SIG_NEW_WIN] = | |
1109 g_signal_new("new_win", | |
1110 G_TYPE_FROM_CLASS(klass), | |
1111 G_SIGNAL_RUN_LAST, | |
1112 G_STRUCT_OFFSET(GntWMClass, new_window), | |
1113 NULL, NULL, | |
1114 g_cclosure_marshal_VOID__POINTER, | |
1115 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1116 signals[SIG_DECORATE_WIN] = | |
1117 g_signal_new("decorate_win", | |
1118 G_TYPE_FROM_CLASS(klass), | |
1119 G_SIGNAL_RUN_LAST, | |
1120 G_STRUCT_OFFSET(GntWMClass, decorate_window), | |
1121 NULL, NULL, | |
1122 g_cclosure_marshal_VOID__POINTER, | |
1123 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1124 signals[SIG_CLOSE_WIN] = | |
1125 g_signal_new("close_win", | |
1126 G_TYPE_FROM_CLASS(klass), | |
1127 G_SIGNAL_RUN_LAST, | |
1128 G_STRUCT_OFFSET(GntWMClass, close_window), | |
1129 NULL, NULL, | |
1130 g_cclosure_marshal_VOID__POINTER, | |
1131 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1132 signals[SIG_CONFIRM_RESIZE] = | |
1133 g_signal_new("confirm_resize", | |
1134 G_TYPE_FROM_CLASS(klass), | |
1135 G_SIGNAL_RUN_LAST, | |
1136 G_STRUCT_OFFSET(GntWMClass, window_resize_confirm), | |
1137 gnt_boolean_handled_accumulator, NULL, | |
1138 gnt_closure_marshal_BOOLEAN__POINTER_POINTER_POINTER, | |
1139 G_TYPE_BOOLEAN, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER); | |
1140 | |
1141 signals[SIG_CONFIRM_MOVE] = | |
1142 g_signal_new("confirm_move", | |
1143 G_TYPE_FROM_CLASS(klass), | |
1144 G_SIGNAL_RUN_LAST, | |
1145 G_STRUCT_OFFSET(GntWMClass, window_move_confirm), | |
1146 gnt_boolean_handled_accumulator, NULL, | |
1147 gnt_closure_marshal_BOOLEAN__POINTER_POINTER_POINTER, | |
1148 G_TYPE_BOOLEAN, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER); | |
1149 | |
1150 signals[SIG_RESIZED] = | |
1151 g_signal_new("window_resized", | |
1152 G_TYPE_FROM_CLASS(klass), | |
1153 G_SIGNAL_RUN_LAST, | |
1154 G_STRUCT_OFFSET(GntWMClass, window_resized), | |
1155 NULL, NULL, | |
1156 g_cclosure_marshal_VOID__POINTER, | |
1157 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1158 signals[SIG_MOVED] = | |
1159 g_signal_new("window_moved", | |
1160 G_TYPE_FROM_CLASS(klass), | |
1161 G_SIGNAL_RUN_LAST, | |
1162 G_STRUCT_OFFSET(GntWMClass, window_moved), | |
1163 NULL, NULL, | |
1164 g_cclosure_marshal_VOID__POINTER, | |
1165 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1166 signals[SIG_UPDATE_WIN] = | |
1167 g_signal_new("window_update", | |
1168 G_TYPE_FROM_CLASS(klass), | |
1169 G_SIGNAL_RUN_LAST, | |
1170 G_STRUCT_OFFSET(GntWMClass, window_update), | |
1171 NULL, NULL, | |
1172 g_cclosure_marshal_VOID__POINTER, | |
1173 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1174 | |
1175 signals[SIG_GIVE_FOCUS] = | |
1176 g_signal_new("give_focus", | |
1177 G_TYPE_FROM_CLASS(klass), | |
1178 G_SIGNAL_RUN_LAST, | |
1179 G_STRUCT_OFFSET(GntWMClass, give_focus), | |
1180 NULL, NULL, | |
1181 g_cclosure_marshal_VOID__POINTER, | |
1182 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1183 | |
1184 signals[SIG_MOUSE_CLICK] = | |
1185 g_signal_new("mouse_clicked", | |
1186 G_TYPE_FROM_CLASS(klass), | |
1187 G_SIGNAL_RUN_LAST, | |
1188 G_STRUCT_OFFSET(GntWMClass, mouse_clicked), | |
1189 gnt_boolean_handled_accumulator, NULL, | |
1190 gnt_closure_marshal_BOOLEAN__INT_INT_INT_POINTER, | |
1191 G_TYPE_BOOLEAN, 4, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_POINTER); | |
1192 | |
1193 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-next", window_next, | |
1194 "\033" "n", NULL); | |
1195 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-prev", window_prev, | |
1196 "\033" "p", NULL); | |
1197 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-close", window_close, | |
1198 "\033" "c", NULL); | |
1199 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-list", window_list, | |
1200 "\033" "w", NULL); | |
1201 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "dump-screen", dump_screen, | |
1202 "\033" "d", NULL); | |
1203 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "shift-left", shift_left, | |
1204 "\033" ",", NULL); | |
1205 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "shift-right", shift_right, | |
1206 "\033" ".", NULL); | |
1207 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "action-list", list_actions, | |
1208 "\033" "a", NULL); | |
1209 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "start-move", start_move, | |
1210 "\033" "m", NULL); | |
1211 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "start-resize", start_resize, | |
1212 "\033" "r", NULL); | |
1213 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "wm-quit", wm_quit, | |
1214 "\033" "q", NULL); | |
1215 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "refresh-screen", refresh_screen, | |
1216 "\033" "l", NULL); | |
1217 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "switch-window-n", switch_window_n, | |
1218 NULL, NULL); | |
1219 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-scroll-down", window_scroll_down, | |
1220 "\033" GNT_KEY_CTRL_J, NULL); | |
1221 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-scroll-up", window_scroll_up, | |
1222 "\033" GNT_KEY_CTRL_K, NULL); | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1223 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "help-for-widget", help_for_widget, |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1224 "\033" "/", NULL); |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1225 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "workspace-next", workspace_next, |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1226 "\033" ">", NULL); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1227 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "workspace-prev", workspace_prev, |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1228 "\033" "<", NULL); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1229 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-tag", tag_widget, |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1230 "\033" "t", NULL); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1231 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "place-tagged", place_tagged, |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1232 "\033" "T", NULL); |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1233 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "workspace-list", workspace_list, |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1234 "\033" "s", NULL); |
16526
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1235 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "toggle-clipboard", |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1236 toggle_clipboard, "\033" "C", NULL); |
15818 | 1237 |
1238 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); | |
1239 | |
1240 /* Make sure Alt+x are detected properly. */ | |
1241 for (i = '0'; i <= '9'; i++) { | |
1242 char str[] = "\033X"; | |
1243 str[1] = i; | |
1244 gnt_keys_add_combination(str); | |
1245 } | |
1246 | |
1247 GNTDEBUG; | |
1248 } | |
1249 | |
1250 /****************************************************************************** | |
1251 * GntWM API | |
1252 *****************************************************************************/ | |
1253 GType | |
1254 gnt_wm_get_gtype(void) | |
1255 { | |
1256 static GType type = 0; | |
1257 | |
1258 if(type == 0) { | |
1259 static const GTypeInfo info = { | |
1260 sizeof(GntWMClass), | |
1261 NULL, /* base_init */ | |
1262 NULL, /* base_finalize */ | |
1263 (GClassInitFunc)gnt_wm_class_init, | |
1264 NULL, | |
1265 NULL, /* class_data */ | |
1266 sizeof(GntWM), | |
1267 0, /* n_preallocs */ | |
1268 gnt_wm_init, /* instance_init */ | |
1269 NULL /* value_table */ | |
1270 }; | |
1271 | |
1272 type = g_type_register_static(GNT_TYPE_BINDABLE, | |
1273 "GntWM", | |
1274 &info, 0); | |
1275 } | |
1276 | |
1277 return type; | |
1278 } | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1279 void |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1280 gnt_wm_add_workspace(GntWM *wm, GntWS *ws) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1281 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1282 wm->workspaces = g_list_append(wm->workspaces, ws); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1283 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1284 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1285 gboolean |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1286 gnt_wm_switch_workspace(GntWM *wm, gint n) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1287 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1288 GntWS *s = g_list_nth_data(wm->workspaces, n); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1289 if (!s) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1290 return FALSE; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1291 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1292 if (wm->_list.window) { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1293 gnt_widget_destroy(wm->_list.window); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1294 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1295 gnt_ws_hide(wm->cws, wm->nodes); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1296 wm->cws = s; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1297 gnt_ws_show(wm->cws, wm->nodes); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1298 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1299 gnt_ws_draw_taskbar(wm->cws, TRUE); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1300 update_screen(wm); |
16472
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
1301 if (wm->cws->ordered) { |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1302 gnt_widget_set_focus(wm->cws->ordered->data, TRUE); |
16472
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
1303 gnt_wm_raise_window(wm, wm->cws->ordered->data); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
1304 } |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
1305 |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
1306 if (act && g_list_find(act, wm->cws)) { |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
1307 act = g_list_remove(act, wm->cws); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
1308 update_act_msg(); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
1309 } |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1310 return TRUE; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1311 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1312 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1313 gboolean |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1314 gnt_wm_switch_workspace_prev(GntWM *wm) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1315 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1316 int n = g_list_index(wm->workspaces, wm->cws); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1317 return gnt_wm_switch_workspace(wm, --n); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1318 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1319 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1320 gboolean |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1321 gnt_wm_switch_workspace_next(GntWM *wm) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1322 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1323 int n = g_list_index(wm->workspaces, wm->cws); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1324 return gnt_wm_switch_workspace(wm, ++n); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1325 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1326 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1327 static gboolean |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1328 workspace_next(GntBindable *wm, GList *n) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1329 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1330 return gnt_wm_switch_workspace_next(GNT_WM(wm)); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1331 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1332 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1333 static gboolean |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1334 workspace_prev(GntBindable *wm, GList *n) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1335 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1336 return gnt_wm_switch_workspace_prev(GNT_WM(wm)); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1337 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1338 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1339 void |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1340 gnt_wm_widget_move_workspace(GntWM *wm, GntWS *neww, GntWidget *widget) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1341 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1342 GntWS *oldw = gnt_wm_widget_find_workspace(wm, widget); |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1343 GntNode *node; |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1344 if (!oldw || oldw == neww) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1345 return; |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1346 node = g_hash_table_lookup(wm->nodes, widget); |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1347 if (node && node->ws == neww) |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1348 return; |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1349 |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1350 if (node) |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1351 node->ws = neww; |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1352 |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1353 gnt_ws_remove_widget(oldw, widget); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1354 gnt_ws_add_widget(neww, widget); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1355 if (neww == wm->cws) { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1356 gnt_ws_widget_show(widget, wm->nodes); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1357 } else { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1358 gnt_ws_widget_hide(widget, wm->nodes); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1359 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1360 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1361 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1362 static gint widget_in_workspace(gconstpointer workspace, gconstpointer wid) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1363 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1364 GntWS *s = (GntWS *)workspace; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1365 if (s->list && g_list_find(s->list, wid)) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1366 return 0; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1367 return 1; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1368 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1369 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1370 GntWS *gnt_wm_widget_find_workspace(GntWM *wm, GntWidget *widget) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1371 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1372 GList *l = g_list_find_custom(wm->workspaces, widget, widget_in_workspace); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1373 if (l) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1374 return l->data; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1375 return NULL; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1376 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1377 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1378 static void free_workspaces(gpointer data, gpointer n) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1379 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1380 GntWS *s = data; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1381 g_free(s->name); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1382 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1383 |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1384 void gnt_wm_set_workspaces(GntWM *wm, GList *workspaces) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1385 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1386 g_list_foreach(wm->workspaces, free_workspaces, NULL); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1387 wm->workspaces = workspaces; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1388 gnt_wm_switch_workspace(wm, 0); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1389 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1390 |
15818 | 1391 static void |
1392 update_window_in_list(GntWM *wm, GntWidget *wid) | |
1393 { | |
1394 GntTextFormatFlags flag = 0; | |
1395 | |
1396 if (wm->windows == NULL) | |
1397 return; | |
1398 | |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1399 if (wm->cws->ordered && wid == wm->cws->ordered->data) |
15818 | 1400 flag |= GNT_TEXT_FLAG_DIM; |
1401 else if (GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_URGENT)) | |
1402 flag |= GNT_TEXT_FLAG_BOLD; | |
1403 | |
1404 gnt_tree_set_row_flags(GNT_TREE(wm->windows->tree), wid, flag); | |
1405 } | |
1406 | |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1407 static gboolean |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1408 match_title(gpointer title, gpointer n, gpointer wid_title) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1409 { |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1410 /* maybe check for regex.h? */ |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1411 if (g_strrstr((gchar *)wid_title, (gchar *)title)) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1412 return TRUE; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1413 return FALSE; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1414 } |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1415 |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1416 static GntWS * |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1417 new_widget_find_workspace(GntWM *wm, GntWidget *widget, gchar *wid_title) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1418 { |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1419 GntWS *ret; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1420 const gchar *name; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1421 ret = g_hash_table_find(wm->title_places, match_title, wid_title); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1422 if (ret) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1423 return ret; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1424 name = gnt_widget_get_name(widget); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1425 if (name) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1426 ret = g_hash_table_lookup(wm->name_places, name); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1427 return ret ? ret : wm->cws; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1428 } |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1429 |
15818 | 1430 static void |
1431 gnt_wm_new_window_real(GntWM *wm, GntWidget *widget) | |
1432 { | |
1433 GntNode *node; | |
1434 gboolean transient = FALSE; | |
1435 | |
1436 if (widget->window == NULL) | |
1437 return; | |
1438 | |
1439 node = g_new0(GntNode, 1); | |
1440 node->me = widget; | |
1441 node->scroll = 0; | |
1442 | |
1443 g_hash_table_replace(wm->nodes, widget, node); | |
1444 | |
1445 refresh_node(widget, node, NULL); | |
1446 | |
1447 transient = !!GNT_WIDGET_IS_FLAG_SET(node->me, GNT_WIDGET_TRANSIENT); | |
1448 | |
1449 #if 1 | |
1450 { | |
1451 int x, y, w, h, maxx, maxy; | |
1452 gboolean shadow = TRUE; | |
1453 | |
1454 if (!gnt_widget_has_shadow(widget)) | |
1455 shadow = FALSE; | |
1456 x = widget->priv.x; | |
1457 y = widget->priv.y; | |
1458 w = widget->priv.width; | |
1459 h = widget->priv.height; | |
1460 | |
1461 getmaxyx(stdscr, maxy, maxx); | |
1462 maxy -= 1; /* room for the taskbar */ | |
1463 maxy -= shadow; | |
1464 maxx -= shadow; | |
1465 | |
1466 x = MAX(0, x); | |
1467 y = MAX(0, y); | |
1468 if (x + w >= maxx) | |
1469 x = MAX(0, maxx - w); | |
1470 if (y + h >= maxy) | |
1471 y = MAX(0, maxy - h); | |
1472 | |
1473 w = MIN(w, maxx); | |
1474 h = MIN(h, maxy); | |
1475 node->window = newwin(h + shadow, w + shadow, y, x); | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1476 gnt_wm_copy_win(widget, node); |
15818 | 1477 } |
1478 #endif | |
1479 | |
1480 node->panel = new_panel(node->window); | |
1481 set_panel_userptr(node->panel, node); | |
1482 | |
1483 if (!transient) { | |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1484 GntWS *ws = wm->cws; |
15818 | 1485 if (node->me != wm->_list.window) { |
1486 GntWidget *w = NULL; | |
1487 | |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1488 if (GNT_IS_BOX(widget)) { |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1489 char *title = GNT_BOX(widget)->title; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1490 ws = new_widget_find_workspace(wm, widget, title); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1491 } |
15818 | 1492 |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1493 if (ws->ordered) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1494 w = ws->ordered->data; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1495 |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1496 node->ws = ws; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1497 ws->list = g_list_append(ws->list, widget); |
15818 | 1498 |
1499 if (wm->event_stack) | |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1500 ws->ordered = g_list_prepend(ws->ordered, widget); |
15818 | 1501 else |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1502 ws->ordered = g_list_append(ws->ordered, widget); |
15818 | 1503 |
1504 gnt_widget_set_focus(widget, TRUE); | |
1505 if (w) | |
1506 gnt_widget_set_focus(w, FALSE); | |
1507 } | |
1508 | |
1509 if (wm->event_stack || node->me == wm->_list.window) { | |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1510 if (wm->cws != ws) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1511 gnt_wm_switch_workspace(wm, g_list_index(wm->workspaces, ws)); |
15818 | 1512 gnt_wm_raise_window(wm, node->me); |
1513 } else { | |
1514 bottom_panel(node->panel); /* New windows should not grab focus */ | |
1515 gnt_widget_set_urgent(node->me); | |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1516 if (wm->cws != ws) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
1517 gnt_ws_widget_hide(widget, wm->nodes); |
15818 | 1518 } |
1519 } | |
1520 } | |
1521 | |
1522 void gnt_wm_new_window(GntWM *wm, GntWidget *widget) | |
1523 { | |
1524 while (widget->parent) | |
1525 widget = widget->parent; | |
1526 | |
1527 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_INVISIBLE) || | |
1528 g_hash_table_lookup(wm->nodes, widget)) { | |
1529 update_screen(wm); | |
1530 return; | |
1531 } | |
1532 | |
1533 if (GNT_IS_BOX(widget)) { | |
1534 const char *title = GNT_BOX(widget)->title; | |
1535 GntPosition *p = NULL; | |
1536 if (title && (p = g_hash_table_lookup(wm->positions, title)) != NULL) { | |
1537 sanitize_position(widget, &p->x, &p->y); | |
1538 gnt_widget_set_position(widget, p->x, p->y); | |
1539 mvwin(widget->window, p->y, p->x); | |
1540 } | |
1541 } | |
1542 | |
1543 g_signal_emit(wm, signals[SIG_NEW_WIN], 0, widget); | |
1544 g_signal_emit(wm, signals[SIG_DECORATE_WIN], 0, widget); | |
1545 | |
1546 if (wm->windows && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { | |
1547 if ((GNT_IS_BOX(widget) && GNT_BOX(widget)->title) && wm->_list.window != widget | |
1548 && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS)) { | |
1549 gnt_tree_add_row_last(GNT_TREE(wm->windows->tree), widget, | |
1550 gnt_tree_create_row(GNT_TREE(wm->windows->tree), GNT_BOX(widget)->title), | |
16471
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16414
diff
changeset
|
1551 g_object_get_data(G_OBJECT(wm->windows->tree), "workspace") ? wm->cws : NULL); |
15818 | 1552 update_window_in_list(wm, widget); |
1553 } | |
1554 } | |
1555 | |
1556 update_screen(wm); | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1557 gnt_ws_draw_taskbar(wm->cws, FALSE); |
15818 | 1558 } |
1559 | |
1560 void gnt_wm_window_decorate(GntWM *wm, GntWidget *widget) | |
1561 { | |
1562 g_signal_emit(wm, signals[SIG_DECORATE_WIN], 0, widget); | |
1563 } | |
1564 | |
1565 void gnt_wm_window_close(GntWM *wm, GntWidget *widget) | |
1566 { | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1567 GntWS *s; |
15818 | 1568 GntNode *node; |
1569 int pos; | |
1570 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1571 s = gnt_wm_widget_find_workspace(wm, widget); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1572 |
15818 | 1573 if ((node = g_hash_table_lookup(wm->nodes, widget)) == NULL) |
1574 return; | |
1575 | |
1576 g_signal_emit(wm, signals[SIG_CLOSE_WIN], 0, widget); | |
1577 g_hash_table_remove(wm->nodes, widget); | |
1578 | |
1579 if (wm->windows) { | |
1580 gnt_tree_remove(GNT_TREE(wm->windows->tree), widget); | |
1581 } | |
1582 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1583 if (s) { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1584 pos = g_list_index(s->list, widget); |
15818 | 1585 |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1586 if (pos != -1) { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1587 s->list = g_list_remove(s->list, widget); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1588 s->ordered = g_list_remove(s->ordered, widget); |
15818 | 1589 |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1590 if (s->ordered && wm->cws == s) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1591 gnt_wm_raise_window(wm, s->ordered->data); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1592 } |
15818 | 1593 } |
1594 | |
1595 update_screen(wm); | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1596 gnt_ws_draw_taskbar(wm->cws, FALSE); |
15818 | 1597 } |
1598 | |
1599 time_t gnt_wm_get_idle_time() | |
1600 { | |
1601 return time(NULL) - last_active_time; | |
1602 } | |
1603 | |
1604 gboolean gnt_wm_process_input(GntWM *wm, const char *keys) | |
1605 { | |
1606 gboolean ret = FALSE; | |
1607 | |
1608 keys = gnt_bindable_remap_keys(GNT_BINDABLE(wm), keys); | |
1609 | |
1610 idle_update = TRUE; | |
1611 | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1612 if (gnt_bindable_perform_action_key(GNT_BINDABLE(wm), keys)) { |
15818 | 1613 return TRUE; |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1614 } |
15818 | 1615 |
1616 /* Do some manual checking */ | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1617 if (wm->cws->ordered && wm->mode != GNT_KP_MODE_NORMAL) { |
15818 | 1618 int xmin = 0, ymin = 0, xmax = getmaxx(stdscr), ymax = getmaxy(stdscr) - 1; |
1619 int x, y, w, h; | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1620 GntWidget *widget = GNT_WIDGET(wm->cws->ordered->data); |
15818 | 1621 int ox, oy, ow, oh; |
1622 | |
1623 gnt_widget_get_position(widget, &x, &y); | |
1624 gnt_widget_get_size(widget, &w, &h); | |
1625 ox = x; oy = y; | |
1626 ow = w; oh = h; | |
1627 | |
1628 if (wm->mode == GNT_KP_MODE_MOVE) { | |
1629 if (strcmp(keys, GNT_KEY_LEFT) == 0) { | |
1630 if (x > xmin) | |
1631 x--; | |
1632 } else if (strcmp(keys, GNT_KEY_RIGHT) == 0) { | |
1633 if (x + w < xmax) | |
1634 x++; | |
1635 } else if (strcmp(keys, GNT_KEY_UP) == 0) { | |
1636 if (y > ymin) | |
1637 y--; | |
1638 } else if (strcmp(keys, GNT_KEY_DOWN) == 0) { | |
1639 if (y + h < ymax) | |
1640 y++; | |
1641 } | |
1642 if (ox != x || oy != y) { | |
1643 gnt_screen_move_widget(widget, x, y); | |
1644 window_reverse(widget, TRUE, wm); | |
1645 return TRUE; | |
1646 } | |
1647 } else if (wm->mode == GNT_KP_MODE_RESIZE) { | |
1648 if (strcmp(keys, GNT_KEY_LEFT) == 0) { | |
1649 w--; | |
1650 } else if (strcmp(keys, GNT_KEY_RIGHT) == 0) { | |
1651 if (x + w < xmax) | |
1652 w++; | |
1653 } else if (strcmp(keys, GNT_KEY_UP) == 0) { | |
1654 h--; | |
1655 } else if (strcmp(keys, GNT_KEY_DOWN) == 0) { | |
1656 if (y + h < ymax) | |
1657 h++; | |
1658 } | |
1659 if (oh != h || ow != w) { | |
1660 gnt_screen_resize_widget(widget, w, h); | |
1661 window_reverse(widget, TRUE, wm); | |
1662 return TRUE; | |
1663 } | |
1664 } | |
1665 if (strcmp(keys, "\r") == 0 || strcmp(keys, "\033") == 0) { | |
1666 window_reverse(widget, FALSE, wm); | |
1667 wm->mode = GNT_KP_MODE_NORMAL; | |
1668 } | |
1669 return TRUE; | |
1670 } | |
1671 | |
1672 /* Escape to close the window-list or action-list window */ | |
1673 if (strcmp(keys, "\033") == 0) { | |
1674 if (wm->_list.window) { | |
1675 gnt_widget_destroy(wm->_list.window); | |
1676 return TRUE; | |
1677 } | |
1678 } else if (keys[0] == '\033' && isdigit(keys[1]) && keys[2] == '\0') { | |
1679 /* Alt+x for quick switch */ | |
1680 int n = *(keys + 1) - '0'; | |
1681 GList *list = NULL; | |
1682 | |
1683 if (n == 0) | |
1684 n = 10; | |
1685 | |
1686 list = g_list_append(list, GINT_TO_POINTER(n - 1)); | |
1687 switch_window_n(GNT_BINDABLE(wm), list); | |
1688 g_list_free(list); | |
1689 return TRUE; | |
1690 } | |
1691 | |
1692 if (wm->menu) | |
1693 ret = gnt_widget_key_pressed(GNT_WIDGET(wm->menu), keys); | |
1694 else if (wm->_list.window) | |
1695 ret = gnt_widget_key_pressed(wm->_list.window, keys); | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1696 else if (wm->cws->ordered) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1697 ret = gnt_widget_key_pressed(GNT_WIDGET(wm->cws->ordered->data), keys); |
15818 | 1698 return ret; |
1699 } | |
1700 | |
1701 static void | |
1702 gnt_wm_win_resized(GntWM *wm, GntNode *node) | |
1703 { | |
1704 /*refresh_node(node->me, node, NULL);*/ | |
1705 } | |
1706 | |
1707 static void | |
1708 gnt_wm_win_moved(GntWM *wm, GntNode *node) | |
1709 { | |
1710 refresh_node(node->me, node, NULL); | |
1711 } | |
1712 | |
1713 void gnt_wm_resize_window(GntWM *wm, GntWidget *widget, int width, int height) | |
1714 { | |
1715 gboolean ret = TRUE; | |
1716 GntNode *node; | |
1717 int shadow; | |
1718 int maxx, maxy; | |
1719 | |
1720 while (widget->parent) | |
1721 widget = widget->parent; | |
1722 node = g_hash_table_lookup(wm->nodes, widget); | |
1723 if (!node) | |
1724 return; | |
1725 | |
1726 g_signal_emit(wm, signals[SIG_CONFIRM_RESIZE], 0, widget, &width, &height, &ret); | |
1727 if (!ret) | |
1728 return; /* resize is not permitted */ | |
1729 hide_panel(node->panel); | |
1730 gnt_widget_set_size(widget, width, height); | |
1731 gnt_widget_draw(widget); | |
1732 | |
1733 shadow = gnt_widget_has_shadow(widget) ? 1 : 0; | |
1734 maxx = getmaxx(stdscr) - shadow; | |
1735 maxy = getmaxy(stdscr) - 1 - shadow; | |
1736 height = MIN(height, maxy); | |
1737 width = MIN(width, maxx); | |
15978
2a82bc8d57f7
More fixes for resizing when shadow is turned on.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15964
diff
changeset
|
1738 wresize(node->window, height, width); |
15818 | 1739 replace_panel(node->panel, node->window); |
1740 | |
1741 g_signal_emit(wm, signals[SIG_RESIZED], 0, node); | |
1742 | |
1743 show_panel(node->panel); | |
1744 update_screen(wm); | |
1745 } | |
1746 | |
1747 static void | |
1748 write_gdi(gpointer key, gpointer value, gpointer data) | |
1749 { | |
1750 GntPosition *p = value; | |
1751 fprintf(data, ".%s = %d;%d\n", (char *)key, p->x, p->y); | |
1752 } | |
1753 | |
1754 static gboolean | |
1755 write_already(gpointer data) | |
1756 { | |
1757 GntWM *wm = data; | |
1758 FILE *file; | |
1759 char *filename; | |
1760 | |
1761 filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL); | |
1762 | |
1763 file = fopen(filename, "wb"); | |
1764 if (file == NULL) { | |
1765 g_printerr("GntWM: error opening file to save positions\n"); | |
1766 } else { | |
1767 fprintf(file, "[positions]\n"); | |
1768 g_hash_table_foreach(wm->positions, write_gdi, file); | |
1769 fclose(file); | |
1770 } | |
1771 | |
1772 g_free(filename); | |
1773 g_source_remove(write_timeout); | |
1774 write_timeout = 0; | |
1775 return FALSE; | |
1776 } | |
1777 | |
1778 static void | |
1779 write_positions_to_file(GntWM *wm) | |
1780 { | |
1781 if (write_timeout) { | |
1782 g_source_remove(write_timeout); | |
1783 } | |
1784 write_timeout = g_timeout_add(10000, write_already, wm); | |
1785 } | |
1786 | |
1787 void gnt_wm_move_window(GntWM *wm, GntWidget *widget, int x, int y) | |
1788 { | |
1789 gboolean ret = TRUE; | |
1790 GntNode *node; | |
1791 | |
1792 while (widget->parent) | |
1793 widget = widget->parent; | |
1794 node = g_hash_table_lookup(wm->nodes, widget); | |
1795 if (!node) | |
1796 return; | |
1797 | |
1798 g_signal_emit(wm, signals[SIG_CONFIRM_MOVE], 0, widget, &x, &y, &ret); | |
1799 if (!ret) | |
1800 return; /* resize is not permitted */ | |
1801 | |
1802 gnt_widget_set_position(widget, x, y); | |
1803 move_panel(node->panel, y, x); | |
1804 | |
1805 g_signal_emit(wm, signals[SIG_MOVED], 0, node); | |
15995
bc2dd3358d46
Don't remember the position of transient windows
Richard Nelson <wabz@pidgin.im>
parents:
15978
diff
changeset
|
1806 if (gnt_style_get_bool(GNT_STYLE_REMPOS, TRUE) && GNT_IS_BOX(widget) && |
bc2dd3358d46
Don't remember the position of transient windows
Richard Nelson <wabz@pidgin.im>
parents:
15978
diff
changeset
|
1807 !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { |
15818 | 1808 const char *title = GNT_BOX(widget)->title; |
1809 if (title) { | |
1810 GntPosition *p = g_new0(GntPosition, 1); | |
1811 GntWidget *wid = node->me; | |
1812 p->x = wid->priv.x; | |
1813 p->y = wid->priv.y; | |
1814 g_hash_table_replace(wm->positions, g_strdup(title), p); | |
1815 write_positions_to_file(wm); | |
1816 } | |
1817 } | |
1818 | |
1819 update_screen(wm); | |
1820 } | |
1821 | |
1822 static void | |
1823 gnt_wm_give_focus(GntWM *wm, GntWidget *widget) | |
1824 { | |
1825 GntNode *node = g_hash_table_lookup(wm->nodes, widget); | |
1826 | |
1827 if (!node) | |
1828 return; | |
1829 | |
1830 if (widget != wm->_list.window && !GNT_IS_MENU(widget) && | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1831 wm->cws->ordered->data != widget) { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1832 GntWidget *w = wm->cws->ordered->data; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1833 wm->cws->ordered = g_list_bring_to_front(wm->cws->ordered, widget); |
15818 | 1834 gnt_widget_set_focus(w, FALSE); |
1835 } | |
1836 | |
1837 gnt_widget_set_focus(widget, TRUE); | |
1838 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_URGENT); | |
1839 gnt_widget_draw(widget); | |
1840 top_panel(node->panel); | |
1841 | |
1842 if (wm->_list.window) { | |
1843 GntNode *nd = g_hash_table_lookup(wm->nodes, wm->_list.window); | |
1844 top_panel(nd->panel); | |
1845 } | |
1846 update_screen(wm); | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1847 gnt_ws_draw_taskbar(wm->cws, FALSE); |
15818 | 1848 } |
1849 | |
1850 void gnt_wm_update_window(GntWM *wm, GntWidget *widget) | |
1851 { | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1852 GntNode *node = NULL; |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1853 GntWS *ws; |
15818 | 1854 |
1855 while (widget->parent) | |
1856 widget = widget->parent; | |
1857 if (!GNT_IS_MENU(widget)) | |
1858 gnt_box_sync_children(GNT_BOX(widget)); | |
1859 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1860 ws = gnt_wm_widget_find_workspace(wm, widget); |
15818 | 1861 node = g_hash_table_lookup(wm->nodes, widget); |
1862 if (node == NULL) { | |
1863 gnt_wm_new_window(wm, widget); | |
1864 } else | |
1865 g_signal_emit(wm, signals[SIG_UPDATE_WIN], 0, node); | |
1866 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1867 if (ws == wm->cws || GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1868 gnt_wm_copy_win(widget, node); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1869 update_screen(wm); |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1870 gnt_ws_draw_taskbar(wm->cws, FALSE); |
16472
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
1871 } else if (ws != wm->cws && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_URGENT)) { |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
1872 if (!act || (act && !g_list_find(act, ws))) |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
1873 act = g_list_prepend(act, ws); |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16471
diff
changeset
|
1874 update_act_msg(); |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
1875 } |
15818 | 1876 } |
1877 | |
1878 gboolean gnt_wm_process_click(GntWM *wm, GntMouseEvent event, int x, int y, GntWidget *widget) | |
1879 { | |
1880 gboolean ret = TRUE; | |
1881 idle_update = TRUE; | |
1882 g_signal_emit(wm, signals[SIG_MOUSE_CLICK], 0, event, x, y, widget, &ret); | |
1883 return ret; | |
1884 } | |
1885 | |
1886 void gnt_wm_raise_window(GntWM *wm, GntWidget *widget) | |
1887 { | |
1888 g_signal_emit(wm, signals[SIG_GIVE_FOCUS], 0, widget); | |
1889 } | |
1890 | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1891 void gnt_wm_set_event_stack(GntWM *wm, gboolean set) |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1892 { |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1893 wm->event_stack = set; |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1894 } |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1895 |