pidgin/gtkblist.c

changeset 39317
b31b810fe6db
parent 39274
7acdb1d9797c
child 39318
32d87356213b
equal deleted inserted replaced
39298:b6f9f735f68f 39317:b31b810fe6db
244 244
245 /* we handle everything, event should not propogate further */ 245 /* we handle everything, event should not propogate further */
246 return TRUE; 246 return TRUE;
247 } 247 }
248 248
249 static gboolean gtk_blist_configure_cb(GtkWidget *w, GdkEventConfigure *event, gpointer data) 249 static void
250 { 250 gtk_blist_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation,
251 /* unfortunately GdkEventConfigure ignores the window gravity, but * 251 gpointer data)
252 * the only way we have of setting the position doesn't. we have to * 252 {
253 * call get_position because it does pay attention to the gravity. * 253 int new_width;
254 * this is inefficient and I agree it sucks, but it's more likely * 254 int new_height;
255 * to work correctly. - Robot101 */
256 gint x, y;
257
258 /* check for visibility because when we aren't visible, this will *
259 * give us bogus (0,0) coordinates. - xOr */
260 if (gtk_widget_get_visible(w))
261 gtk_window_get_position(GTK_WINDOW(w), &x, &y);
262 else
263 return FALSE; /* carry on normally */
264
265 #ifdef _WIN32
266 /* Workaround for GTK+ bug # 169811 - "configure_event" is fired
267 * when the window is being maximized */
268 if (PIDGIN_WINDOW_MAXIMIZED(w))
269 return FALSE;
270 #endif
271
272 /* don't save if nothing changed */
273 if (x == purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/x") &&
274 y == purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/y") &&
275 event->width == purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/width") &&
276 event->height == purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/height")) {
277
278 return FALSE; /* carry on normally */
279 }
280
281 /* don't save off-screen positioning */
282 if (x + event->width < 0 ||
283 y + event->height < 0 ||
284 x > gdk_screen_width() ||
285 y > gdk_screen_height()) {
286
287 return FALSE; /* carry on normally */
288 }
289 255
290 /* ignore changes when maximized */ 256 /* ignore changes when maximized */
291 if(purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/blist/list_maximized")) 257 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/blist/list_maximized")) {
292 return FALSE; 258 return;
293 259 }
294 /* store the position */ 260
295 purple_prefs_set_int(PIDGIN_PREFS_ROOT "/blist/x", x); 261 gtk_window_get_size(GTK_WINDOW(widget), &new_width, &new_height);
296 purple_prefs_set_int(PIDGIN_PREFS_ROOT "/blist/y", y); 262
297 purple_prefs_set_int(PIDGIN_PREFS_ROOT "/blist/width", event->width); 263 /* store the size */
298 purple_prefs_set_int(PIDGIN_PREFS_ROOT "/blist/height", event->height); 264 purple_prefs_set_int(PIDGIN_PREFS_ROOT "/blist/width", new_width);
299 265 purple_prefs_set_int(PIDGIN_PREFS_ROOT "/blist/height", new_height);
300 /* continue to handle event normally */
301 return FALSE;
302 } 266 }
303 267
304 static void gtk_blist_menu_info_cb(GtkWidget *w, PurpleBuddy *b) 268 static void gtk_blist_menu_info_cb(GtkWidget *w, PurpleBuddy *b)
305 { 269 {
306 PurpleAccount *account = purple_buddy_get_account(b); 270 PurpleAccount *account = purple_buddy_get_account(b);
4462 } 4426 }
4463 4427
4464 return text; 4428 return text;
4465 } 4429 }
4466 4430
4467 static void pidgin_blist_restore_position(void) 4431 static void pidgin_blist_restore_window_state(void)
4468 { 4432 {
4469 int blist_x, blist_y, blist_width, blist_height; 4433 int blist_width, blist_height;
4470 4434
4471 blist_width = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/width"); 4435 blist_width = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/width");
4472 4436
4473 /* if the window exists, is hidden, we're saving positions, and the 4437 /* if the window exists, is hidden, we're saving sizes, and the
4474 * position is sane... */ 4438 * size is sane... */
4475 if (gtkblist && gtkblist->window && 4439 if (gtkblist && gtkblist->window &&
4476 !gtk_widget_get_visible(gtkblist->window) && blist_width != 0) { 4440 !gtk_widget_get_visible(gtkblist->window) && blist_width != 0) {
4477 4441
4478 blist_x = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/x");
4479 blist_y = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/y");
4480 blist_height = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/height"); 4442 blist_height = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/height");
4481 4443
4482 /* ...check position is on screen... */ 4444 gtk_window_set_default_size(GTK_WINDOW(gtkblist->window),
4483 if (blist_x >= gdk_screen_width()) 4445 blist_width, blist_height);
4484 blist_x = gdk_screen_width() - 100;
4485 else if (blist_x + blist_width < 0)
4486 blist_x = 100;
4487
4488 if (blist_y >= gdk_screen_height())
4489 blist_y = gdk_screen_height() - 100;
4490 else if (blist_y + blist_height < 0)
4491 blist_y = 100;
4492
4493 /* ...and move it back. */
4494 gtk_window_move(GTK_WINDOW(gtkblist->window), blist_x, blist_y);
4495 gtk_window_resize(GTK_WINDOW(gtkblist->window), blist_width, blist_height);
4496 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/blist/list_maximized")) 4446 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/blist/list_maximized"))
4497 gtk_window_maximize(GTK_WINDOW(gtkblist->window)); 4447 gtk_window_maximize(GTK_WINDOW(gtkblist->window));
4498 } 4448 }
4499 } 4449 }
4500 4450
5806 gtkblist->main_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); 5756 gtkblist->main_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
5807 gtk_widget_show(gtkblist->main_vbox); 5757 gtk_widget_show(gtkblist->main_vbox);
5808 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->main_vbox); 5758 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->main_vbox);
5809 5759
5810 g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gtk_blist_delete_cb), NULL); 5760 g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gtk_blist_delete_cb), NULL);
5811 g_signal_connect(G_OBJECT(gtkblist->window), "configure_event", G_CALLBACK(gtk_blist_configure_cb), NULL); 5761 g_signal_connect(G_OBJECT(gtkblist->window), "size-allocate",
5762 G_CALLBACK(gtk_blist_size_allocate_cb), NULL);
5812 g_signal_connect(G_OBJECT(gtkblist->window), "visibility_notify_event", G_CALLBACK(gtk_blist_visibility_cb), NULL); 5763 g_signal_connect(G_OBJECT(gtkblist->window), "visibility_notify_event", G_CALLBACK(gtk_blist_visibility_cb), NULL);
5813 g_signal_connect(G_OBJECT(gtkblist->window), "window_state_event", G_CALLBACK(gtk_blist_window_state_cb), NULL); 5764 g_signal_connect(G_OBJECT(gtkblist->window), "window_state_event", G_CALLBACK(gtk_blist_window_state_cb), NULL);
5814 g_signal_connect(G_OBJECT(gtkblist->window), "key_press_event", G_CALLBACK(gtk_blist_window_key_press_cb), gtkblist); 5765 g_signal_connect(G_OBJECT(gtkblist->window), "key_press_event", G_CALLBACK(gtk_blist_window_key_press_cb), gtkblist);
5815 gtk_widget_add_events(gtkblist->window, GDK_VISIBILITY_NOTIFY_MASK); 5766 gtk_widget_add_events(gtkblist->window, GDK_VISIBILITY_NOTIFY_MASK);
5816 5767
6049 pidgin_blist_update_plugin_actions(); 6000 pidgin_blist_update_plugin_actions();
6050 pidgin_blist_update_sort_methods(); 6001 pidgin_blist_update_sort_methods();
6051 6002
6052 /* OK... let's show this bad boy. */ 6003 /* OK... let's show this bad boy. */
6053 pidgin_blist_refresh(list); 6004 pidgin_blist_refresh(list);
6054 pidgin_blist_restore_position(); 6005 pidgin_blist_restore_window_state();
6055 gtk_widget_show_all(GTK_WIDGET(gtkblist->vbox)); 6006 gtk_widget_show_all(GTK_WIDGET(gtkblist->vbox));
6056 gtk_widget_realize(GTK_WIDGET(gtkblist->window)); 6007 gtk_widget_realize(GTK_WIDGET(gtkblist->window));
6057 purple_blist_set_visible(purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/blist/list_visible")); 6008 purple_blist_set_visible(purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/blist/list_visible"));
6058 6009
6059 /* start the refresh timer */ 6010 /* start the refresh timer */
6936 6887
6937 if (show) { 6888 if (show) {
6938 if(!PIDGIN_WINDOW_ICONIFIED(gtkblist->window) && 6889 if(!PIDGIN_WINDOW_ICONIFIED(gtkblist->window) &&
6939 !gtk_widget_get_visible(gtkblist->window)) 6890 !gtk_widget_get_visible(gtkblist->window))
6940 purple_signal_emit(pidgin_blist_get_handle(), "gtkblist-unhiding", gtkblist); 6891 purple_signal_emit(pidgin_blist_get_handle(), "gtkblist-unhiding", gtkblist);
6941 pidgin_blist_restore_position();
6942 gtk_window_present(GTK_WINDOW(gtkblist->window)); 6892 gtk_window_present(GTK_WINDOW(gtkblist->window));
6943 } else { 6893 } else {
6944 if(visibility_manager_count) { 6894 if(visibility_manager_count) {
6945 purple_signal_emit(pidgin_blist_get_handle(), "gtkblist-hiding", gtkblist); 6895 purple_signal_emit(pidgin_blist_get_handle(), "gtkblist-hiding", gtkblist);
6946 gtk_widget_hide(gtkblist->window); 6896 gtk_widget_hide(gtkblist->window);
7565 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/blist/show_offline_buddies", FALSE); 7515 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/blist/show_offline_buddies", FALSE);
7566 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/blist/show_protocol_icons", FALSE); 7516 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/blist/show_protocol_icons", FALSE);
7567 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/blist/list_visible", FALSE); 7517 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/blist/list_visible", FALSE);
7568 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/blist/list_maximized", FALSE); 7518 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/blist/list_maximized", FALSE);
7569 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/blist/sort_type", "alphabetical"); 7519 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/blist/sort_type", "alphabetical");
7570 purple_prefs_add_int(PIDGIN_PREFS_ROOT "/blist/x", 0);
7571 purple_prefs_add_int(PIDGIN_PREFS_ROOT "/blist/y", 0);
7572 purple_prefs_add_int(PIDGIN_PREFS_ROOT "/blist/width", 250); /* Golden ratio, baby */ 7520 purple_prefs_add_int(PIDGIN_PREFS_ROOT "/blist/width", 250); /* Golden ratio, baby */
7573 purple_prefs_add_int(PIDGIN_PREFS_ROOT "/blist/height", 405); /* Golden ratio, baby */ 7521 purple_prefs_add_int(PIDGIN_PREFS_ROOT "/blist/height", 405); /* Golden ratio, baby */
7574 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/blist/theme", ""); 7522 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/blist/theme", "");
7575 7523
7576 purple_theme_manager_register_type(g_object_new(PIDGIN_TYPE_BLIST_THEME_LOADER, "type", "blist", NULL)); 7524 purple_theme_manager_register_type(g_object_new(PIDGIN_TYPE_BLIST_THEME_LOADER, "type", "blist", NULL));

mercurial