comparison gtk/plugins/win32/transparency/win2ktrans.c @ 14224:ab8a105eff62

[gaim-migrate @ 16905] First step of getting wingaim working again. libgaim and gtk are compiling. The protocols aren't compiling yet. There are a number of things that are compiling, but should be cleaned up. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Sun, 20 Aug 2006 16:49:37 +0000
parents
children
comparison
equal deleted inserted replaced
14223:7c560c01b8f9 14224:ab8a105eff62
1 /*
2 * gaim - Transparency plugin
3 *
4 * copyright (c) 1998-2002, rob flynn <rob@marko.net>
5 * copyright (c) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com>
6 * copyright (c) 2005, Daniel Atallah <daniel_atallah@yahoo.com>
7 *
8 * this program is free software; you can redistribute it and/or modify
9 * it under the terms of the gnu general public license as published by
10 * the free software foundation; either version 2 of the license, or
11 * (at your option) any later version.
12 *
13 * this program is distributed in the hope that it will be useful,
14 * but without any warranty; without even the implied warranty of
15 * merchantability or fitness for a particular purpose. see the
16 * gnu general public license for more details.
17 *
18 * you should have received a copy of the gnu general public license
19 * along with this program; if not, write to the free software
20 * foundation, inc., 59 temple place, suite 330, boston, ma 02111-1307 usa
21 *
22 */
23 #ifndef _WIN32_WINNT
24 #define _WIN32_WINNT 0x0500
25 #endif
26 #include <gdk/gdkwin32.h>
27 #include "internal.h"
28
29 #include "core.h"
30 #include "prefs.h"
31 #include "debug.h"
32
33 #include "gtkconv.h"
34 #include "gtkplugin.h"
35 #include "gtkprefs.h"
36 #include "gtkblist.h"
37 #include "gtkutils.h"
38 #include "signals.h"
39 #include "version.h"
40
41 /*
42 * MACROS & DEFINES
43 */
44 #define WINTRANS_PLUGIN_ID "gtk-win-trans"
45
46 #define blist (gaim_get_blist() \
47 ? (GAIM_GTK_BLIST(gaim_get_blist()) \
48 ? ((GAIM_GTK_BLIST(gaim_get_blist()))->window) \
49 : NULL) \
50 : NULL)
51
52 /*
53 * DATA STRUCTS
54 */
55 typedef struct {
56 GtkWidget *win;
57 GtkWidget *slider;
58 } slider_win;
59
60 /*
61 * LOCALS
62 */
63 static const char *OPT_WINTRANS_IM_ENABLED= "/plugins/gtk/win32/wintrans/im_enabled";
64 static const char *OPT_WINTRANS_IM_ALPHA = "/plugins/gtk/win32/wintrans/im_alpha";
65 static const char *OPT_WINTRANS_IM_SLIDER = "/plugins/gtk/win32/wintrans/im_slider";
66 static const char *OPT_WINTRANS_IM_ONFOCUS= "/plugins/gtk/win32/wintrans/im_solid_onfocus";
67 static const char *OPT_WINTRANS_IM_ONTOP = "/plugins/gtk/win32/wintrans/im_always_on_top";
68 static const char *OPT_WINTRANS_BL_ENABLED= "/plugins/gtk/win32/wintrans/bl_enabled";
69 static const char *OPT_WINTRANS_BL_ALPHA = "/plugins/gtk/win32/wintrans/bl_alpha";
70 static const char *OPT_WINTRANS_BL_ONFOCUS= "/plugins/gtk/win32/wintrans/bl_solid_onfocus";
71 static const char *OPT_WINTRANS_BL_ONTOP = "/plugins/gtk/win32/wintrans/bl_always_on_top";
72 static GSList *window_list = NULL;
73
74 static BOOL (*MySetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags) = NULL;
75
76 /*
77 * CODE
78 */
79 static GtkWidget *wgaim_button(const char *text, const char *pref, GtkWidget *page) {
80 GtkWidget *button;
81 button = gtk_check_button_new_with_mnemonic(text);
82 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),
83 gaim_prefs_get_bool(pref));
84 gtk_box_pack_start(GTK_BOX(page), button, FALSE, FALSE, 0);
85 gtk_widget_show(button);
86 return button;
87 }
88
89 /* Set window transparency level */
90 static void set_wintrans(GtkWidget *window, int alpha, gboolean enabled,
91 gboolean always_on_top) {
92 if (MySetLayeredWindowAttributes) {
93 HWND hWnd = GDK_WINDOW_HWND(window->window);
94 LONG style = GetWindowLong(hWnd, GWL_EXSTYLE);
95 if (enabled) {
96 style |= WS_EX_LAYERED;
97 } else {
98 style &= ~WS_EX_LAYERED;
99 }
100 SetWindowLong(hWnd, GWL_EXSTYLE, style);
101
102
103 if (enabled) {
104 SetWindowPos(hWnd,
105 always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST,
106 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
107 MySetLayeredWindowAttributes(hWnd, 0, alpha, LWA_ALPHA);
108 } else {
109 /* Ask the window and its children to repaint */
110 SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
111 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
112
113 RedrawWindow(hWnd, NULL, NULL,
114 RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
115 }
116 }
117 }
118
119 /* When a conv window is focused, if we're only transparent when unfocused,
120 * deal with transparency */
121 static gboolean focus_conv_win_cb(GtkWidget *w, GdkEventFocus *e, gpointer d) {
122 if (gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED)
123 && gaim_prefs_get_bool(OPT_WINTRANS_IM_ONFOCUS)) {
124 GtkWidget *window = (GtkWidget *) d;
125 if (e->in) { /* Focused */
126 set_wintrans(window, 0, FALSE,
127 gaim_prefs_get_bool(OPT_WINTRANS_IM_ONTOP));
128 } else {
129 set_wintrans(window,
130 gaim_prefs_get_int(OPT_WINTRANS_IM_ALPHA),
131 TRUE,
132 gaim_prefs_get_bool(OPT_WINTRANS_IM_ONTOP));
133 }
134 }
135 return FALSE;
136 }
137
138 /* When buddy list window is focused,
139 * if we're only transparent when unfocused, deal with transparency */
140 static gboolean focus_blist_win_cb(GtkWidget *w, GdkEventFocus *e, gpointer d) {
141 if (gaim_prefs_get_bool(OPT_WINTRANS_BL_ENABLED)
142 && gaim_prefs_get_bool(OPT_WINTRANS_BL_ONFOCUS)) {
143 GtkWidget *window = (GtkWidget *) d;
144 if (e->in) { /* Focused */
145 set_wintrans(window, 0, FALSE,
146 gaim_prefs_get_bool(OPT_WINTRANS_BL_ONTOP));
147 } else {
148 set_wintrans(window,
149 gaim_prefs_get_int(OPT_WINTRANS_BL_ALPHA),
150 TRUE,
151 gaim_prefs_get_bool(OPT_WINTRANS_BL_ONTOP));
152 }
153 }
154 return FALSE;
155 }
156
157 static void change_alpha(GtkWidget *w, gpointer data) {
158 int alpha = gtk_range_get_value(GTK_RANGE(w));
159 gaim_prefs_set_int(OPT_WINTRANS_IM_ALPHA, alpha);
160
161 /* If we're in no-transparency on focus mode,
162 * don't take effect immediately */
163 if (!gaim_prefs_get_bool(OPT_WINTRANS_IM_ONFOCUS))
164 set_wintrans(GTK_WIDGET(data), alpha, TRUE,
165 gaim_prefs_get_bool(OPT_WINTRANS_IM_ONTOP));
166 }
167
168
169 static GtkWidget *wintrans_slider(GtkWidget *win) {
170 GtkWidget *hbox;
171 GtkWidget *label, *slider;
172 GtkWidget *frame;
173
174 int imalpha = gaim_prefs_get_int(OPT_WINTRANS_IM_ALPHA);
175
176 frame = gtk_frame_new(NULL);
177 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE);
178 gtk_widget_show(frame);
179
180 hbox = gtk_hbox_new(FALSE, 5);
181 gtk_container_add(GTK_CONTAINER(frame), hbox);
182
183 label = gtk_label_new(_("Opacity:"));
184 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
185 gtk_widget_show(hbox);
186
187 slider = gtk_hscale_new_with_range(50, 255, 1);
188 gtk_range_set_value(GTK_RANGE(slider), imalpha);
189 gtk_widget_set_usize(GTK_WIDGET(slider), 200, -1);
190
191 /* On slider val change, update window's transparency level */
192 g_signal_connect(GTK_OBJECT(slider), "value-changed",
193 GTK_SIGNAL_FUNC(change_alpha), win);
194
195 gtk_box_pack_start(GTK_BOX(hbox), slider, FALSE, TRUE, 5);
196
197 /* Set the initial transparency level */
198 set_wintrans(win, imalpha, TRUE,
199 gaim_prefs_get_bool(OPT_WINTRANS_IM_ONTOP));
200
201 gtk_widget_show_all(hbox);
202
203 return frame;
204 }
205
206 static slider_win* find_slidwin(GtkWidget *win) {
207 GSList *tmp = window_list;
208
209 while (tmp) {
210 if (((slider_win*) (tmp->data))->win == win)
211 return (slider_win*) tmp->data;
212 tmp = tmp->next;
213 }
214 return NULL;
215 }
216
217 /* Clean up transparency stuff for the conv window */
218 static void cleanup_conv_window(GaimGtkWindow *win) {
219 GtkWidget *window = win->window;
220 slider_win *slidwin = NULL;
221
222 /* Remove window from the window list */
223 gaim_debug_info(WINTRANS_PLUGIN_ID,
224 "Conv window destroyed... removing from list\n");
225
226 if ((slidwin = find_slidwin(window))) {
227 window_list = g_slist_remove(window_list, slidwin);
228 g_free(slidwin);
229 }
230
231 /* Remove the focus cbs */
232 g_signal_handlers_disconnect_by_func(G_OBJECT(window),
233 G_CALLBACK(focus_conv_win_cb), window);
234 }
235
236 static void gaim_conversation_delete(GaimConversation *conv) {
237 GaimGtkWindow *win = gaim_gtkconv_get_window(GAIM_GTK_CONVERSATION(conv));
238 /* If it is the last conversation in the window, cleanup */
239 if (gaim_gtk_conv_window_get_gtkconv_count(win) == 1)
240 cleanup_conv_window(win);
241 }
242
243 static void set_blist_trans(GtkWidget *w, const char *pref) {
244 gboolean enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
245 gaim_prefs_set_bool(pref, enabled);
246 if (blist) {
247 set_wintrans(blist, gaim_prefs_get_int(OPT_WINTRANS_BL_ALPHA),
248 gaim_prefs_get_bool(OPT_WINTRANS_BL_ENABLED),
249 gaim_prefs_get_bool(OPT_WINTRANS_IM_ONTOP));
250 }
251 }
252
253 static void add_slider(GtkWidget *win) {
254 GList *wl, *wl1;
255 GtkWidget *vbox = NULL;
256
257 /* Look up this window to see if it already has a slider */
258 if (!find_slidwin(win)) {
259 GtkWidget *slider_box = NULL;
260 slider_win *slidwin = NULL;
261 GtkRequisition slidereq;
262 gint width, height;
263
264 /* Get top vbox */
265 for (wl1 = wl = gtk_container_get_children(
266 GTK_CONTAINER(win));
267 wl != NULL;
268 wl = wl->next) {
269 if (GTK_IS_VBOX(GTK_OBJECT(wl->data)))
270 vbox = GTK_WIDGET(wl->data);
271 else {
272 gaim_debug_error(WINTRANS_PLUGIN_ID,
273 "no vbox found\n");
274 return;
275 }
276 }
277 g_list_free(wl1);
278
279 slider_box = wintrans_slider(win);
280 /* Figure out how tall the slider wants to be */
281 gtk_widget_size_request(slider_box, &slidereq);
282 gtk_window_get_size(GTK_WINDOW(win), &width, &height);
283 gtk_box_pack_start(GTK_BOX(vbox),
284 slider_box, FALSE, FALSE, 0);
285 /* Make window taller so we don't slowly collapse its message area */
286 gtk_window_resize(GTK_WINDOW(win), width,
287 (height + slidereq.height));
288 /* Add window to list, to track that it has a slider */
289 slidwin = g_new0(slider_win, 1);
290 slidwin->win = win;
291 slidwin->slider = slider_box;
292 window_list = g_slist_append(window_list, slidwin);
293 }
294 }
295
296 static void remove_sliders() {
297 if (window_list) {
298 GSList *tmp = window_list;
299 while (tmp) {
300 slider_win *slidwin = (slider_win*) tmp->data;
301 if (slidwin != NULL &&
302 GTK_IS_WINDOW(slidwin->win)) {
303 GtkRequisition slidereq;
304 gint width, height;
305 /* Figure out how tall the slider was */
306 gtk_widget_size_request(
307 slidwin->slider, &slidereq);
308 gtk_window_get_size(
309 GTK_WINDOW(slidwin->win),
310 &width, &height);
311
312 gtk_widget_destroy(slidwin->slider);
313
314 gtk_window_resize(
315 GTK_WINDOW(slidwin->win),
316 width, (height - slidereq.height));
317 }
318 g_free(slidwin);
319 tmp = tmp->next;
320 }
321 g_slist_free(window_list);
322 window_list = NULL;
323 }
324 }
325
326 /* Remove all transparency related aspects from conversation windows */
327 static void remove_convs_wintrans(gboolean remove_signal) {
328 GList *wins;
329
330 for (wins = gaim_gtk_conv_windows_get_list(); wins; wins = wins->next) {
331 GaimGtkWindow *win = wins->data;
332 GtkWidget *window = win->window;
333
334 if (gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED))
335 set_wintrans(window, 0, FALSE, FALSE);
336
337 /* Remove the focus cbs */
338 if (remove_signal)
339 g_signal_handlers_disconnect_by_func(G_OBJECT(window),
340 G_CALLBACK(focus_conv_win_cb), window);
341 }
342
343 remove_sliders();
344 }
345
346 static void set_conv_window_trans(GaimGtkWindow *oldwin, GaimGtkWindow *newwin) {
347 GtkWidget *win = newwin->window;
348
349 /* check prefs to see if we want trans */
350 if (gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED)) {
351 set_wintrans(win, gaim_prefs_get_int(OPT_WINTRANS_IM_ALPHA),
352 TRUE, gaim_prefs_get_bool(OPT_WINTRANS_IM_ONTOP));
353
354 if (gaim_prefs_get_bool(OPT_WINTRANS_IM_SLIDER)) {
355 add_slider(win);
356 }
357 }
358
359 /* If we're moving from one window to another,
360 * add the focus listeners to the new window if not already there */
361 if (oldwin != NULL && oldwin != newwin) {
362 if (gaim_gtk_conv_window_get_gtkconv_count(newwin) == 0) {
363 g_signal_connect(G_OBJECT(win), "focus_in_event",
364 G_CALLBACK(focus_conv_win_cb), win);
365 g_signal_connect(G_OBJECT(win), "focus_out_event",
366 G_CALLBACK(focus_conv_win_cb), win);
367 }
368
369 /* If we've moved the last conversation, cleanup the window */
370 if (gaim_gtk_conv_window_get_gtkconv_count(oldwin) == 1)
371 cleanup_conv_window(oldwin);
372 }
373 }
374
375 static void update_convs_wintrans(GtkWidget *toggle_btn, const char *pref) {
376 gaim_prefs_set_bool(pref, gtk_toggle_button_get_active(
377 GTK_TOGGLE_BUTTON(toggle_btn)));
378
379 if (gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED)) {
380 GList *wins;
381
382 for (wins = gaim_gtk_conv_windows_get_list(); wins; wins = wins->next) {
383 GaimGtkWindow *win = wins->data;
384 set_conv_window_trans(NULL, win);
385 }
386
387 if (!gaim_prefs_get_bool(OPT_WINTRANS_IM_SLIDER))
388 remove_sliders();
389 }
390 else
391 remove_convs_wintrans(FALSE);
392 }
393
394 static void gaim_new_conversation(GaimConversation *conv) {
395 GaimGtkWindow *win = gaim_gtkconv_get_window(GAIM_GTK_CONVERSATION(conv));
396
397 /* If it is the first conversation in the window,
398 * add the sliders, and set transparency */
399 if (gaim_gtk_conv_window_get_gtkconv_count(win) == 1) {
400 GtkWidget *window = win->window;
401
402 set_conv_window_trans(NULL, win);
403
404 g_signal_connect(G_OBJECT(window), "focus_in_event",
405 G_CALLBACK(focus_conv_win_cb), window);
406 g_signal_connect(G_OBJECT(window), "focus_out_event",
407 G_CALLBACK(focus_conv_win_cb), window);
408 }
409 }
410
411 static void blist_created_cb(GaimBuddyList *gaim_blist, gpointer data) {
412 if (blist) {
413 if (gaim_prefs_get_bool(OPT_WINTRANS_BL_ENABLED)) {
414 set_wintrans(blist,
415 gaim_prefs_get_int(OPT_WINTRANS_BL_ALPHA),
416 TRUE,
417 gaim_prefs_get_bool(OPT_WINTRANS_BL_ONTOP));
418 }
419
420 g_signal_connect(G_OBJECT(blist), "focus_in_event",
421 G_CALLBACK(focus_blist_win_cb), blist);
422 g_signal_connect(G_OBJECT(blist), "focus_out_event",
423 G_CALLBACK(focus_blist_win_cb), blist);
424 }
425 }
426
427 static void alpha_change(GtkWidget *w, gpointer data) {
428 GList *wins;
429 int imalpha = gtk_range_get_value(GTK_RANGE(w));
430
431 for (wins = gaim_gtk_conv_windows_get_list(); wins; wins = wins->next) {
432 GaimGtkWindow *win = wins->data;
433 set_wintrans(win->window, imalpha, TRUE,
434 gaim_prefs_get_bool(OPT_WINTRANS_IM_ONTOP));
435 }
436 }
437
438 static void alpha_pref_set_int (GtkWidget *w, GdkEventFocus *e, const char *pref)
439 {
440 int alpha = gtk_range_get_value(GTK_RANGE(w));
441 gaim_prefs_set_int(pref, alpha);
442 }
443
444 static void bl_alpha_change(GtkWidget *w, gpointer data) {
445 if (blist)
446 change_alpha(w, blist);
447 }
448
449 static void update_existing_convs() {
450 GList *wins;
451
452 for (wins = gaim_gtk_conv_windows_get_list(); wins; wins = wins->next) {
453 GaimGtkWindow *win = wins->data;
454 GtkWidget *window = win->window;
455
456 set_conv_window_trans(NULL, win);
457
458 g_signal_connect(G_OBJECT(window), "focus_in_event",
459 G_CALLBACK(focus_conv_win_cb), window);
460 g_signal_connect(G_OBJECT(window), "focus_out_event",
461 G_CALLBACK(focus_conv_win_cb), window);
462 }
463 }
464
465 /*
466 * EXPORTED FUNCTIONS
467 */
468 static gboolean plugin_load(GaimPlugin *plugin) {
469 MySetLayeredWindowAttributes = (void*) wgaim_find_and_loadproc(
470 "user32.dll", "SetLayeredWindowAttributes");
471
472 if (!MySetLayeredWindowAttributes) {
473 gaim_debug_error(WINTRANS_PLUGIN_ID,
474 "SetLayeredWindowAttributes API not found (Required W2K+)\n");
475 return FALSE;
476 }
477
478 gaim_signal_connect(gaim_conversations_get_handle(),
479 "conversation-created", plugin,
480 GAIM_CALLBACK(gaim_new_conversation), NULL);
481
482 /* Set callback to remove window from the list, if the window is destroyed */
483 gaim_signal_connect(gaim_conversations_get_handle(),
484 "deleting-conversation", plugin,
485 GAIM_CALLBACK(gaim_conversation_delete), NULL);
486
487 gaim_signal_connect(gaim_gtk_conversations_get_handle(),
488 "conversation-dragging", plugin,
489 GAIM_CALLBACK(set_conv_window_trans), NULL);
490
491 update_existing_convs();
492
493 if (blist)
494 blist_created_cb(NULL, NULL);
495 else
496 gaim_signal_connect(gaim_gtk_blist_get_handle(),
497 "gtkblist-created", plugin,
498 GAIM_CALLBACK(blist_created_cb), NULL);
499
500
501 return TRUE;
502 }
503
504 static gboolean plugin_unload(GaimPlugin *plugin) {
505 gaim_debug_info(WINTRANS_PLUGIN_ID, "Unloading win2ktrans plugin\n");
506
507 remove_convs_wintrans(TRUE);
508
509 if (blist) {
510 if (gaim_prefs_get_bool(OPT_WINTRANS_BL_ENABLED))
511 set_wintrans(blist, 0, FALSE, FALSE);
512
513 /* Remove the focus cbs */
514 g_signal_handlers_disconnect_by_func(G_OBJECT(blist),
515 G_CALLBACK(focus_blist_win_cb), blist);
516 }
517
518 return TRUE;
519 }
520
521 static GtkWidget *get_config_frame(GaimPlugin *plugin) {
522 GtkWidget *ret;
523 GtkWidget *imtransbox, *bltransbox;
524 GtkWidget *hbox;
525 GtkWidget *label, *slider;
526 GtkWidget *button;
527 GtkWidget *trans_box;
528
529 ret = gtk_vbox_new(FALSE, 18);
530 gtk_container_set_border_width(GTK_CONTAINER (ret), 12);
531
532 /* IM Convo trans options */
533 imtransbox = gaim_gtk_make_frame(ret, _("IM Conversation Windows"));
534 button = wgaim_button(_("_IM window transparency"),
535 OPT_WINTRANS_IM_ENABLED, imtransbox);
536 g_signal_connect(GTK_OBJECT(button), "clicked",
537 GTK_SIGNAL_FUNC(update_convs_wintrans),
538 (gpointer) OPT_WINTRANS_IM_ENABLED);
539
540 trans_box = gtk_vbox_new(FALSE, 18);
541 if (!gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED))
542 gtk_widget_set_sensitive(GTK_WIDGET(trans_box), FALSE);
543 gtk_widget_show(trans_box);
544
545 g_signal_connect(GTK_OBJECT(button), "clicked",
546 GTK_SIGNAL_FUNC(gaim_gtk_toggle_sensitive), trans_box);
547
548 button = wgaim_button(_("_Show slider bar in IM window"),
549 OPT_WINTRANS_IM_SLIDER, trans_box);
550 g_signal_connect(GTK_OBJECT(button), "clicked",
551 GTK_SIGNAL_FUNC(update_convs_wintrans),
552 (gpointer) OPT_WINTRANS_IM_SLIDER);
553
554 button = gaim_gtk_prefs_checkbox(
555 _("Remove IM window transparency on focus"),
556 OPT_WINTRANS_IM_ONFOCUS, trans_box);
557
558 button = wgaim_button(_("Always on top"), OPT_WINTRANS_IM_ONTOP,
559 trans_box);
560 g_signal_connect(GTK_OBJECT(button), "clicked",
561 GTK_SIGNAL_FUNC(update_convs_wintrans),
562 (gpointer) OPT_WINTRANS_IM_ONTOP);
563
564 gtk_box_pack_start(GTK_BOX(imtransbox), trans_box, FALSE, FALSE, 5);
565
566 /* IM transparency slider */
567 hbox = gtk_hbox_new(FALSE, 5);
568
569 label = gtk_label_new(_("Opacity:"));
570 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
571
572 slider = gtk_hscale_new_with_range(50, 255, 1);
573 gtk_range_set_value(GTK_RANGE(slider),
574 gaim_prefs_get_int(OPT_WINTRANS_IM_ALPHA));
575 gtk_widget_set_usize(GTK_WIDGET(slider), 200, -1);
576
577 g_signal_connect(GTK_OBJECT(slider), "value-changed",
578 GTK_SIGNAL_FUNC(alpha_change), NULL);
579 g_signal_connect(GTK_OBJECT(slider), "focus-out-event",
580 GTK_SIGNAL_FUNC(alpha_pref_set_int),
581 (gpointer) OPT_WINTRANS_IM_ALPHA);
582
583 gtk_box_pack_start(GTK_BOX(hbox), slider, FALSE, TRUE, 5);
584
585 gtk_widget_show_all(hbox);
586
587 gtk_box_pack_start(GTK_BOX(trans_box), hbox, FALSE, FALSE, 5);
588
589 /* Buddy List trans options */
590 bltransbox = gaim_gtk_make_frame (ret, _("Buddy List Window"));
591 button = wgaim_button(_("_Buddy List window transparency"),
592 OPT_WINTRANS_BL_ENABLED, bltransbox);
593 g_signal_connect(GTK_OBJECT(button), "clicked",
594 GTK_SIGNAL_FUNC(set_blist_trans),
595 (gpointer) OPT_WINTRANS_BL_ENABLED);
596
597 trans_box = gtk_vbox_new(FALSE, 18);
598 if (!gaim_prefs_get_bool(OPT_WINTRANS_BL_ENABLED))
599 gtk_widget_set_sensitive(GTK_WIDGET(trans_box), FALSE);
600 gtk_widget_show(trans_box);
601 g_signal_connect(GTK_OBJECT(button), "clicked",
602 GTK_SIGNAL_FUNC(gaim_gtk_toggle_sensitive), trans_box);
603 button = gaim_gtk_prefs_checkbox(
604 _("Remove Buddy List window transparency on focus"),
605 OPT_WINTRANS_BL_ONFOCUS, trans_box);
606 button = wgaim_button(_("Always on top"), OPT_WINTRANS_BL_ONTOP,
607 trans_box);
608 g_signal_connect(GTK_OBJECT(button), "clicked",
609 GTK_SIGNAL_FUNC(set_blist_trans),
610 (gpointer) OPT_WINTRANS_BL_ONTOP);
611 gtk_box_pack_start(GTK_BOX(bltransbox), trans_box, FALSE, FALSE, 5);
612
613 /* IM transparency slider */
614 hbox = gtk_hbox_new(FALSE, 5);
615
616 label = gtk_label_new(_("Opacity:"));
617 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
618
619 slider = gtk_hscale_new_with_range(50, 255, 1);
620 gtk_range_set_value(GTK_RANGE(slider),
621 gaim_prefs_get_int(OPT_WINTRANS_BL_ALPHA));
622
623 gtk_widget_set_usize(GTK_WIDGET(slider), 200, -1);
624
625 g_signal_connect(GTK_OBJECT(slider), "value-changed",
626 GTK_SIGNAL_FUNC(bl_alpha_change), NULL);
627 g_signal_connect(GTK_OBJECT(slider), "focus-out-event",
628 GTK_SIGNAL_FUNC(alpha_pref_set_int),
629 (gpointer) OPT_WINTRANS_BL_ALPHA);
630
631 gtk_box_pack_start(GTK_BOX(hbox), slider, FALSE, TRUE, 5);
632
633 gtk_widget_show_all(hbox);
634
635 gtk_box_pack_start(GTK_BOX(trans_box), hbox, FALSE, FALSE, 5);
636
637 gtk_widget_show_all(ret);
638 return ret;
639 }
640
641 static GaimGtkPluginUiInfo ui_info =
642 {
643 get_config_frame,
644 0 /* page_num (Reserved) */
645 };
646
647 static GaimPluginInfo info =
648 {
649 GAIM_PLUGIN_MAGIC,
650 GAIM_MAJOR_VERSION,
651 GAIM_MINOR_VERSION,
652 GAIM_PLUGIN_STANDARD, /**< type */
653 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */
654 0, /**< flags */
655 NULL, /**< dependencies */
656 GAIM_PRIORITY_DEFAULT, /**< priority */
657 WINTRANS_PLUGIN_ID, /**< id */
658 N_("Transparency"), /**< name */
659 VERSION, /**< version */
660 /** summary */
661 N_("Variable Transparency for the buddy list and conversations."),
662 /** description */
663 N_("This plugin enables variable alpha transparency on conversation windows and the buddy list.\n\n"
664 "* Note: This plugin requires Win2000 or greater."),
665 "Herman Bloggs <hermanator12002@yahoo.com>", /**< author */
666 GAIM_WEBSITE, /**< homepage */
667 plugin_load, /**< load */
668 plugin_unload, /**< unload */
669 NULL, /**< destroy */
670 &ui_info, /**< ui_info */
671 NULL, /**< extra_info */
672 NULL, /**< prefs_info */
673 NULL /**< actions */
674 };
675
676 static void
677 init_plugin(GaimPlugin *plugin)
678 {
679 gaim_prefs_add_none("/plugins/gtk/win32");
680 gaim_prefs_add_none("/plugins/gtk/win32/wintrans");
681 gaim_prefs_add_bool(OPT_WINTRANS_IM_ENABLED, FALSE);
682 gaim_prefs_add_int(OPT_WINTRANS_IM_ALPHA, 255);
683 gaim_prefs_add_bool(OPT_WINTRANS_IM_SLIDER, FALSE);
684 gaim_prefs_add_bool(OPT_WINTRANS_IM_ONFOCUS, FALSE);
685 gaim_prefs_add_bool(OPT_WINTRANS_IM_ONTOP, FALSE);
686 gaim_prefs_add_bool(OPT_WINTRANS_BL_ENABLED, FALSE);
687 gaim_prefs_add_int(OPT_WINTRANS_BL_ALPHA, 255);
688 gaim_prefs_add_bool(OPT_WINTRANS_BL_ONFOCUS, FALSE);
689 gaim_prefs_add_bool(OPT_WINTRANS_BL_ONTOP, FALSE);
690 }
691
692 GAIM_INIT_PLUGIN(wintrans, init_plugin, info)