Sat, 19 May 2007 21:38:47 +0000
merge of '1442df274a24edc9a31194327bd00dfbcf478720'
and 'ce02548a6b6a545d97fb3f371506bcf1b5cc5131'
| 14286 | 1 | /* |
| 15884 | 2 | * purple - Transparency plugin |
| 14286 | 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 | ||
| 15884 | 46 | #define blist (purple_get_blist() \ |
| 47 | ? (PIDGIN_BLIST(purple_get_blist()) \ | |
| 48 | ? ((PIDGIN_BLIST(purple_get_blist()))->window) \ | |
| 14286 | 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 | */ | |
| 15884 | 79 | static GtkWidget *wpurple_button(const char *text, const char *pref, GtkWidget *page) { |
| 14286 | 80 | GtkWidget *button; |
| 81 | button = gtk_check_button_new_with_mnemonic(text); | |
| 82 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), | |
| 15884 | 83 | purple_prefs_get_bool(pref)); |
| 14286 | 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) { | |
| 15884 | 122 | if (purple_prefs_get_bool(OPT_WINTRANS_IM_ENABLED) |
| 123 | && purple_prefs_get_bool(OPT_WINTRANS_IM_ONFOCUS)) { | |
| 14286 | 124 | GtkWidget *window = (GtkWidget *) d; |
| 125 | if (e->in) { /* Focused */ | |
| 126 | set_wintrans(window, 0, FALSE, | |
| 15884 | 127 | purple_prefs_get_bool(OPT_WINTRANS_IM_ONTOP)); |
| 14286 | 128 | } else { |
| 129 | set_wintrans(window, | |
| 15884 | 130 | purple_prefs_get_int(OPT_WINTRANS_IM_ALPHA), |
| 14286 | 131 | TRUE, |
| 15884 | 132 | purple_prefs_get_bool(OPT_WINTRANS_IM_ONTOP)); |
| 14286 | 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) { | |
| 15884 | 141 | if (purple_prefs_get_bool(OPT_WINTRANS_BL_ENABLED) |
| 142 | && purple_prefs_get_bool(OPT_WINTRANS_BL_ONFOCUS)) { | |
| 14286 | 143 | GtkWidget *window = (GtkWidget *) d; |
| 144 | if (e->in) { /* Focused */ | |
| 145 | set_wintrans(window, 0, FALSE, | |
| 15884 | 146 | purple_prefs_get_bool(OPT_WINTRANS_BL_ONTOP)); |
| 14286 | 147 | } else { |
| 148 | set_wintrans(window, | |
| 15884 | 149 | purple_prefs_get_int(OPT_WINTRANS_BL_ALPHA), |
| 14286 | 150 | TRUE, |
| 15884 | 151 | purple_prefs_get_bool(OPT_WINTRANS_BL_ONTOP)); |
| 14286 | 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)); | |
| 15884 | 159 | purple_prefs_set_int(OPT_WINTRANS_IM_ALPHA, alpha); |
| 14286 | 160 | |
| 161 | /* If we're in no-transparency on focus mode, | |
| 162 | * don't take effect immediately */ | |
| 15884 | 163 | if (!purple_prefs_get_bool(OPT_WINTRANS_IM_ONFOCUS)) |
| 14286 | 164 | set_wintrans(GTK_WIDGET(data), alpha, TRUE, |
| 15884 | 165 | purple_prefs_get_bool(OPT_WINTRANS_IM_ONTOP)); |
| 14286 | 166 | } |
| 167 | ||
| 168 | ||
| 169 | static GtkWidget *wintrans_slider(GtkWidget *win) { | |
| 170 | GtkWidget *hbox; | |
| 171 | GtkWidget *label, *slider; | |
| 172 | GtkWidget *frame; | |
| 173 | ||
| 15884 | 174 | int imalpha = purple_prefs_get_int(OPT_WINTRANS_IM_ALPHA); |
| 14286 | 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, | |
| 15884 | 199 | purple_prefs_get_bool(OPT_WINTRANS_IM_ONTOP)); |
| 14286 | 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 */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
218 | static void cleanup_conv_window(PidginWindow *win) { |
| 14286 | 219 | GtkWidget *window = win->window; |
| 220 | slider_win *slidwin = NULL; | |
| 221 | ||
| 222 | /* Remove window from the window list */ | |
| 15884 | 223 | purple_debug_info(WINTRANS_PLUGIN_ID, |
| 14286 | 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 | ||
| 15884 | 236 | static void purple_conversation_delete(PurpleConversation *conv) { |
| 15563 | 237 | PidginWindow *win = pidgin_conv_get_window(PIDGIN_CONVERSATION(conv)); |
| 14286 | 238 | /* If it is the last conversation in the window, cleanup */ |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
239 | if (pidgin_conv_window_get_gtkconv_count(win) == 1) |
| 14286 | 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)); | |
| 15884 | 245 | purple_prefs_set_bool(pref, enabled); |
| 14286 | 246 | if (blist) { |
| 15884 | 247 | set_wintrans(blist, purple_prefs_get_int(OPT_WINTRANS_BL_ALPHA), |
| 248 | purple_prefs_get_bool(OPT_WINTRANS_BL_ENABLED), | |
| 249 | purple_prefs_get_bool(OPT_WINTRANS_IM_ONTOP)); | |
| 14286 | 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 { | |
| 15884 | 272 | purple_debug_error(WINTRANS_PLUGIN_ID, |
| 14286 | 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 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
330 | for (wins = pidgin_conv_windows_get_list(); wins; wins = wins->next) { |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
331 | PidginWindow *win = wins->data; |
| 14286 | 332 | GtkWidget *window = win->window; |
| 333 | ||
| 15884 | 334 | if (purple_prefs_get_bool(OPT_WINTRANS_IM_ENABLED)) |
| 14286 | 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 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
346 | static void set_conv_window_trans(PidginWindow *oldwin, PidginWindow *newwin) { |
| 14286 | 347 | GtkWidget *win = newwin->window; |
| 348 | ||
| 349 | /* check prefs to see if we want trans */ | |
| 15884 | 350 | if (purple_prefs_get_bool(OPT_WINTRANS_IM_ENABLED)) { |
| 351 | set_wintrans(win, purple_prefs_get_int(OPT_WINTRANS_IM_ALPHA), | |
| 352 | TRUE, purple_prefs_get_bool(OPT_WINTRANS_IM_ONTOP)); | |
| 14286 | 353 | |
| 15884 | 354 | if (purple_prefs_get_bool(OPT_WINTRANS_IM_SLIDER)) { |
| 14286 | 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) { | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
362 | if (pidgin_conv_window_get_gtkconv_count(newwin) == 0) { |
| 14286 | 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 */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
370 | if (pidgin_conv_window_get_gtkconv_count(oldwin) == 1) |
| 14286 | 371 | cleanup_conv_window(oldwin); |
| 372 | } | |
| 373 | } | |
| 374 | ||
| 375 | static void update_convs_wintrans(GtkWidget *toggle_btn, const char *pref) { | |
| 15884 | 376 | purple_prefs_set_bool(pref, gtk_toggle_button_get_active( |
| 14286 | 377 | GTK_TOGGLE_BUTTON(toggle_btn))); |
| 378 | ||
| 15884 | 379 | if (purple_prefs_get_bool(OPT_WINTRANS_IM_ENABLED)) { |
| 14286 | 380 | GList *wins; |
| 381 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
382 | for (wins = pidgin_conv_windows_get_list(); wins; wins = wins->next) { |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
383 | PidginWindow *win = wins->data; |
| 14286 | 384 | set_conv_window_trans(NULL, win); |
| 385 | } | |
| 386 | ||
| 15884 | 387 | if (!purple_prefs_get_bool(OPT_WINTRANS_IM_SLIDER)) |
| 14286 | 388 | remove_sliders(); |
| 389 | } | |
| 390 | else | |
| 391 | remove_convs_wintrans(FALSE); | |
| 392 | } | |
| 393 | ||
| 15884 | 394 | static void purple_new_conversation(PurpleConversation *conv) { |
| 15563 | 395 | PidginWindow *win = pidgin_conv_get_window(PIDGIN_CONVERSATION(conv)); |
| 14286 | 396 | |
| 397 | /* If it is the first conversation in the window, | |
| 398 | * add the sliders, and set transparency */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
399 | if (pidgin_conv_window_get_gtkconv_count(win) == 1) { |
| 14286 | 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 | ||
| 15884 | 411 | static void blist_created_cb(PurpleBuddyList *purple_blist, gpointer data) { |
| 14286 | 412 | if (blist) { |
| 15884 | 413 | if (purple_prefs_get_bool(OPT_WINTRANS_BL_ENABLED)) { |
| 14286 | 414 | set_wintrans(blist, |
| 15884 | 415 | purple_prefs_get_int(OPT_WINTRANS_BL_ALPHA), |
| 14286 | 416 | TRUE, |
| 15884 | 417 | purple_prefs_get_bool(OPT_WINTRANS_BL_ONTOP)); |
| 14286 | 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 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
431 | for (wins = pidgin_conv_windows_get_list(); wins; wins = wins->next) { |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
432 | PidginWindow *win = wins->data; |
| 14286 | 433 | set_wintrans(win->window, imalpha, TRUE, |
| 15884 | 434 | purple_prefs_get_bool(OPT_WINTRANS_IM_ONTOP)); |
| 14286 | 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)); | |
| 15884 | 441 | purple_prefs_set_int(pref, alpha); |
| 14286 | 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 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
452 | for (wins = pidgin_conv_windows_get_list(); wins; wins = wins->next) { |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
453 | PidginWindow *win = wins->data; |
| 14286 | 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 | */ | |
| 15884 | 468 | static gboolean plugin_load(PurplePlugin *plugin) { |
| 469 | MySetLayeredWindowAttributes = (void*) wpurple_find_and_loadproc( | |
| 14286 | 470 | "user32.dll", "SetLayeredWindowAttributes"); |
| 471 | ||
| 472 | if (!MySetLayeredWindowAttributes) { | |
| 15884 | 473 | purple_debug_error(WINTRANS_PLUGIN_ID, |
| 14286 | 474 | "SetLayeredWindowAttributes API not found (Required W2K+)\n"); |
| 475 | return FALSE; | |
| 476 | } | |
| 477 | ||
| 15884 | 478 | purple_signal_connect(purple_conversations_get_handle(), |
| 14286 | 479 | "conversation-created", plugin, |
| 15884 | 480 | PURPLE_CALLBACK(purple_new_conversation), NULL); |
| 14286 | 481 | |
| 482 | /* Set callback to remove window from the list, if the window is destroyed */ | |
| 15884 | 483 | purple_signal_connect(purple_conversations_get_handle(), |
| 14286 | 484 | "deleting-conversation", plugin, |
| 15884 | 485 | PURPLE_CALLBACK(purple_conversation_delete), NULL); |
| 14286 | 486 | |
| 15884 | 487 | purple_signal_connect(pidgin_conversations_get_handle(), |
| 14286 | 488 | "conversation-dragging", plugin, |
| 15884 | 489 | PURPLE_CALLBACK(set_conv_window_trans), NULL); |
| 14286 | 490 | |
| 491 | update_existing_convs(); | |
| 492 | ||
| 493 | if (blist) | |
| 494 | blist_created_cb(NULL, NULL); | |
| 495 | else | |
| 15884 | 496 | purple_signal_connect(pidgin_blist_get_handle(), |
| 14286 | 497 | "gtkblist-created", plugin, |
| 15884 | 498 | PURPLE_CALLBACK(blist_created_cb), NULL); |
| 14286 | 499 | |
| 500 | ||
| 501 | return TRUE; | |
| 502 | } | |
| 503 | ||
| 15884 | 504 | static gboolean plugin_unload(PurplePlugin *plugin) { |
| 505 | purple_debug_info(WINTRANS_PLUGIN_ID, "Unloading win2ktrans plugin\n"); | |
| 14286 | 506 | |
| 507 | remove_convs_wintrans(TRUE); | |
| 508 | ||
| 509 | if (blist) { | |
| 15884 | 510 | if (purple_prefs_get_bool(OPT_WINTRANS_BL_ENABLED)) |
| 14286 | 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 | ||
| 15884 | 521 | static GtkWidget *get_config_frame(PurplePlugin *plugin) { |
| 14286 | 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 */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
533 | imtransbox = pidgin_make_frame(ret, _("IM Conversation Windows")); |
| 15884 | 534 | button = wpurple_button(_("_IM window transparency"), |
| 14286 | 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); | |
| 15884 | 541 | if (!purple_prefs_get_bool(OPT_WINTRANS_IM_ENABLED)) |
| 14286 | 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", | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
546 | GTK_SIGNAL_FUNC(pidgin_toggle_sensitive), trans_box); |
| 14286 | 547 | |
| 15884 | 548 | button = wpurple_button(_("_Show slider bar in IM window"), |
| 14286 | 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 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
554 | button = pidgin_prefs_checkbox( |
| 14286 | 555 | _("Remove IM window transparency on focus"), |
| 556 | OPT_WINTRANS_IM_ONFOCUS, trans_box); | |
| 557 | ||
| 15884 | 558 | button = wpurple_button(_("Always on top"), OPT_WINTRANS_IM_ONTOP, |
| 14286 | 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), | |
| 15884 | 574 | purple_prefs_get_int(OPT_WINTRANS_IM_ALPHA)); |
| 14286 | 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 */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
590 | bltransbox = pidgin_make_frame (ret, _("Buddy List Window")); |
| 15884 | 591 | button = wpurple_button(_("_Buddy List window transparency"), |
| 14286 | 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); | |
| 15884 | 598 | if (!purple_prefs_get_bool(OPT_WINTRANS_BL_ENABLED)) |
| 14286 | 599 | gtk_widget_set_sensitive(GTK_WIDGET(trans_box), FALSE); |
| 600 | gtk_widget_show(trans_box); | |
| 601 | g_signal_connect(GTK_OBJECT(button), "clicked", | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
602 | GTK_SIGNAL_FUNC(pidgin_toggle_sensitive), trans_box); |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
603 | button = pidgin_prefs_checkbox( |
| 14286 | 604 | _("Remove Buddy List window transparency on focus"), |
| 605 | OPT_WINTRANS_BL_ONFOCUS, trans_box); | |
| 15884 | 606 | button = wpurple_button(_("Always on top"), OPT_WINTRANS_BL_ONTOP, |
| 14286 | 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), | |
| 15884 | 621 | purple_prefs_get_int(OPT_WINTRANS_BL_ALPHA)); |
| 14286 | 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 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
641 | static PidginPluginUiInfo ui_info = |
| 14286 | 642 | { |
| 643 | get_config_frame, | |
|
16751
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
644 | 0, /* page_num (Reserved) */ |
|
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
645 | |
|
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
646 | /* padding */ |
|
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
647 | NULL, |
|
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
648 | NULL, |
|
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
649 | NULL, |
|
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
650 | NULL |
| 14286 | 651 | }; |
| 652 | ||
| 15884 | 653 | static PurplePluginInfo info = |
| 14286 | 654 | { |
| 15884 | 655 | PURPLE_PLUGIN_MAGIC, |
| 656 | PURPLE_MAJOR_VERSION, | |
| 657 | PURPLE_MINOR_VERSION, | |
| 658 | PURPLE_PLUGIN_STANDARD, /**< type */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
659 | PIDGIN_PLUGIN_TYPE, /**< ui_requirement */ |
| 14286 | 660 | 0, /**< flags */ |
| 661 | NULL, /**< dependencies */ | |
| 15884 | 662 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 14286 | 663 | WINTRANS_PLUGIN_ID, /**< id */ |
| 664 | N_("Transparency"), /**< name */ | |
| 665 | VERSION, /**< version */ | |
| 666 | /** summary */ | |
| 667 | N_("Variable Transparency for the buddy list and conversations."), | |
| 668 | /** description */ | |
| 669 | N_("This plugin enables variable alpha transparency on conversation windows and the buddy list.\n\n" | |
| 670 | "* Note: This plugin requires Win2000 or greater."), | |
| 671 | "Herman Bloggs <hermanator12002@yahoo.com>", /**< author */ | |
| 15884 | 672 | PURPLE_WEBSITE, /**< homepage */ |
| 14286 | 673 | plugin_load, /**< load */ |
| 674 | plugin_unload, /**< unload */ | |
| 675 | NULL, /**< destroy */ | |
| 676 | &ui_info, /**< ui_info */ | |
| 677 | NULL, /**< extra_info */ | |
| 678 | NULL, /**< prefs_info */ | |
|
16751
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
679 | NULL, /**< actions */ |
|
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
680 | |
|
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
681 | /* padding */ |
|
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
682 | NULL, |
|
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
683 | NULL, |
|
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
684 | NULL, |
|
8e552dc2ef9f
20:06 < SimGuy> grim: add padding to the two win32 plugins while you're at it :P
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
685 | NULL |
| 14286 | 686 | }; |
| 687 | ||
| 688 | static void | |
| 15884 | 689 | init_plugin(PurplePlugin *plugin) |
| 14286 | 690 | { |
| 15884 | 691 | purple_prefs_add_none("/plugins/gtk/win32"); |
| 692 | purple_prefs_add_none("/plugins/gtk/win32/wintrans"); | |
| 693 | purple_prefs_add_bool(OPT_WINTRANS_IM_ENABLED, FALSE); | |
| 694 | purple_prefs_add_int(OPT_WINTRANS_IM_ALPHA, 255); | |
| 695 | purple_prefs_add_bool(OPT_WINTRANS_IM_SLIDER, FALSE); | |
| 696 | purple_prefs_add_bool(OPT_WINTRANS_IM_ONFOCUS, FALSE); | |
| 697 | purple_prefs_add_bool(OPT_WINTRANS_IM_ONTOP, FALSE); | |
| 698 | purple_prefs_add_bool(OPT_WINTRANS_BL_ENABLED, FALSE); | |
| 699 | purple_prefs_add_int(OPT_WINTRANS_BL_ALPHA, 255); | |
| 700 | purple_prefs_add_bool(OPT_WINTRANS_BL_ONFOCUS, FALSE); | |
| 701 | purple_prefs_add_bool(OPT_WINTRANS_BL_ONTOP, FALSE); | |
| 14286 | 702 | } |
| 703 | ||
| 15884 | 704 | PURPLE_INIT_PLUGIN(wintrans, init_plugin, info) |