connect to GdkDisplayManager and automatically add/remove move-to-screen

2005-11-17  Michael Natterer  <mitch@gimp.org>

	* app/actions/window-actions.[ch]: connect to GdkDisplayManager
	and automatically add/remove move-to-screen actions when
	displays are opened/closed.

	* app/menus/window-menu.c: added similar code here to add/remove
	menu items for the above actions.

	* app/actions/Makefile.am
	* app/actions/window-commands.[ch]: new files containing window
	close and move-to-screen callbacks. There is no need to implement
	these twice for GimpDock and GimpDisplay.

	* app/actions/dock-commands.[ch]
	* app/actions/view-commands.[ch]: remove the callbacks here.

	* app/actions/dock-actions.c
	* app/actions/view-actions.c: changed accordingly.
This commit is contained in:
Michael Natterer 2005-11-17 20:16:07 +00:00 committed by Michael Natterer
parent cf7a31fb57
commit 8b6b8f413e
13 changed files with 405 additions and 168 deletions

View File

@ -1,3 +1,23 @@
2005-11-17 Michael Natterer <mitch@gimp.org>
* app/actions/window-actions.[ch]: connect to GdkDisplayManager
and automatically add/remove move-to-screen actions when
displays are opened/closed.
* app/menus/window-menu.c: added similar code here to add/remove
menu items for the above actions.
* app/actions/Makefile.am
* app/actions/window-commands.[ch]: new files containing window
close and move-to-screen callbacks. There is no need to implement
these twice for GimpDock and GimpDisplay.
* app/actions/dock-commands.[ch]
* app/actions/view-commands.[ch]: remove the callbacks here.
* app/actions/dock-actions.c
* app/actions/view-actions.c: changed accordingly.
2005-11-16 Manish Singh <yosh@gimp.org>
* plug-ins/common/curve_bend.c (p_gimp_rotate): use

View File

@ -150,7 +150,9 @@ libappactions_a_SOURCES = \
view-commands.c \
view-commands.h \
window-actions.c \
window-actions.h
window-actions.h \
window-commands.c \
window-commands.h
EXTRA_DIST = \

View File

@ -32,6 +32,7 @@
#include "dock-actions.h"
#include "dock-commands.h"
#include "window-actions.h"
#include "window-commands.h"
#include "gimp-intl.h"
@ -44,7 +45,7 @@ static GimpActionEntry dock_actions[] =
{ "dock-close", GTK_STOCK_CLOSE,
N_("Close Dock"), "<control>W", NULL,
G_CALLBACK (dock_close_cmd_callback),
G_CALLBACK (window_close_cmd_callback),
GIMP_HELP_DOCK_CLOSE }
};
@ -75,9 +76,7 @@ dock_actions_setup (GimpActionGroup *group)
dock_toggle_actions,
G_N_ELEMENTS (dock_toggle_actions));
window_actions_setup (group,
GIMP_HELP_DOCK_CHANGE_SCREEN,
G_CALLBACK (dock_move_to_screen_cmd_callback));
window_actions_setup (group, GIMP_HELP_DOCK_CHANGE_SCREEN);
}
void

View File

@ -32,55 +32,6 @@
/* public functions */
void
dock_close_cmd_callback (GtkAction *action,
gpointer data)
{
GtkWidget *widget;
return_if_no_widget (widget, data);
if (! GTK_WIDGET_TOPLEVEL (widget))
widget = gtk_widget_get_toplevel (widget);
if (widget && widget->window)
{
GdkEvent *event = gdk_event_new (GDK_DELETE);
event->any.window = g_object_ref (widget->window);
event->any.send_event = TRUE;
gtk_main_do_event (event);
gdk_event_free (event);
}
}
void
dock_move_to_screen_cmd_callback (GtkAction *action,
GtkAction *current,
gpointer data)
{
GtkWidget *widget;
gint value;
return_if_no_widget (widget, data);
if (! GTK_WIDGET_TOPLEVEL (widget))
widget = gtk_widget_get_toplevel (widget);
value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
if (value != gdk_screen_get_number (gtk_widget_get_screen (widget)))
{
GdkDisplay *display;
GdkScreen *screen;
display = gtk_widget_get_display (widget);
screen = gdk_display_get_screen (display, value);
if (screen)
gtk_window_set_screen (GTK_WINDOW (widget), screen);
}
}
void
dock_toggle_image_menu_cmd_callback (GtkAction *action,
gpointer data)

View File

@ -20,12 +20,6 @@
#define __DOCK_COMMANDS_H__
void dock_close_cmd_callback (GtkAction *action,
gpointer data);
void dock_move_to_screen_cmd_callback (GtkAction *action,
GtkAction *current,
gpointer data);
void dock_toggle_image_menu_cmd_callback (GtkAction *action,
gpointer data);
void dock_toggle_auto_cmd_callback (GtkAction *action,

View File

@ -46,6 +46,7 @@
#include "view-actions.h"
#include "view-commands.h"
#include "window-actions.h"
#include "window-commands.h"
#include "gimp-intl.h"
@ -75,7 +76,7 @@ static GimpActionEntry view_actions[] =
{ "view-close", GTK_STOCK_CLOSE,
N_( "_Close"), "<control>W", NULL,
G_CALLBACK (view_close_cmd_callback),
G_CALLBACK (window_close_cmd_callback),
GIMP_HELP_FILE_CLOSE },
{ "view-zoom-fit-in", GTK_STOCK_ZOOM_FIT,
@ -451,9 +452,7 @@ view_actions_setup (GimpActionGroup *group)
G_N_ELEMENTS (view_scroll_vertical_actions),
G_CALLBACK (view_scroll_vertical_cmd_callback));
window_actions_setup (group,
GIMP_HELP_VIEW_CHANGE_SCREEN,
G_CALLBACK (view_move_to_screen_cmd_callback));
window_actions_setup (group, GIMP_HELP_VIEW_CHANGE_SCREEN);
/* connect "activate" of view-zoom-other manually so it can be
* selected even if it's the active item of the radio group

View File

@ -88,16 +88,6 @@ view_new_cmd_callback (GtkAction *action,
shell->unit, gimp_zoom_model_get_factor (shell->zoom));
}
void
view_close_cmd_callback (GtkAction *action,
gpointer data)
{
GimpDisplay *gdisp;
return_if_no_display (gdisp, data);
gimp_display_shell_close (GIMP_DISPLAY_SHELL (gdisp->shell), FALSE);
}
void
view_zoom_fit_in_cmd_callback (GtkAction *action,
gpointer data)
@ -647,30 +637,6 @@ view_fullscreen_cmd_callback (GtkAction *action,
gimp_display_shell_set_fullscreen (shell, active);
}
void
view_move_to_screen_cmd_callback (GtkAction *action,
GtkAction *current,
gpointer data)
{
GimpDisplay *gdisp;
gint value;
return_if_no_display (gdisp, data);
value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
if (value != gdk_screen_get_number (gtk_widget_get_screen (gdisp->shell)))
{
GdkDisplay *display;
GdkScreen *screen;
display = gtk_widget_get_display (gdisp->shell);
screen = gdk_display_get_screen (display, value);
if (screen)
gtk_window_set_screen (GTK_WINDOW (gdisp->shell), screen);
}
}
/* private functions */

View File

@ -22,8 +22,6 @@
void view_new_cmd_callback (GtkAction *action,
gpointer data);
void view_close_cmd_callback (GtkAction *action,
gpointer data);
void view_zoom_fit_in_cmd_callback (GtkAction *action,
gpointer data);
@ -86,9 +84,6 @@ void view_shrink_wrap_cmd_callback (GtkAction *action,
gpointer data);
void view_fullscreen_cmd_callback (GtkAction *action,
gpointer data);
void view_move_to_screen_cmd_callback (GtkAction *action,
GtkAction *current,
gpointer data);
#endif /* __VIEW_COMMANDS_H__ */

View File

@ -29,59 +29,50 @@
#include "actions.h"
#include "window-actions.h"
#include "window-commands.h"
#include "gimp-intl.h"
/* private functions */
static void window_actions_display_opened (GdkDisplayManager *manager,
GdkDisplay *display,
GimpActionGroup *group);
static void window_actions_display_closed (GdkDisplay *display,
gboolean is_error,
GimpActionGroup *group);
/* public functions */
void
window_actions_setup (GimpActionGroup *group,
const gchar *move_to_screen_help_id,
GCallback move_to_screen_callback)
const gchar *move_to_screen_help_id)
{
GdkDisplay *display;
GimpRadioActionEntry *entries;
const gchar *group_name;
gint n_entries;
gint i;
GdkDisplayManager *manager = gdk_display_manager_get ();
GSList *displays;
GSList *list;
display = gdk_display_get_default ();
n_entries = gdk_display_get_n_screens (display);
g_object_set_data_full (G_OBJECT (group), "move-to-screen-help-id",
g_strdup (move_to_screen_help_id),
(GDestroyNotify) g_free);
group_name = gtk_action_group_get_name (GTK_ACTION_GROUP (group));
displays = gdk_display_manager_list_displays (manager);
entries = g_new0 (GimpRadioActionEntry, n_entries);
/* present displays in the order in which they were opened */
displays = g_slist_reverse (displays);
for (i = 0; i < n_entries; i++)
for (list = displays; list; list = g_slist_next (list))
{
GdkScreen *screen;
gchar *screen_name;
screen = gdk_display_get_screen (display, i);
screen_name = gdk_screen_make_display_name (screen);
entries[i].name = g_strdup_printf ("%s-move-to-screen-%02d",
group_name, i);
entries[i].stock_id = GIMP_STOCK_MOVE_TO_SCREEN;
entries[i].label = g_strdup_printf (_("Screen %d (%s)"),
i, screen_name);
entries[i].accelerator = NULL;
entries[i].tooltip = NULL;
entries[i].value = i;
entries[i].help_id = move_to_screen_help_id;
g_free (screen_name);
window_actions_display_opened (manager, list->data, group);
}
gimp_action_group_add_radio_actions (group, entries, n_entries, NULL, 0,
G_CALLBACK (move_to_screen_callback));
g_slist_free (displays);
for (i = 0; i < n_entries; i++)
{
g_free ((gchar *) entries[i].name);
g_free ((gchar *) entries[i].label);
}
g_free (entries);
g_signal_connect_object (manager, "display-opened",
G_CALLBACK (window_actions_display_opened),
G_OBJECT (group), 0);
}
void
@ -89,7 +80,7 @@ window_actions_update (GimpActionGroup *group,
GtkWidget *window)
{
const gchar *group_name;
gint n_screens = 1;
gint show_menu = FALSE;
gchar *name;
group_name = gtk_action_group_get_name (GTK_ACTION_GROUP (group));
@ -101,26 +92,155 @@ window_actions_update (GimpActionGroup *group,
if (GTK_IS_WINDOW (window))
{
GdkDisplay *display;
GdkScreen *screen;
gint cur_screen;
GdkDisplay *display;
GdkScreen *screen;
gchar *screen_name;
display = gtk_widget_get_display (window);
screen = gtk_widget_get_screen (window);
n_screens = gdk_display_get_n_screens (display);
cur_screen = gdk_screen_get_number (screen);
show_menu = (gdk_display_get_n_screens (display) > 1);
if (! show_menu)
{
GdkDisplayManager *manager = gdk_display_manager_get ();
GSList *displays;
displays = gdk_display_manager_list_displays (manager);
show_menu = (displays->next != NULL);
g_slist_free (displays);
}
screen = gtk_widget_get_screen (window);
screen_name = gdk_screen_make_display_name (screen);
name = g_strdup_printf ("%s-move-to-screen-%s", group_name, screen_name);
g_free (screen_name);
name = g_strdup_printf ("%s-move-to-screen-%02d",
group_name, cur_screen);
SET_ACTIVE (name, TRUE);
g_free (name);
}
name = g_strdup_printf ("%s-move-to-screen-menu", group_name);
SET_VISIBLE (name, n_screens > 1);
SET_VISIBLE (name, show_menu);
g_free (name);
#undef SET_ACTIVE
#undef SET_VISIBLE
}
/* private functions */
static void
window_actions_display_opened (GdkDisplayManager *manager,
GdkDisplay *display,
GimpActionGroup *group)
{
GimpRadioActionEntry *entries;
const gchar *help_id;
const gchar *group_name;
GSList *radio_group;
gint n_screens;
gint i;
help_id = g_object_get_data (G_OBJECT (group), "change-to-screen-help-id");
group_name = gtk_action_group_get_name (GTK_ACTION_GROUP (group));
n_screens = gdk_display_get_n_screens (display);
entries = g_new0 (GimpRadioActionEntry, n_screens);
for (i = 0; i < n_screens; i++)
{
GdkScreen *screen = gdk_display_get_screen (display, i);
gchar *screen_name;
screen_name = gdk_screen_make_display_name (screen);
entries[i].name = g_strdup_printf ("%s-move-to-screen-%s",
group_name, screen_name);
entries[i].stock_id = GIMP_STOCK_MOVE_TO_SCREEN;
entries[i].label = g_strdup_printf (_("Screen %s"), screen_name);
entries[i].accelerator = NULL;
entries[i].tooltip = NULL;
entries[i].value = g_quark_from_string (screen_name);
entries[i].help_id = help_id;
g_free (screen_name);
}
radio_group = g_object_get_data (G_OBJECT (group),
"change-to-screen-radio-group");
radio_group = gimp_action_group_add_radio_actions (group, entries, n_screens,
radio_group, 0,
G_CALLBACK (window_move_to_screen_cmd_callback));
g_object_set_data (G_OBJECT (group), "change-to-screen-radio-group",
radio_group);
for (i = 0; i < n_screens; i++)
{
GdkScreen *screen = gdk_display_get_screen (display, i);
GtkAction *action;
action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
entries[i].name);
if (action)
g_object_set_data (G_OBJECT (action), "screen", screen);
g_free ((gchar *) entries[i].name);
g_free ((gchar *) entries[i].label);
}
g_free (entries);
g_signal_connect_object (display, "closed",
G_CALLBACK (window_actions_display_closed),
G_OBJECT (group), 0);
}
static void
window_actions_display_closed (GdkDisplay *display,
gboolean is_error,
GimpActionGroup *group)
{
const gchar *group_name;
gint n_screens;
gint i;
group_name = gtk_action_group_get_name (GTK_ACTION_GROUP (group));
n_screens = gdk_display_get_n_screens (display);
for (i = 0; i < n_screens; i++)
{
GdkScreen *screen = gdk_display_get_screen (display, i);
GtkAction *action;
gchar *screen_name;
gchar *action_name;
screen_name = gdk_screen_make_display_name (screen);
action_name = g_strdup_printf ("%s-move-to-screen-%s",
group_name, screen_name);
g_free (screen_name);
action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
action_name);
if (action)
{
GSList *radio_group;
radio_group = gtk_radio_action_get_group (GTK_RADIO_ACTION (action));
if (radio_group->data == (gpointer) action)
radio_group = radio_group->next;
gtk_action_group_remove_action (GTK_ACTION_GROUP (group), action);
g_object_set_data (G_OBJECT (group), "change-to-screen-radio-group",
radio_group);
}
g_free (action_name);
}
}

View File

@ -21,8 +21,7 @@
void window_actions_setup (GimpActionGroup *group,
const gchar *move_to_screen_help_id,
GCallback move_to_screen_callback);
const gchar *move_to_screen_help_id);
void window_actions_update (GimpActionGroup *group,
GtkWidget *window);

View File

@ -0,0 +1,73 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "actions-types.h"
#include "actions.h"
#include "window-commands.h"
/* public functions */
void
window_close_cmd_callback (GtkAction *action,
gpointer data)
{
GtkWidget *widget;
return_if_no_widget (widget, data);
if (! GTK_WIDGET_TOPLEVEL (widget))
widget = gtk_widget_get_toplevel (widget);
if (widget && widget->window)
{
GdkEvent *event = gdk_event_new (GDK_DELETE);
event->any.window = g_object_ref (widget->window);
event->any.send_event = TRUE;
gtk_main_do_event (event);
gdk_event_free (event);
}
}
void
window_move_to_screen_cmd_callback (GtkAction *action,
GtkAction *current,
gpointer data)
{
GtkWidget *widget;
GdkScreen *screen;
return_if_no_widget (widget, data);
if (! GTK_WIDGET_TOPLEVEL (widget))
widget = gtk_widget_get_toplevel (widget);
screen = g_object_get_data (G_OBJECT (current), "screen");
if (GDK_IS_SCREEN (screen) && screen != gtk_widget_get_screen (widget))
{
gtk_window_set_screen (GTK_WINDOW (widget), screen);
}
}

View File

@ -0,0 +1,30 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __WINDOW_COMMANDS_H__
#define __WINDOW_COMMANDS_H__
void window_close_cmd_callback (GtkAction *action,
gpointer data);
void window_move_to_screen_cmd_callback (GtkAction *action,
GtkAction *current,
gpointer data);
#endif /* __WINDOW_COMMANDS_H__ */

View File

@ -31,35 +31,101 @@
#include "window-menu.h"
/* private functions */
static void window_menu_display_opened (GdkDisplayManager *disp_manager,
GdkDisplay *display,
GimpUIManager *manager);
static void window_menu_display_closed (GdkDisplay *display,
gboolean is_error,
GimpUIManager *manager);
/* public functions */
void
window_menu_setup (GimpUIManager *manager,
const gchar *group_name,
const gchar *ui_path)
{
GdkDisplay *display;
GtkUIManager *ui_manager;
gint n_entries;
guint merge_id;
gint i;
GdkDisplayManager *disp_manager = gdk_display_manager_get ();
GSList *displays;
GSList *list;
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
ui_manager = GTK_UI_MANAGER (manager);
g_object_set_data_full (G_OBJECT (manager), "move-to-screen-group-name",
g_strdup (group_name),
(GDestroyNotify) g_free);
g_object_set_data_full (G_OBJECT (manager), "move-to-screen-ui-path",
g_strdup (ui_path),
(GDestroyNotify) g_free);
display = gdk_display_get_default ();
n_entries = gdk_display_get_n_screens (display);
displays = gdk_display_manager_list_displays (disp_manager);
/* present displays in the order in which they were opened */
displays = g_slist_reverse (displays);
for (list = displays; list; list = g_slist_next (list))
{
window_menu_display_opened (disp_manager, list->data, manager);
}
g_slist_free (displays);
g_signal_connect_object (disp_manager, "display-opened",
G_CALLBACK (window_menu_display_opened),
G_OBJECT (manager), 0);
}
/* private functions */
static void
window_menu_display_opened (GdkDisplayManager *disp_manager,
GdkDisplay *display,
GimpUIManager *manager)
{
GtkUIManager *ui_manager = GTK_UI_MANAGER (manager);
const gchar *group_name;
const gchar *ui_path;
gchar *action_path;
gchar *merge_key;
guint merge_id;
gint n_screens;
gint i;
group_name = g_object_get_data (G_OBJECT (manager),
"move-to-screen-group-name");
ui_path = g_object_get_data (G_OBJECT (manager),
"move-to-screen-ui-path");
action_path = g_strdup_printf ("%s/Move to Screen", ui_path);
merge_key = g_strdup_printf ("%s-display-merge-id",
gdk_display_get_name (display));
merge_id = gtk_ui_manager_new_merge_id (ui_manager);
g_object_set_data (G_OBJECT (manager), merge_key,
GUINT_TO_POINTER (merge_id));
for (i = 0; i < n_entries; i++)
g_free (merge_key);
n_screens = gdk_display_get_n_screens (display);
for (i = 0; i < n_screens; i++)
{
gchar *action_name;
gchar *action_path;
GdkScreen *screen;
gchar *screen_name;
gchar *action_name;
action_name = g_strdup_printf ("%s-move-to-screen-%02d",
group_name, i);
action_path = g_strdup_printf ("%s/Move to Screen", ui_path);
screen = gdk_display_get_screen (display, i);
screen_name = gdk_screen_make_display_name (screen);
action_name = g_strdup_printf ("%s-move-to-screen-%s",
group_name, screen_name);
g_free (screen_name);
gtk_ui_manager_add_ui (ui_manager, merge_id,
action_path, action_name, action_name,
@ -67,6 +133,29 @@ window_menu_setup (GimpUIManager *manager,
FALSE);
g_free (action_name);
g_free (action_path);
}
g_free (action_path);
g_signal_connect_object (display, "closed",
G_CALLBACK (window_menu_display_closed),
G_OBJECT (manager), 0);
}
static void
window_menu_display_closed (GdkDisplay *display,
gboolean is_error,
GimpUIManager *manager)
{
gchar *merge_key;
guint merge_id;
merge_key = g_strdup_printf ("%s-display-merge-id",
gdk_display_get_name (display));
merge_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (manager),
merge_key));
g_free (merge_key);
if (merge_id)
gtk_ui_manager_remove_ui (GTK_UI_MANAGER (manager), merge_id);
}