Commit 550bf181 authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor

Add a --screen option for setting the default screen. (Based on a patch

Thu Oct 31 12:40:39 2002  Owen Taylor  <otaylor@redhat.com>

        * gdk/gdk.[ch] gdk/gdkglobals.c gdk/gdkinternals.h
        gdk/{x11,win32,linux-fb}/gdkscreen-{x11,win32,linux-fb}.c:
        Add a --screen option for setting the default screen.
        (Based on a patch from Balamurali Viswanathan, #81145)

        * gdk/gdk.c gdkdisplay.h gtk/gtkmain.c: Add
        gdk_display_open_default_libgtk_only(), so gtk_init_check()
        and gdk_init_check() can share the same behavior w.r.t.
        --screen.

        * gdk/gdk.[ch]: Make gdk_get_display_arg_name() G_CONST_RETURN.

        * gdk/x11/gdkselection-x11.c (gdk_selection_property_get):
        Suppress a spurious warning.

        * tests/testgtkrc: Remove someleft-over commented out
        includes that could be confusing.
parent 089a3882
......@@ -239,6 +239,7 @@ static GdkArgDesc gdk_args[] = {
{ "class" , GDK_ARG_CALLBACK, NULL, gdk_arg_class_cb },
{ "name", GDK_ARG_CALLBACK, NULL, gdk_arg_name_cb },
{ "display", GDK_ARG_STRING, &_gdk_display_name, (GdkArgFunc)NULL },
{ "screen", GDK_ARG_INT, &_gdk_screen_number, (GdkArgFunc)NULL },
#ifdef G_ENABLE_DEBUG
{ "gdk-debug", GDK_ARG_CALLBACK, NULL, gdk_arg_debug_cb },
......@@ -355,11 +356,60 @@ gdk_parse_args (int *argc,
* to gdk_init() or gdk_parse_args(), if any.
*
* Returns: the display name, if specified explicitely, otherwise %NULL
* this string is owned by GTK+ and must not be modified or freed.
*/
gchar *
G_CONST_RETURN gchar *
gdk_get_display_arg_name (void)
{
return _gdk_display_name;
if (!_gdk_display_arg_name)
{
if (_gdk_screen_number >= 0)
_gdk_display_arg_name = _gdk_windowing_substitute_screen_number (_gdk_display_name, _gdk_screen_number);
else
_gdk_display_arg_name = g_strdup (_gdk_display_name);
}
return _gdk_display_arg_name;
}
/**
* gdk_display_open_default_libgtk_only:
*
* Opens the default display specified by command line arguments or
* environment variables, sets it as the default display, and returns
* it. gdk_parse_args must have been called first. If the default
* display has previously been set, simply returns that. An internal
* function that should not be used by applications.
*
* Return value: the default display, if it could be opened,
* otherwise %NULL.
**/
GdkDisplay *
gdk_display_open_default_libgtk_only (void)
{
GdkDisplay *display;
g_return_if_fail (gdk_initialized);
display = gdk_display_get_default ();
if (display)
return display;
display = gdk_display_open (gdk_get_display_arg_name ());
if (!display && _gdk_screen_number >= 0)
{
g_free (_gdk_display_arg_name);
_gdk_display_arg_name = g_strdup (_gdk_display_name);
display = gdk_display_open (_gdk_display_name);
}
if (display)
gdk_display_manager_set_default_display (gdk_display_manager_get (),
display);
return display;
}
/*
......@@ -392,19 +442,7 @@ gdk_init_check (int *argc,
gdk_parse_args (argc, argv);
if (gdk_display_get_default ())
return TRUE;
display = gdk_display_open (_gdk_display_name);
if (display)
{
gdk_display_manager_set_default_display (gdk_display_manager_get (),
display);
return TRUE;
}
else
return FALSE;
return gdk_display_open_default_libgtk_only () != NULL;
}
void
......
......@@ -85,8 +85,8 @@ void gdk_set_use_xshm (gboolean use_xshm);
gboolean gdk_get_use_xshm (void);
#endif /* GDK_DISABLE_DEPRECATED */
gchar* gdk_get_display (void);
gchar* gdk_get_display_arg_name (void);
gchar* gdk_get_display (void);
G_CONST_RETURN gchar* gdk_get_display_arg_name (void);
#ifndef GDK_DISABLE_DEPRECATED
gint gdk_input_add_full (gint source,
......
......@@ -146,6 +146,8 @@ GdkWindow * gdk_display_get_window_at_pointer (GdkDisplay *disp
GdkDisplayPointerHooks *gdk_display_set_pointer_hooks (GdkDisplay *display,
const GdkDisplayPointerHooks *new_hooks);
GdkDisplay *gdk_display_open_default_libgtk_only (void);
G_END_DECLS
#endif /* __GDK_DISPLAY_H__ */
......@@ -35,6 +35,8 @@ gint _gdk_error_code = 0;
gint _gdk_error_warnings = TRUE;
GList *_gdk_default_filters = NULL;
gchar *_gdk_display_name = NULL;
gint _gdk_screen_number = -1;
gchar *_gdk_display_arg_name = NULL;
GSList *_gdk_displays = NULL;
......
......@@ -166,6 +166,8 @@ extern GDestroyNotify _gdk_event_notify;
extern GSList *_gdk_displays;
extern gchar *_gdk_display_name;
extern gint _gdk_screen_number;
extern gchar *_gdk_display_arg_name;
void _gdk_events_queue (GdkDisplay *display);
GdkEvent* _gdk_event_unqueue (GdkDisplay *display);
......@@ -236,6 +238,9 @@ void _gdk_windowing_init (gint *argc,
gchar ***argv);
void _gdk_windowing_set_default_display (GdkDisplay *display);
gchar *_gdk_windowing_substitute_screen_number (const gchar *display_name,
gint screen_number);
void _gdk_windowing_window_get_offsets (GdkWindow *window,
gint *x_offset,
gint *y_offset);
......
......@@ -73,7 +73,6 @@ GList * gdk_screen_list_visuals (GdkScreen *screen);
GList * gdk_screen_get_toplevel_windows (GdkScreen *screen);
gchar * gdk_screen_make_display_name (GdkScreen *screen);
gint gdk_screen_get_n_monitors (GdkScreen *screen);
void gdk_screen_get_monitor_geometry (GdkScreen *screen,
gint monitor_num,
......
......@@ -79,6 +79,13 @@ gdk_screen_get_number (GdkScreen *screen)
return 0;
}
gchar *
_gdk_windowing_substitute_screen_number (gchar *display_name,
int screen_number)
{
return g_strdup (display_name);
}
gchar *
gdk_screen_make_display_name (GdkScreen *screen)
{
......
......@@ -81,6 +81,13 @@ gdk_screen_get_number (GdkScreen *screen)
return 0;
}
gchar *
_gdk_windowing_substitute_screen_number (gchar *display_name,
int screen_number)
{
return g_strdup (display_name);
}
gchar *
gdk_screen_make_display_name (GdkScreen *screen)
{
......
......@@ -551,6 +551,45 @@ _gdk_x11_screen_window_manager_changed (GdkScreen *screen)
signals[WINDOW_MANAGER_CHANGED], 0);
}
/**
* _gdk_windowing_substitute_screen_number:
* @display_name : The name of a display, in the form used by
* gdk_display_open (). If %NULL a default value
* will be used. On X11, this is derived from the DISPLAY
* environment variable.
* @screen_number : The number of a screen within the display
* referred to by @display_name.
*
* Modifies a @display_name to make @screen_number the default
* screen when the display is opened.
*
* Return value: a newly allocated string holding the resulting
* display name. Free with g_free().
*/
gchar *
_gdk_windowing_substitute_screen_number (const gchar *display_name,
gint screen_number)
{
GString *str;
gchar *p;
if (!display_name)
display_name = getenv ("DISPLAY");
if (!display_name)
return NULL;
str = g_string_new (display_name);
p = strrchr (str->str, '.');
if (p && p > strchr (str->str, ':'))
g_string_truncate (str, p - str->str);
g_string_append_printf (str, ".%d", screen_number);
return g_string_free (str, FALSE);
}
/**
* gdk_screen_make_display_name:
* @screen: a #GdkScreen
......@@ -563,20 +602,12 @@ _gdk_x11_screen_window_manager_changed (GdkScreen *screen)
gchar *
gdk_screen_make_display_name (GdkScreen *screen)
{
GString *str;
const gchar *old_display;
gchar *p;
old_display = gdk_display_get_name (gdk_screen_get_display (screen));
str = g_string_new (old_display);
p = strrchr (str->str, '.');
if (p && p > strchr (str->str, ':'))
g_string_truncate (str, p - str->str);
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
g_string_append_printf (str, ".%d", gdk_screen_get_number (screen));
old_display = gdk_display_get_name (gdk_screen_get_display (screen));
return g_string_free (str, FALSE);
return _gdk_windowing_substitute_screen_number (old_display,
gdk_screen_get_number (screen));
}
......@@ -261,7 +261,7 @@ gdk_selection_property_get (GdkWindow *requestor,
{
gulong nitems;
gulong nbytes;
gulong length;
gulong length = 0; /* Quiet GCC */
Atom prop_type;
gint prop_format;
guchar *t = NULL;
......
......@@ -871,19 +871,7 @@ gtk_init_check (int *argc,
if (!gtk_parse_args (argc, argv))
return FALSE;
if (gdk_display_get_default ())
return TRUE;
display = gdk_display_open (gdk_get_display_arg_name ());
if (display)
{
gdk_display_manager_set_default_display (gdk_display_manager_get (),
display);
return TRUE;
}
else
return FALSE;
return gdk_display_open_default_libgtk_only () != NULL;
}
#undef gtk_init
......
......@@ -13,10 +13,6 @@
# testgtkrc2 sets all the buttons in the main window to blue by default
include "testgtkrc2"
#include "/usr/local/share/themes/Redmond95/gtk-2.0/gtkrc"
#include "/usr/local/share/themes/Metal/gtk-2.0/gtkrc"
#include "/usr/local/share/themes/Default/gtk-2.0/gtkrc"
double-click_timeout = 42
bell-duration = 39
bell_duration = 40
......
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