[gnome-terminal/gsettings] Move common code to terminal-client-utils.c
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal/gsettings] Move common code to terminal-client-utils.c
- Date: Fri, 25 Nov 2011 19:04:32 +0000 (UTC)
commit 6e82870e77cf19348fc0c8a62213aa3a1ceaa755
Author: Christian Persch <chpe gnome org>
Date: Fri Nov 25 20:02:59 2011 +0100
Move common code to terminal-client-utils.c
src/client.c | 59 +---------------------------------------
src/terminal-client-utils.c | 63 +++++++++++++++++++++++++++++++++++++++++++
src/terminal-client-utils.h | 2 +
src/terminal.c | 61 +----------------------------------------
4 files changed, 67 insertions(+), 118 deletions(-)
---
diff --git a/src/client.c b/src/client.c
index d763031..99959cf 100644
--- a/src/client.c
+++ b/src/client.c
@@ -35,7 +35,6 @@
#include <gio/gio.h>
#include <gtk/gtk.h>
-#include <gdk/gdkx.h>
#include "terminal-intl.h"
#include "terminal-gdbus-generated.h"
@@ -138,62 +137,6 @@ modify_argv0_for_command (gint *argc, gchar **argv[], const gchar *command)
g_free (program_name);
}
-/* ---------------------------------------------------------------------------------------------------- */
-
-/* Copied from libnautilus/nautilus-program-choosing.c; Needed in case
- * we have no DESKTOP_STARTUP_ID (with its accompanying timestamp).
- */
-static char *
-slowly_and_stupidly_obtain_timestamp (void)
-{
- Display *xdisplay;
- Window xwindow;
- XEvent event;
-
- xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
-
- {
- XSetWindowAttributes attrs;
- Atom atom_name;
- Atom atom_type;
- const char *name;
-
- attrs.override_redirect = True;
- attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
-
- xwindow =
- XCreateWindow (xdisplay,
- RootWindow (xdisplay, 0),
- -100, -100, 1, 1,
- 0,
- CopyFromParent,
- CopyFromParent,
- (Visual *)CopyFromParent,
- CWOverrideRedirect | CWEventMask,
- &attrs);
-
- atom_name = XInternAtom (xdisplay, "WM_NAME", TRUE);
- g_assert (atom_name != None);
- atom_type = XInternAtom (xdisplay, "STRING", TRUE);
- g_assert (atom_type != None);
-
- name = "Fake Window";
- XChangeProperty (xdisplay,
- xwindow, atom_name,
- atom_type,
- 8, PropModeReplace, (unsigned char *)name, strlen (name));
- }
-
- XWindowEvent (xdisplay,
- xwindow,
- PropertyChangeMask,
- &event);
-
- XDestroyWindow(xdisplay, xwindow);
-
- return g_strdup_printf ("_TIME%lu", event.xproperty.time);
-}
-
typedef struct
{
/* Window options */
@@ -395,7 +338,7 @@ parse_arguments (int *argcp,
/* Do this here so that gdk_display is initialized */
if (data->startup_id == NULL)
- data->startup_id = slowly_and_stupidly_obtain_timestamp ();
+ terminal_client_get_fallback_startup_id (&data->startup_id);
data->display_name = gdk_display_get_name (gdk_display_get_default ());
diff --git a/src/terminal-client-utils.c b/src/terminal-client-utils.c
index 800b7cf..166b033 100644
--- a/src/terminal-client-utils.c
+++ b/src/terminal-client-utils.c
@@ -1,4 +1,8 @@
/*
+ * Copyright  2001, 2002 Havoc Pennington
+ * Copyright  2002 Red Hat, Inc.
+ * Copyright  2002 Sun Microsystems
+ * Copyright  2003 Mariano Suarez-Alvarez
* Copyright  2011 Christian Persch
*
* This programme is free software; you can redistribute it and/or
@@ -21,7 +25,10 @@
#include "terminal-client-utils.h"
+#include <string.h>
+
#include <gio/gio.h>
+#include <gdk/gdkx.h>
/**
* terminal_client_append_create_instance_options:
@@ -106,3 +113,59 @@ terminal_client_append_exec_options (GVariantBuilder *builder,
g_strfreev (envv);
}
+
+/**
+ * terminal_client_get_fallback_startup_id:
+ * @startup_id: (inout):
+ */
+void
+terminal_client_get_fallback_startup_id (char **startup_id)
+{
+ Display *xdisplay;
+ Window xwindow;
+ XEvent event;
+
+ xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+
+ {
+ XSetWindowAttributes attrs;
+ Atom atom_name;
+ Atom atom_type;
+ const char *name;
+
+ attrs.override_redirect = True;
+ attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
+
+ xwindow =
+ XCreateWindow (xdisplay,
+ RootWindow (xdisplay, 0),
+ -100, -100, 1, 1,
+ 0,
+ CopyFromParent,
+ CopyFromParent,
+ (Visual *)CopyFromParent,
+ CWOverrideRedirect | CWEventMask,
+ &attrs);
+
+ atom_name = XInternAtom (xdisplay, "WM_NAME", TRUE);
+ g_assert (atom_name != None);
+ atom_type = XInternAtom (xdisplay, "STRING", TRUE);
+ g_assert (atom_type != None);
+
+ name = "Fake Window";
+ XChangeProperty (xdisplay,
+ xwindow, atom_name,
+ atom_type,
+ 8, PropModeReplace, (unsigned char *)name, strlen (name));
+ }
+
+ XWindowEvent (xdisplay,
+ xwindow,
+ PropertyChangeMask,
+ &event);
+
+ XDestroyWindow(xdisplay, xwindow);
+
+ if (startup_id)
+ *startup_id = g_strdup_printf ("_TIME%lu", event.xproperty.time);
+}
diff --git a/src/terminal-client-utils.h b/src/terminal-client-utils.h
index d7c95d9..14a1693 100644
--- a/src/terminal-client-utils.h
+++ b/src/terminal-client-utils.h
@@ -37,6 +37,8 @@ void terminal_client_append_create_instance_options (GVariantBuilder *builder,
void terminal_client_append_exec_options (GVariantBuilder *builder,
const char *working_directory);
+void terminal_client_get_fallback_startup_id (char **startup_id);
+
G_END_DECLS
#endif /* TERMINAL_UTIL_UTILS_H */
diff --git a/src/terminal.c b/src/terminal.c
index c6e9f0a..5d92afc 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -32,7 +32,6 @@
#include <gio/gio.h>
#include <gtk/gtk.h>
-#include <gdk/gdkx.h>
#include "terminal-debug.h"
#include "terminal-intl.h"
@@ -226,57 +225,6 @@ handle_options (TerminalFactory *factory,
return TRUE;
}
-/* Copied from libnautilus/nautilus-program-choosing.c; Needed in case
- * we have no DESKTOP_STARTUP_ID (with its accompanying timestamp).
- */
-static Time
-slowly_and_stupidly_obtain_timestamp (Display *xdisplay)
-{
- Window xwindow;
- XEvent event;
-
- {
- XSetWindowAttributes attrs;
- Atom atom_name;
- Atom atom_type;
- const char *name;
-
- attrs.override_redirect = True;
- attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
-
- xwindow =
- XCreateWindow (xdisplay,
- RootWindow (xdisplay, 0),
- -100, -100, 1, 1,
- 0,
- CopyFromParent,
- CopyFromParent,
- (Visual *)CopyFromParent,
- CWOverrideRedirect | CWEventMask,
- &attrs);
-
- atom_name = XInternAtom (xdisplay, "WM_NAME", TRUE);
- g_assert (atom_name != None);
- atom_type = XInternAtom (xdisplay, "STRING", TRUE);
- g_assert (atom_type != None);
-
- name = "Fake Window";
- XChangeProperty (xdisplay,
- xwindow, atom_name,
- atom_type,
- 8, PropModeReplace, (unsigned char *)name, strlen (name));
- }
-
- XWindowEvent (xdisplay,
- xwindow,
- PropertyChangeMask,
- &event);
-
- XDestroyWindow(xdisplay, xwindow);
-
- return event.xproperty.time;
-}
-
int
main (int argc, char **argv)
{
@@ -325,14 +273,7 @@ main (int argc, char **argv)
/* Do this here so that gdk_display is initialized */
if (options->startup_id == NULL)
- {
- /* Create a fake one containing a timestamp that we can use */
- Time timestamp;
-
- timestamp = slowly_and_stupidly_obtain_timestamp (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
-
- options->startup_id = g_strdup_printf ("_TIME%lu", timestamp);
- }
+ terminal_client_get_fallback_startup_id (&options->startup_id);
display = gdk_display_get_default ();
display_name = gdk_display_get_name (display);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]