Commit 7335a9b6 authored by Paolo Maggi's avatar Paolo Maggi Committed by Paolo Maggi

Fixed bug #333129 – [Multihead] cannot launch multiple instances of

2006-03-03  Paolo Maggi  <paolo@gnome.org>

	Fixed bug #333129 – [Multihead] cannot launch multiple instances
of
	                    gedit on different heads

	* gedit/gedit-app.c (gedit_app_create_window): added screen
argument
	(is_in_workspace): new function
	(_gedit_app_get_window_in_workspace): fixed to me multihead
aware

	* gedit/gedit-app.h: updated gedit_app_create_window prototype

	* gedit/gedit-window.c (clone_window): update to call
	gedit_app_create_window with a screen parameter

	* gedit/gedit.c (on_message_received) (send_bacon_message)
(main):
	updated the client/server protocol used to support single
application
	instances so that display name and screen number are
communicated from
	client to server

	* bindings/python/gedit.defs:
	* bindings/python/gedit.override: updated binding for
create_window(),
	overridden so that the screen param is optional
parent fa9b44b9
2006-03-03 Paolo Maggi <paolo@gnome.org>
Fixed bug #333129 – [Multihead] cannot launch multiple instances of
gedit on different heads
* gedit/gedit-app.c (gedit_app_create_window): added screen argument
(is_in_workspace): new function
(_gedit_app_get_window_in_workspace): fixed to me multihead aware
* gedit/gedit-app.h: updated gedit_app_create_window prototype
* gedit/gedit-window.c (clone_window): update to call
gedit_app_create_window with a screen parameter
* gedit/gedit.c (on_message_received) (send_bacon_message) (main):
updated the client/server protocol used to support single application
instances so that display name and screen number are communicated from
client to server
* bindings/python/gedit.defs:
* bindings/python/gedit.override: updated binding for create_window(),
overridden so that the screen param is optional
2006-03-02 Steve Frécinaux <steve@istique.net>
* plugins/modelines/modelines.py:
......
......@@ -126,6 +126,9 @@
(of-object "GeditApp")
(c-name "gedit_app_create_window")
(return-type "GeditWindow*")
(parameters
'("GdkScreen*" "screen")
)
)
(define-method get_windows
......
......@@ -37,7 +37,8 @@ _helper_wrap_gobject_glist (const GList *list)
modulename gedit
%%
import gtk.Widget as PyGtkWidget_Type
import gobject.GObject as PyGObject_Type
import gobject.GObject as PyGObject_Type
import gtk.gdk.Screen as PyGdkScreen_Type
import gtk.VBox as PyGtkVBox_Type
import gtk.Window as PyGtkWindow_Type
import gtk.Image as PyGtkImage_Type
......@@ -50,6 +51,26 @@ ignore-glob
gedit_document_error_quark
gedit_panel_add_item_with_stock_icon
%%
override gedit_app_create_window kwargs
static PyObject *
_wrap_gedit_app_create_window(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "screen", NULL};
PyGObject *screen = NULL;
GeditWindow *ret;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"|O!", kwlist,
&PyGdkScreen_Type, &screen))
return NULL;
ret = gedit_app_create_window(GEDIT_APP(self->obj),
screen ? GDK_SCREEN(screen->obj) : NULL);
/* pygobject_new handles NULL checking */
return pygobject_new((GObject *)ret);
}
%%
override gedit_app_get_windows
static PyObject *
_wrap_gedit_app_get_windows(PyGObject *self)
......
......@@ -32,6 +32,8 @@
#include <config.h>
#endif
#include <string.h>
#include <glib/gi18n.h>
#include "gedit-app.h"
......@@ -273,9 +275,17 @@ gedit_app_create_window_real (GeditApp *app,
}
GeditWindow *
gedit_app_create_window (GeditApp *app)
gedit_app_create_window (GeditApp *app,
GdkScreen *screen)
{
return gedit_app_create_window_real (app, TRUE, NULL);
GeditWindow *window;
window = gedit_app_create_window_real (app, TRUE, NULL);
if (screen != NULL)
gtk_window_set_screen (GTK_WINDOW (window), screen);
return window;
}
/*
......@@ -317,12 +327,42 @@ gedit_app_get_active_window (GeditApp *app)
return app->priv->active_window;
}
static gboolean
is_in_workspace (GeditWindow *window,
GdkScreen *screen,
gint workspace)
{
GdkScreen *s;
GdkDisplay *display;
const gchar *cur_name;
const gchar *name;
gint cur_n;
gint n;
gint ws;
display = gdk_screen_get_display (screen);
cur_name = gdk_display_get_name (display);
cur_n = gdk_screen_get_number (screen);
s = gtk_window_get_screen (GTK_WINDOW (window));
display = gdk_screen_get_display (s);
name = gdk_display_get_name (display);
n = gdk_screen_get_number (s);
ws = gedit_utils_get_window_workspace (GTK_WINDOW (window));
return ((strcmp (cur_name, name) == 0) && cur_n == n &&
(ws == workspace || ws == GEDIT_ALL_WORKSPACES));
}
GeditWindow *
_gedit_app_get_window_in_workspace (GeditApp *app,
gint workspace)
_gedit_app_get_window_in_workspace (GeditApp *app,
GdkScreen *screen,
gint workspace)
{
GeditWindow *window;
gint ws;
GList *l;
g_return_val_if_fail (GEDIT_IS_APP (app), NULL);
......@@ -330,29 +370,21 @@ _gedit_app_get_window_in_workspace (GeditApp *app,
window = app->priv->active_window;
g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
ws = gedit_utils_get_window_workspace (GTK_WINDOW (window));
if (ws != workspace && ws != GEDIT_ALL_WORKSPACES)
{
GList *l;
/* try to see if there is a window on this workspace */
l = app->priv->windows;
while (l != NULL)
{
ws = gedit_utils_get_window_workspace (GTK_WINDOW (l->data));
if (ws == workspace || ws == GEDIT_ALL_WORKSPACES)
break;
if (is_in_workspace (window, screen, workspace))
return window;
l = g_list_next (l);
}
/* otherwise try to see if there is a window on this workspace */
for (l = app->priv->windows; l != NULL; l = l->next)
{
window = l->data;
/* no window on this workspace... create a new one */
if (l == NULL)
window = gedit_app_create_window (app);
if (is_in_workspace (window, screen, workspace))
return window;
}
return window;
/* no window on this workspace... create a new one */
return gedit_app_create_window (app, screen);
}
/* Returns a newly allocated list with all the documents */
......
......@@ -81,7 +81,8 @@ GType gedit_app_get_type (void) G_GNUC_CONST;
GeditApp *gedit_app_get_default (void);
GeditWindow *gedit_app_create_window (GeditApp *app);
GeditWindow *gedit_app_create_window (GeditApp *app,
GdkScreen *screen);
const GList *gedit_app_get_windows (GeditApp *app);
GeditWindow *gedit_app_get_active_window (GeditApp *app);
......@@ -97,8 +98,9 @@ GList *gedit_app_get_views (GeditApp *app);
*/
GeditWindow *_gedit_app_restore_window (GeditApp *app,
const gchar *role);
GeditWindow *_gedit_app_get_window_in_workspace (GeditApp *app,
gint workspace);
GeditWindow *_gedit_app_get_window_in_workspace (GeditApp *app,
GdkScreen *screen,
gint workspace);
G_END_DECLS
......
......@@ -1337,14 +1337,16 @@ static GeditWindow *
clone_window (GeditWindow *origin)
{
GtkWindow *window;
GdkScreen *screen;
GeditApp *app;
gedit_debug (DEBUG_WINDOW);
app = gedit_app_get_default ();
window = GTK_WINDOW (gedit_app_create_window (app));
screen = gtk_window_get_screen (GTK_WINDOW (origin));
window = GTK_WINDOW (gedit_app_create_window (app, screen));
gtk_window_set_default_size (window,
origin->priv->width,
origin->priv->height);
......
......@@ -177,9 +177,13 @@ on_message_received (const char *message,
gchar **commands;
gchar **params;
gint workspace;
gchar *display_name;
gint screen_number;
gint i;
GeditApp *app;
GeditWindow *window;
GdkDisplay *display;
GdkScreen *screen;
g_return_if_fail (message != NULL);
......@@ -188,9 +192,16 @@ on_message_received (const char *message,
commands = g_strsplit (message, "\v", -1);
/* header */
params = g_strsplit (commands[0], "\t", 2);
startup_timestamp = atoi (params[0]); //CHECK if this is safe
workspace = atoi (params[1]);
params = g_strsplit (commands[0], "\t", 4);
startup_timestamp = atoi (params[0]); /* CHECK if this is safe */
display_name = g_strdup (params[1]);
screen_number = atoi (params[2]);
workspace = atoi (params[3]);
display = gdk_display_open (display_name);
screen = gdk_display_get_screen (display, screen_number);
g_free (display_name);
g_strfreev (params);
/* body */
......@@ -244,12 +255,14 @@ on_message_received (const char *message,
if (new_window_option)
{
window = gedit_app_create_window (app);
window = gedit_app_create_window (app, screen);
}
else
{
/* get a window in the current workspace (if exists) and raise it */
window = _gedit_app_get_window_in_workspace (app, workspace);
window = _gedit_app_get_window_in_workspace (app,
screen,
workspace);
}
if (file_list != NULL)
......@@ -305,12 +318,16 @@ on_message_received (const char *message,
static void
send_bacon_message (void)
{
GdkScreen *screen;
GdkDisplay *display;
const gchar *display_name;
gint screen_number;
gint ws;
GString *command;
/* the messages have the following format:
* <---- header -----> <---- body ----->
* timestamp \t workspace \v OP1 \t arg \t arg \v OP2 \t arg \t arg|...
* <--- header ---> <---- body ----->
* timestamp \t display_name \t screen_number \t workspace \v OP1 \t arg \t arg \v OP2 \t arg \t arg|...
*
* when the arg is a list of uri, they are separated by a space.
* So the delimiters are \v for the commands, \t for the tokens in
......@@ -318,14 +335,27 @@ send_bacon_message (void)
* be part of an uri, this way parsing is easier.
*/
ws = gedit_utils_get_current_workspace (gdk_screen_get_default ());
gedit_debug (DEBUG_APP);
screen = gdk_screen_get_default ();
display = gdk_screen_get_display (screen);
display_name = gdk_display_get_name (display);
screen_number = gdk_screen_get_number (screen);
gedit_debug_message (DEBUG_APP, "Display: %s", display_name);
gedit_debug_message (DEBUG_APP, "Screen: %d", screen_number);
ws = gedit_utils_get_current_workspace (screen);
command = g_string_new (NULL);
/* header */
g_string_append_printf (command,
"%" G_GUINT32_FORMAT "\t%d",
"%" G_GUINT32_FORMAT "\t%s\t%d\t%d",
startup_timestamp,
display_name,
screen_number,
ws);
/* NEW-WINDOW command */
......@@ -364,6 +394,8 @@ send_bacon_message (void)
}
}
gedit_debug_message (DEBUG_APP, "Bacon Message: %s", command->str);
bacon_message_connection_send (connection,
command->str);
......@@ -482,8 +514,8 @@ main (int argc, char *argv[])
app = gedit_app_get_default ();
gedit_debug_message (DEBUG_APP, "Create main window");
window = gedit_app_create_window (app);
window = gedit_app_create_window (app, NULL);
if (file_list != NULL)
{
gedit_debug_message (DEBUG_APP, "Load files");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment