2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-10-10 23:59:12 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpsessioninfo.c
|
2007-05-25 03:22:06 +08:00
|
|
|
* Copyright (C) 2001-2007 Michael Natterer <mitch@gimp.org>
|
2003-10-10 23:59:12 +08:00
|
|
|
*
|
|
|
|
* 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 <string.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "widgets-types.h"
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
#include "gimpcontainerview.h"
|
|
|
|
#include "gimpcontainerview-utils.h"
|
|
|
|
#include "gimpdialogfactory.h"
|
|
|
|
#include "gimpdock.h"
|
|
|
|
#include "gimpdockable.h"
|
|
|
|
#include "gimpdockbook.h"
|
2003-10-11 05:24:12 +08:00
|
|
|
#include "gimpdocked.h"
|
2003-10-10 23:59:12 +08:00
|
|
|
#include "gimpsessioninfo.h"
|
2007-05-25 03:22:06 +08:00
|
|
|
#include "gimpsessioninfoaux.h"
|
|
|
|
#include "gimpsessioninfobook.h"
|
|
|
|
#include "gimpsessioninfodockable.h"
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SESSION_INFO_POSITION,
|
|
|
|
SESSION_INFO_SIZE,
|
|
|
|
SESSION_INFO_OPEN,
|
|
|
|
SESSION_INFO_AUX,
|
|
|
|
|
|
|
|
SESSION_INFO_DOCK,
|
|
|
|
|
2007-05-25 03:22:06 +08:00
|
|
|
SESSION_INFO_BOOK
|
2003-10-10 23:59:12 +08:00
|
|
|
};
|
|
|
|
|
2003-11-14 04:57:59 +08:00
|
|
|
#define DEFAULT_SCREEN -1
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2007-05-25 03:22:06 +08:00
|
|
|
static GTokenType session_info_dock_deserialize (GScanner *scanner,
|
|
|
|
gint scope,
|
|
|
|
GimpSessionInfo *info);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2007-05-25 03:22:06 +08:00
|
|
|
GimpSessionInfo *
|
|
|
|
gimp_session_info_new (void)
|
|
|
|
{
|
|
|
|
return g_slice_new0 (GimpSessionInfo);
|
|
|
|
}
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
void
|
|
|
|
gimp_session_info_free (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
|
|
|
|
if (info->aux_info)
|
|
|
|
{
|
2004-07-08 20:04:15 +08:00
|
|
|
g_list_foreach (info->aux_info,
|
|
|
|
(GFunc) gimp_session_info_aux_free, NULL);
|
2003-10-10 23:59:12 +08:00
|
|
|
g_list_free (info->aux_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->books)
|
|
|
|
{
|
2004-07-08 20:04:15 +08:00
|
|
|
g_list_foreach (info->books,
|
|
|
|
(GFunc) gimp_session_info_book_free, NULL);
|
2003-10-10 23:59:12 +08:00
|
|
|
g_list_free (info->books);
|
|
|
|
}
|
|
|
|
|
2007-05-25 03:22:06 +08:00
|
|
|
g_slice_free (GimpSessionInfo, info);
|
2004-07-08 08:09:41 +08:00
|
|
|
}
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
void
|
|
|
|
gimp_session_info_save (GimpSessionInfo *info,
|
|
|
|
const gchar *factory_name,
|
|
|
|
GimpConfigWriter *writer)
|
|
|
|
{
|
|
|
|
const gchar *dialog_name;
|
|
|
|
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
g_return_if_fail (factory_name != NULL);
|
|
|
|
g_return_if_fail (writer != NULL);
|
|
|
|
|
|
|
|
if (info->widget)
|
|
|
|
gimp_session_info_get_geometry (info);
|
|
|
|
|
|
|
|
if (info->toplevel_entry)
|
|
|
|
dialog_name = info->toplevel_entry->identifier;
|
|
|
|
else
|
|
|
|
dialog_name = "dock";
|
|
|
|
|
|
|
|
gimp_config_writer_open (writer, "session-info");
|
|
|
|
gimp_config_writer_string (writer, factory_name);
|
|
|
|
gimp_config_writer_string (writer, dialog_name);
|
|
|
|
|
|
|
|
gimp_config_writer_open (writer, "position");
|
|
|
|
gimp_config_writer_printf (writer, "%d %d", info->x, info->y);
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
|
|
|
|
if (info->width > 0 && info->height > 0)
|
|
|
|
{
|
|
|
|
gimp_config_writer_open (writer, "size");
|
|
|
|
gimp_config_writer_printf (writer, "%d %d", info->width, info->height);
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->open)
|
|
|
|
{
|
|
|
|
gimp_config_writer_open (writer, "open-on-exit");
|
2003-11-14 04:57:59 +08:00
|
|
|
|
|
|
|
if (info->screen != DEFAULT_SCREEN)
|
|
|
|
gimp_config_writer_printf (writer, "%d", info->screen);
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->widget)
|
|
|
|
{
|
2007-05-25 03:22:06 +08:00
|
|
|
gimp_session_info_aux_serialize (writer, info->widget);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2007-05-25 03:22:06 +08:00
|
|
|
if (! info->toplevel_entry)
|
2003-10-10 23:59:12 +08:00
|
|
|
{
|
2007-05-25 03:22:06 +08:00
|
|
|
GimpDock *dock = GIMP_DOCK (info->widget);
|
|
|
|
GList *books;
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2007-05-25 03:22:06 +08:00
|
|
|
gimp_config_writer_open (writer, "dock");
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2007-05-25 03:22:06 +08:00
|
|
|
for (books = dock->dockbooks; books; books = g_list_next (books))
|
|
|
|
gimp_session_info_book_serialize (writer, books->data);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_config_writer_close (writer); /* session-info */
|
|
|
|
}
|
|
|
|
|
|
|
|
GTokenType
|
|
|
|
gimp_session_info_deserialize (GScanner *scanner,
|
|
|
|
gint scope)
|
|
|
|
{
|
|
|
|
GimpDialogFactory *factory;
|
|
|
|
GimpSessionInfo *info = NULL;
|
|
|
|
GTokenType token;
|
2004-11-05 05:02:34 +08:00
|
|
|
gboolean skip = FALSE;
|
2003-10-10 23:59:12 +08:00
|
|
|
gchar *factory_name;
|
|
|
|
gchar *entry_name;
|
|
|
|
|
|
|
|
g_return_val_if_fail (scanner != NULL, G_TOKEN_LEFT_PAREN);
|
|
|
|
|
|
|
|
g_scanner_scope_add_symbol (scanner, scope, "position",
|
|
|
|
GINT_TO_POINTER (SESSION_INFO_POSITION));
|
|
|
|
g_scanner_scope_add_symbol (scanner, scope, "size",
|
|
|
|
GINT_TO_POINTER (SESSION_INFO_SIZE));
|
|
|
|
g_scanner_scope_add_symbol (scanner, scope, "open-on-exit",
|
|
|
|
GINT_TO_POINTER (SESSION_INFO_OPEN));
|
|
|
|
g_scanner_scope_add_symbol (scanner, scope, "aux-info",
|
|
|
|
GINT_TO_POINTER (SESSION_INFO_AUX));
|
|
|
|
g_scanner_scope_add_symbol (scanner, scope, "dock",
|
|
|
|
GINT_TO_POINTER (SESSION_INFO_DOCK));
|
|
|
|
|
|
|
|
token = G_TOKEN_STRING;
|
|
|
|
|
|
|
|
if (! gimp_scanner_parse_string (scanner, &factory_name))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
factory = gimp_dialog_factory_from_name (factory_name);
|
|
|
|
g_free (factory_name);
|
|
|
|
|
|
|
|
if (! factory)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (! gimp_scanner_parse_string (scanner, &entry_name))
|
|
|
|
goto error;
|
|
|
|
|
2007-05-25 03:22:06 +08:00
|
|
|
info = gimp_session_info_new ();
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2003-11-14 04:57:59 +08:00
|
|
|
info->screen = DEFAULT_SCREEN;
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
if (strcmp (entry_name, "dock"))
|
|
|
|
{
|
|
|
|
info->toplevel_entry = gimp_dialog_factory_find_entry (factory,
|
|
|
|
entry_name);
|
2004-11-05 05:02:34 +08:00
|
|
|
skip = (info->toplevel_entry == NULL);
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
|
2004-11-05 05:02:34 +08:00
|
|
|
g_free (entry_name);
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
|
|
|
|
while (g_scanner_peek_next_token (scanner) == token)
|
|
|
|
{
|
|
|
|
token = g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
switch (token)
|
|
|
|
{
|
|
|
|
case G_TOKEN_LEFT_PAREN:
|
|
|
|
token = G_TOKEN_SYMBOL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_SYMBOL:
|
|
|
|
switch (GPOINTER_TO_INT (scanner->value.v_symbol))
|
|
|
|
{
|
|
|
|
case SESSION_INFO_POSITION:
|
|
|
|
token = G_TOKEN_INT;
|
|
|
|
if (! gimp_scanner_parse_int (scanner, &info->x))
|
|
|
|
goto error;
|
|
|
|
if (! gimp_scanner_parse_int (scanner, &info->y))
|
|
|
|
goto error;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SESSION_INFO_SIZE:
|
|
|
|
token = G_TOKEN_INT;
|
|
|
|
if (! gimp_scanner_parse_int (scanner, &info->width))
|
|
|
|
goto error;
|
|
|
|
if (! gimp_scanner_parse_int (scanner, &info->height))
|
|
|
|
goto error;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SESSION_INFO_OPEN:
|
|
|
|
info->open = TRUE;
|
2003-11-13 23:50:23 +08:00
|
|
|
|
2003-11-14 20:05:13 +08:00
|
|
|
/* the screen number is optional */
|
2003-11-14 01:44:41 +08:00
|
|
|
if (g_scanner_peek_next_token (scanner) == G_TOKEN_RIGHT_PAREN)
|
|
|
|
break;
|
|
|
|
|
2003-11-13 23:50:23 +08:00
|
|
|
token = G_TOKEN_INT;
|
|
|
|
if (! gimp_scanner_parse_int (scanner, &info->screen))
|
|
|
|
goto error;
|
2003-10-10 23:59:12 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SESSION_INFO_AUX:
|
2007-05-25 03:22:06 +08:00
|
|
|
token = gimp_session_info_aux_deserialize (scanner,
|
|
|
|
&info->aux_info);
|
2003-10-12 00:50:35 +08:00
|
|
|
if (token != G_TOKEN_LEFT_PAREN)
|
|
|
|
goto error;
|
2003-10-10 23:59:12 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SESSION_INFO_DOCK:
|
|
|
|
if (info->toplevel_entry)
|
|
|
|
goto error;
|
|
|
|
|
2007-05-25 03:22:06 +08:00
|
|
|
g_scanner_set_scope (scanner, scope + 1);
|
|
|
|
token = session_info_dock_deserialize (scanner, scope + 1, info);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
if (token == G_TOKEN_LEFT_PAREN)
|
|
|
|
g_scanner_set_scope (scanner, scope);
|
|
|
|
else
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
token = G_TOKEN_RIGHT_PAREN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_RIGHT_PAREN:
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (token == G_TOKEN_LEFT_PAREN)
|
|
|
|
{
|
|
|
|
token = G_TOKEN_RIGHT_PAREN;
|
|
|
|
|
2004-11-05 05:02:34 +08:00
|
|
|
if (!skip && g_scanner_peek_next_token (scanner) == token)
|
2003-10-10 23:59:12 +08:00
|
|
|
factory->session_infos = g_list_append (factory->session_infos, info);
|
2004-11-05 05:02:34 +08:00
|
|
|
else
|
|
|
|
gimp_session_info_free (info);
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error:
|
2004-11-05 05:02:34 +08:00
|
|
|
if (info)
|
|
|
|
gimp_session_info_free (info);
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_scanner_scope_remove_symbol (scanner, scope, "position");
|
|
|
|
g_scanner_scope_remove_symbol (scanner, scope, "size");
|
|
|
|
g_scanner_scope_remove_symbol (scanner, scope, "open-on-exit");
|
|
|
|
g_scanner_scope_remove_symbol (scanner, scope, "aux-info");
|
|
|
|
g_scanner_scope_remove_symbol (scanner, scope, "dock");
|
|
|
|
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2004-06-01 20:31:44 +08:00
|
|
|
static void
|
|
|
|
gimp_session_info_paned_size_allocate (GtkWidget *paned,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (paned,
|
|
|
|
gimp_session_info_paned_size_allocate,
|
|
|
|
data);
|
|
|
|
|
|
|
|
gtk_paned_set_position (GTK_PANED (paned), GPOINTER_TO_INT (data));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_session_info_paned_map (GtkWidget *paned,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (paned,
|
|
|
|
gimp_session_info_paned_map,
|
|
|
|
data);
|
|
|
|
|
|
|
|
g_signal_connect_after (paned, "size-allocate",
|
|
|
|
G_CALLBACK (gimp_session_info_paned_size_allocate),
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
void
|
|
|
|
gimp_session_info_restore (GimpSessionInfo *info,
|
|
|
|
GimpDialogFactory *factory)
|
|
|
|
{
|
2003-11-13 23:50:23 +08:00
|
|
|
GdkDisplay *display;
|
2003-11-14 04:57:59 +08:00
|
|
|
GdkScreen *screen = NULL;
|
2003-11-13 23:50:23 +08:00
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
g_return_if_fail (GIMP_IS_DIALOG_FACTORY (factory));
|
|
|
|
|
2003-11-13 23:50:23 +08:00
|
|
|
display = gdk_display_get_default ();
|
|
|
|
|
2003-11-14 04:57:59 +08:00
|
|
|
if (info->screen != DEFAULT_SCREEN)
|
|
|
|
screen = gdk_display_get_screen (display, info->screen);
|
2003-11-13 23:50:23 +08:00
|
|
|
|
|
|
|
if (! screen)
|
|
|
|
screen = gdk_display_get_default_screen (display);
|
|
|
|
|
|
|
|
info->open = FALSE;
|
2003-11-14 04:57:59 +08:00
|
|
|
info->screen = DEFAULT_SCREEN;
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
if (info->toplevel_entry)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
dialog =
|
2003-11-13 23:50:23 +08:00
|
|
|
gimp_dialog_factory_dialog_new (factory, screen,
|
2003-10-10 23:59:12 +08:00
|
|
|
info->toplevel_entry->identifier,
|
2006-01-17 18:08:50 +08:00
|
|
|
info->toplevel_entry->view_size,
|
2004-09-01 06:41:15 +08:00
|
|
|
TRUE);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
if (dialog && info->aux_info)
|
2007-05-25 03:22:06 +08:00
|
|
|
gimp_session_info_set_aux_info (dialog, info->aux_info);
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GimpDock *dock;
|
|
|
|
GList *books;
|
|
|
|
|
2003-11-13 23:50:23 +08:00
|
|
|
dock = GIMP_DOCK (gimp_dialog_factory_dock_new (factory, screen));
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
if (dock && info->aux_info)
|
2007-05-25 03:22:06 +08:00
|
|
|
gimp_session_info_set_aux_info (GTK_WIDGET (dock), info->aux_info);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
for (books = info->books; books; books = g_list_next (books))
|
2007-05-25 03:22:06 +08:00
|
|
|
gimp_session_info_book_restore (books->data, dock);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
for (books = info->books; books; books = g_list_next (books))
|
|
|
|
{
|
|
|
|
GimpSessionInfoBook *book_info = books->data;
|
|
|
|
GtkWidget *dockbook = book_info->widget;
|
|
|
|
|
|
|
|
if (GTK_IS_VPANED (dockbook->parent))
|
|
|
|
{
|
|
|
|
GtkPaned *paned = GTK_PANED (dockbook->parent);
|
|
|
|
|
|
|
|
if (dockbook == paned->child2)
|
2004-06-01 20:31:44 +08:00
|
|
|
g_signal_connect_after (paned, "map",
|
|
|
|
G_CALLBACK (gimp_session_info_paned_map),
|
|
|
|
GINT_TO_POINTER (book_info->position));
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_foreach (info->books, (GFunc) gimp_session_info_book_free, NULL);
|
|
|
|
g_list_free (info->books);
|
|
|
|
info->books = NULL;
|
|
|
|
|
|
|
|
gtk_widget_show (GTK_WIDGET (dock));
|
|
|
|
}
|
|
|
|
|
2003-12-17 02:06:41 +08:00
|
|
|
g_list_foreach (info->aux_info, (GFunc) gimp_session_info_aux_free, NULL);
|
2003-10-10 23:59:12 +08:00
|
|
|
g_list_free (info->aux_info);
|
|
|
|
info->aux_info = NULL;
|
|
|
|
}
|
|
|
|
|
2006-04-21 02:41:38 +08:00
|
|
|
/* This function mostly lifted from
|
|
|
|
* gtk+/gdk/gdkscreen.c:gdk_screen_get_monitor_at_window()
|
|
|
|
*/
|
2006-04-21 15:02:42 +08:00
|
|
|
static gint
|
|
|
|
get_appropriate_monitor (GdkScreen *screen,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
2006-04-21 02:41:38 +08:00
|
|
|
{
|
|
|
|
GdkRectangle rect;
|
2006-04-21 15:02:42 +08:00
|
|
|
gint area = 0;
|
|
|
|
gint monitor = -1;
|
|
|
|
gint num_monitors;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
rect.x = x;
|
|
|
|
rect.y = y;
|
|
|
|
rect.width = w;
|
2006-04-21 02:41:38 +08:00
|
|
|
rect.height = h;
|
|
|
|
|
|
|
|
num_monitors = gdk_screen_get_n_monitors (screen);
|
2006-04-21 15:02:42 +08:00
|
|
|
|
2006-04-21 02:41:38 +08:00
|
|
|
for (i = 0; i < num_monitors; i++)
|
|
|
|
{
|
2006-04-21 15:02:42 +08:00
|
|
|
GdkRectangle geometry;
|
|
|
|
|
|
|
|
gdk_screen_get_monitor_geometry (screen, i, &geometry);
|
|
|
|
|
|
|
|
if (gdk_rectangle_intersect (&rect, &geometry, &geometry) &&
|
|
|
|
geometry.width * geometry.height > area)
|
|
|
|
{
|
|
|
|
area = geometry.width * geometry.height;
|
2006-04-21 02:41:38 +08:00
|
|
|
monitor = i;
|
|
|
|
}
|
|
|
|
}
|
2006-04-21 15:02:42 +08:00
|
|
|
|
2006-04-21 02:41:38 +08:00
|
|
|
if (monitor >= 0)
|
|
|
|
return monitor;
|
|
|
|
else
|
|
|
|
return gdk_screen_get_monitor_at_point (screen,
|
|
|
|
rect.x + rect.width / 2,
|
|
|
|
rect.y + rect.height / 2);
|
|
|
|
}
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
void
|
|
|
|
gimp_session_info_set_geometry (GimpSessionInfo *info)
|
|
|
|
{
|
2006-04-21 02:41:38 +08:00
|
|
|
GdkScreen *screen;
|
|
|
|
GdkRectangle monitor;
|
|
|
|
gchar geom[32];
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_WINDOW (info->widget));
|
|
|
|
|
|
|
|
screen = gtk_widget_get_screen (info->widget);
|
|
|
|
|
2006-04-21 15:02:42 +08:00
|
|
|
if ((! info->toplevel_entry || info->toplevel_entry->remember_size) &&
|
|
|
|
(info->width > 0 && info->height > 0))
|
2006-04-21 02:41:38 +08:00
|
|
|
{
|
|
|
|
gdk_screen_get_monitor_geometry (screen,
|
|
|
|
get_appropriate_monitor (screen,
|
2006-04-21 15:02:42 +08:00
|
|
|
info->x,
|
|
|
|
info->y,
|
|
|
|
info->width,
|
|
|
|
info->height),
|
2006-04-21 02:41:38 +08:00
|
|
|
&monitor);
|
2006-04-21 15:02:42 +08:00
|
|
|
|
|
|
|
info->x = CLAMP (info->x,
|
|
|
|
monitor.x, monitor.x + monitor.width - info->width);
|
|
|
|
info->y = CLAMP (info->y,
|
|
|
|
monitor.y, monitor.y + monitor.height - info->height);
|
2006-04-21 02:41:38 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdk_screen_get_monitor_geometry (screen,
|
2006-04-21 15:02:42 +08:00
|
|
|
gdk_screen_get_monitor_at_point (screen,
|
|
|
|
info->x,
|
|
|
|
info->y),
|
|
|
|
&monitor);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2006-04-21 02:41:38 +08:00
|
|
|
info->x = CLAMP (info->x, monitor.x, monitor.x + monitor.width - 128);
|
|
|
|
info->y = CLAMP (info->y, monitor.y, monitor.y + monitor.height - 128);
|
|
|
|
}
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
g_snprintf (geom, sizeof (geom), "+%d+%d", info->x, info->y);
|
|
|
|
|
|
|
|
gtk_window_parse_geometry (GTK_WINDOW (info->widget), geom);
|
|
|
|
|
|
|
|
if (! info->toplevel_entry || info->toplevel_entry->remember_size)
|
|
|
|
{
|
|
|
|
if (info->width > 0 && info->height > 0)
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (info->widget),
|
|
|
|
info->width, info->height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_session_info_get_geometry (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_WINDOW (info->widget));
|
|
|
|
|
|
|
|
if (info->widget->window)
|
|
|
|
{
|
|
|
|
gdk_window_get_root_origin (info->widget->window, &info->x, &info->y);
|
|
|
|
|
|
|
|
if (! info->toplevel_entry || info->toplevel_entry->remember_size)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
info->width = info->widget->allocation.width;
|
|
|
|
info->height = info->widget->allocation.height;
|
|
|
|
}
|
2003-10-10 23:59:12 +08:00
|
|
|
else
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
info->width = 0;
|
|
|
|
info->height = 0;
|
|
|
|
}
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
|
2004-03-14 02:19:46 +08:00
|
|
|
info->open = FALSE;
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
if (! info->toplevel_entry || info->toplevel_entry->remember_if_open)
|
2004-03-14 02:19:46 +08:00
|
|
|
{
|
|
|
|
GimpDialogVisibilityState visibility;
|
|
|
|
|
|
|
|
visibility =
|
|
|
|
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (info->widget),
|
|
|
|
GIMP_DIALOG_VISIBILITY_KEY));
|
|
|
|
|
|
|
|
switch (visibility)
|
|
|
|
{
|
|
|
|
case GIMP_DIALOG_VISIBILITY_UNKNOWN:
|
|
|
|
info->open = GTK_WIDGET_VISIBLE (info->widget);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_DIALOG_VISIBILITY_INVISIBLE:
|
|
|
|
info->open = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_DIALOG_VISIBILITY_VISIBLE:
|
|
|
|
info->open = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-11-14 04:57:59 +08:00
|
|
|
|
|
|
|
info->screen = DEFAULT_SCREEN;
|
|
|
|
|
|
|
|
if (info->open)
|
2003-11-13 23:50:23 +08:00
|
|
|
{
|
2003-11-14 04:57:59 +08:00
|
|
|
GdkDisplay *display = gtk_widget_get_display (info->widget);
|
|
|
|
GdkScreen *screen = gtk_widget_get_screen (info->widget);
|
|
|
|
|
|
|
|
if (screen != gdk_display_get_default_screen (display))
|
|
|
|
info->screen = gdk_screen_get_number (screen);
|
2003-11-13 23:50:23 +08:00
|
|
|
}
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static GTokenType
|
|
|
|
session_info_dock_deserialize (GScanner *scanner,
|
2007-05-25 03:22:06 +08:00
|
|
|
gint scope,
|
2003-10-10 23:59:12 +08:00
|
|
|
GimpSessionInfo *info)
|
|
|
|
{
|
2007-05-25 03:22:06 +08:00
|
|
|
GTokenType token;
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2007-05-25 03:22:06 +08:00
|
|
|
g_return_val_if_fail (scanner != NULL, G_TOKEN_LEFT_PAREN);
|
|
|
|
g_return_val_if_fail (info != NULL, G_TOKEN_LEFT_PAREN);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2007-05-25 03:22:06 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, scope, "book",
|
|
|
|
GINT_TO_POINTER (SESSION_INFO_BOOK));
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
|
|
|
|
while (g_scanner_peek_next_token (scanner) == token)
|
|
|
|
{
|
|
|
|
token = g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
switch (token)
|
|
|
|
{
|
|
|
|
case G_TOKEN_LEFT_PAREN:
|
|
|
|
token = G_TOKEN_SYMBOL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_SYMBOL:
|
|
|
|
switch (GPOINTER_TO_INT (scanner->value.v_symbol))
|
|
|
|
{
|
2007-05-25 03:22:06 +08:00
|
|
|
case SESSION_INFO_BOOK:
|
|
|
|
g_scanner_set_scope (scanner, scope + 1);
|
|
|
|
token = gimp_session_info_book_deserialize (scanner, scope + 1,
|
|
|
|
info);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
if (token == G_TOKEN_LEFT_PAREN)
|
2007-05-25 03:22:06 +08:00
|
|
|
g_scanner_set_scope (scanner, scope);
|
2003-10-10 23:59:12 +08:00
|
|
|
else
|
2007-05-25 03:22:06 +08:00
|
|
|
return token;
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-05-25 03:22:06 +08:00
|
|
|
return token;
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
token = G_TOKEN_RIGHT_PAREN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_RIGHT_PAREN:
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-25 03:22:06 +08:00
|
|
|
g_scanner_scope_remove_symbol (scanner, scope, "book");
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
return token;
|
|
|
|
}
|