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