2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2005-01-29 03:48:31 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2005-01-29 03:48:31 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2005-01-29 03:48:31 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2005-01-29 03:48:31 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2005-01-29 03:48:31 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "actions-types.h"
|
|
|
|
|
|
|
|
#include "widgets/gimpactiongroup.h"
|
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
|
|
|
|
#include "actions.h"
|
|
|
|
#include "window-actions.h"
|
2005-11-18 04:16:07 +08:00
|
|
|
#include "window-commands.h"
|
2005-01-29 03:48:31 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
/* 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 */
|
|
|
|
|
2005-01-29 03:48:31 +08:00
|
|
|
void
|
|
|
|
window_actions_setup (GimpActionGroup *group,
|
2005-11-18 04:16:07 +08:00
|
|
|
const gchar *move_to_screen_help_id)
|
|
|
|
{
|
|
|
|
GdkDisplayManager *manager = gdk_display_manager_get ();
|
|
|
|
GSList *displays;
|
|
|
|
GSList *list;
|
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (group), "move-to-screen-help-id",
|
|
|
|
g_strdup (move_to_screen_help_id),
|
|
|
|
(GDestroyNotify) g_free);
|
|
|
|
|
2018-06-21 02:29:27 +08:00
|
|
|
g_object_set_data_full (G_OBJECT (group), "display-table",
|
|
|
|
g_hash_table_new_full (g_str_hash,
|
|
|
|
g_str_equal,
|
|
|
|
g_free, NULL),
|
|
|
|
(GDestroyNotify) g_hash_table_unref);
|
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
displays = gdk_display_manager_list_displays (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_actions_display_opened (manager, list->data, group);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (displays);
|
|
|
|
|
|
|
|
g_signal_connect_object (manager, "display-opened",
|
|
|
|
G_CALLBACK (window_actions_display_opened),
|
|
|
|
G_OBJECT (group), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_actions_update (GimpActionGroup *group,
|
|
|
|
GtkWidget *window)
|
|
|
|
{
|
|
|
|
const gchar *group_name;
|
|
|
|
gint show_menu = FALSE;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
group_name = gtk_action_group_get_name (GTK_ACTION_GROUP (group));
|
|
|
|
|
|
|
|
#define SET_ACTIVE(action,active) \
|
|
|
|
gimp_action_group_set_action_active (group, action, (active) != 0)
|
|
|
|
#define SET_VISIBLE(action,active) \
|
|
|
|
gimp_action_group_set_action_visible (group, action, (active) != 0)
|
|
|
|
|
|
|
|
if (GTK_IS_WINDOW (window))
|
|
|
|
{
|
|
|
|
GdkScreen *screen;
|
|
|
|
gchar *screen_name;
|
|
|
|
|
2011-10-06 22:15:32 +08:00
|
|
|
#ifndef GIMP_UNSTABLE
|
2011-10-11 12:38:59 +08:00
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
|
|
|
display = gtk_widget_get_display (window);
|
|
|
|
show_menu = (gdk_display_get_n_screens (display) > 1);
|
|
|
|
}
|
2011-10-06 22:15:32 +08:00
|
|
|
#else
|
2005-11-24 08:39:12 +08:00
|
|
|
show_menu = TRUE;
|
2011-10-06 22:15:32 +08:00
|
|
|
#endif /* !GIMP_UNSTABLE */
|
2005-11-24 08:39:12 +08:00
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
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);
|
|
|
|
|
|
|
|
SET_ACTIVE (name, TRUE);
|
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
name = g_strdup_printf ("%s-move-to-screen-menu", group_name);
|
|
|
|
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)
|
2005-01-29 03:48:31 +08:00
|
|
|
{
|
|
|
|
GimpRadioActionEntry *entries;
|
2018-06-21 02:29:27 +08:00
|
|
|
GHashTable *displays;
|
|
|
|
const gchar *display_name;
|
2005-11-18 04:16:07 +08:00
|
|
|
const gchar *help_id;
|
2005-01-29 03:48:31 +08:00
|
|
|
const gchar *group_name;
|
2005-11-18 04:16:07 +08:00
|
|
|
GSList *radio_group;
|
2018-06-21 02:29:27 +08:00
|
|
|
gint count;
|
2005-11-18 04:16:07 +08:00
|
|
|
gint n_screens;
|
2005-01-29 03:48:31 +08:00
|
|
|
gint i;
|
|
|
|
|
2018-06-21 02:29:27 +08:00
|
|
|
displays = g_object_get_data (G_OBJECT (group), "display-table");
|
|
|
|
|
|
|
|
display_name = gdk_display_get_name (display);
|
|
|
|
|
|
|
|
count = GPOINTER_TO_INT (g_hash_table_lookup (displays,
|
|
|
|
display_name));
|
|
|
|
|
|
|
|
g_hash_table_insert (displays, g_strdup (display_name),
|
|
|
|
GINT_TO_POINTER (count + 1));
|
|
|
|
|
|
|
|
/* don't add the same display twice */
|
|
|
|
if (count > 0)
|
|
|
|
return;
|
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
help_id = g_object_get_data (G_OBJECT (group), "change-to-screen-help-id");
|
2005-01-29 03:48:31 +08:00
|
|
|
|
|
|
|
group_name = gtk_action_group_get_name (GTK_ACTION_GROUP (group));
|
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
n_screens = gdk_display_get_n_screens (display);
|
2005-01-29 03:48:31 +08:00
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
entries = g_new0 (GimpRadioActionEntry, n_screens);
|
|
|
|
|
|
|
|
for (i = 0; i < n_screens; i++)
|
2005-01-29 03:48:31 +08:00
|
|
|
{
|
2005-11-18 04:16:07 +08:00
|
|
|
GdkScreen *screen = gdk_display_get_screen (display, i);
|
2005-01-29 03:48:31 +08:00
|
|
|
gchar *screen_name;
|
|
|
|
|
|
|
|
screen_name = gdk_screen_make_display_name (screen);
|
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
entries[i].name = g_strdup_printf ("%s-move-to-screen-%s",
|
|
|
|
group_name, screen_name);
|
2017-03-05 23:01:59 +08:00
|
|
|
entries[i].icon_name = GIMP_ICON_WINDOW_MOVE_TO_SCREEN;
|
2005-11-18 04:16:07 +08:00
|
|
|
entries[i].label = g_strdup_printf (_("Screen %s"), screen_name);
|
2005-01-29 03:48:31 +08:00
|
|
|
entries[i].accelerator = NULL;
|
2007-03-31 19:38:47 +08:00
|
|
|
entries[i].tooltip = g_strdup_printf (_("Move this window to "
|
|
|
|
"screen %s"), screen_name);
|
2005-11-18 04:16:07 +08:00
|
|
|
entries[i].value = g_quark_from_string (screen_name);
|
|
|
|
entries[i].help_id = help_id;
|
2005-01-29 03:48:31 +08:00
|
|
|
|
|
|
|
g_free (screen_name);
|
|
|
|
}
|
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
radio_group = g_object_get_data (G_OBJECT (group),
|
|
|
|
"change-to-screen-radio-group");
|
2008-12-03 23:27:42 +08:00
|
|
|
radio_group = gimp_action_group_add_radio_actions (group, NULL,
|
|
|
|
entries, n_screens,
|
2005-11-18 04:16:07 +08:00
|
|
|
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);
|
2005-01-29 03:48:31 +08:00
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
for (i = 0; i < n_screens; i++)
|
2005-01-29 03:48:31 +08:00
|
|
|
{
|
2005-11-18 04:16:07 +08:00
|
|
|
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);
|
|
|
|
|
2005-01-29 03:48:31 +08:00
|
|
|
g_free ((gchar *) entries[i].name);
|
2007-03-31 19:38:47 +08:00
|
|
|
g_free ((gchar *) entries[i].tooltip);
|
2005-01-29 03:48:31 +08:00
|
|
|
g_free ((gchar *) entries[i].label);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (entries);
|
2005-11-18 04:16:07 +08:00
|
|
|
|
|
|
|
g_signal_connect_object (display, "closed",
|
|
|
|
G_CALLBACK (window_actions_display_closed),
|
|
|
|
G_OBJECT (group), 0);
|
2005-01-29 03:48:31 +08:00
|
|
|
}
|
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
static void
|
|
|
|
window_actions_display_closed (GdkDisplay *display,
|
|
|
|
gboolean is_error,
|
|
|
|
GimpActionGroup *group)
|
2005-01-29 03:48:31 +08:00
|
|
|
{
|
2018-06-21 02:29:27 +08:00
|
|
|
GHashTable *displays;
|
|
|
|
const gchar *display_name;
|
2005-01-29 03:48:31 +08:00
|
|
|
const gchar *group_name;
|
2018-06-21 02:29:27 +08:00
|
|
|
gint count;
|
2005-11-18 04:16:07 +08:00
|
|
|
gint n_screens;
|
|
|
|
gint i;
|
2005-01-29 03:48:31 +08:00
|
|
|
|
2018-06-21 02:29:27 +08:00
|
|
|
displays = g_object_get_data (G_OBJECT (group), "display-table");
|
|
|
|
|
2018-06-21 02:32:48 +08:00
|
|
|
display_name = gdk_display_get_name (display);
|
|
|
|
|
2018-06-21 02:29:27 +08:00
|
|
|
count = GPOINTER_TO_INT (g_hash_table_lookup (displays,
|
|
|
|
display_name));
|
|
|
|
|
|
|
|
/* don't remove the same display twice */
|
|
|
|
if (count > 1)
|
|
|
|
{
|
|
|
|
g_hash_table_insert (displays, g_strdup (display_name),
|
|
|
|
GINT_TO_POINTER (count - 1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_remove (displays, display_name);
|
|
|
|
|
2005-01-29 03:48:31 +08:00
|
|
|
group_name = gtk_action_group_get_name (GTK_ACTION_GROUP (group));
|
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
n_screens = gdk_display_get_n_screens (display);
|
2005-01-29 03:48:31 +08:00
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
for (i = 0; i < n_screens; i++)
|
2005-01-29 03:48:31 +08:00
|
|
|
{
|
2005-11-18 04:16:07 +08:00
|
|
|
GdkScreen *screen = gdk_display_get_screen (display, i);
|
|
|
|
GtkAction *action;
|
|
|
|
gchar *screen_name;
|
|
|
|
gchar *action_name;
|
2005-01-29 03:48:31 +08:00
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
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);
|
2005-01-29 03:48:31 +08:00
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
|
|
|
|
action_name);
|
2005-01-29 03:48:31 +08:00
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
GSList *radio_group;
|
2005-01-29 03:48:31 +08:00
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
radio_group = gtk_radio_action_get_group (GTK_RADIO_ACTION (action));
|
|
|
|
if (radio_group->data == (gpointer) action)
|
|
|
|
radio_group = radio_group->next;
|
2005-01-29 03:48:31 +08:00
|
|
|
|
2005-11-18 04:16:07 +08:00
|
|
|
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);
|
|
|
|
}
|
2005-01-29 03:48:31 +08:00
|
|
|
}
|