A
download multiscreen-stuff.c
Language: C
License: GPL
Copyright: (C) 2001 George Lebl
LOC: 146
Project Info
gnome-core
Server: Gnome
Type: cvs
...nome‑core\gnome‑core\panel\
   .cvsignore
   aligned-widget.c
   aligned-widget.h
   applet.c
   applet.h
   basep-widget.c
   basep-widget.h
   border-widget.c
   border-widget.h
   button-widget.c
   button-widget.h
   distribution.c
   distribution.h
   drawer-widget.c
   drawer-widget.h
   drawer.c
   drawer.h
   edge-widget.c
   edge-widget.h
   floating-widget.c
   floating-widget.h
   foobar-widget.c
   foobar-widget.h
   global-keys.c
   global-keys.h
   gnome-panel-add-launcher.c
   gnome-panel-properties.c
   ...l-properties.desktop.in
   ...-panel-properties.glade
   gnome-panel-screenshot.c
   ...-panel-screenshot.glade
   gnome-run.c
   gnome-run.h
   GNOME_Panel.server.in
   launcher.c
   launcher.h
   logout.c
   logout.h
   main.c
   Makefile.am
   menu-fentry.c
   menu-fentry.h
   menu-properties.c
   menu-properties.h
   menu-util.c
   menu-util.h
   menu.c
   menu.h
   multiscreen-stuff.c
   multiscreen-stuff.h
   nothing.cP
   nothing.h
   panel-applet-frame.c
   panel-applet-frame.h
   panel-config-global.h
   panel-config.c
   panel-config.h
   panel-gconf.c
   panel-gconf.h
   ...l-global-config.schemas
   panel-main.h
   panel-marshal.list
   ...er-panel-config.schemas
   panel-shell.c
   panel-shell.h
   panel-types.h
   panel-util.c
   panel-util.h
   panel-widget.c
   panel-widget.h
   panel.c
   panel.h
   panel.hints
   quick-desktop-reader.c
   quick-desktop-reader.h
   rgb-stuff.c
   rgb-stuff.h
   session.c
   session.h
   sliding-widget.c
   sliding-widget.h
   status-docklet.c
   status-docklet.h
   status.c
   status.h
   swallow.c
   swallow.h
   TODO.old
   xstuff.c
   xstuff.h

/*
 *   multiscreen-stuff: Xinerama (and in the future multidisplay)
 *   support for the panel
 *
 *   Copyright (C) 2001 George Lebl <jirka@5z.com>
 *
 * 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 <X11/X.h>
#include <X11/Xlib.h>
#include <gdk/gdkx.h>
#ifdef HAVE_LIBXINERAMA
#include <X11/extensions/Xinerama.h>
#endif

#include "multiscreen-stuff.h"

#include "foobar-widget.h"
#include "basep-widget.h"

/* some globals */
static int		screens = 1;
static GdkRectangle *	rectangles = NULL;
static gboolean		initialized = FALSE;

void
multiscreen_init (void)
{
#ifdef HAVE_LIBXINERAMA
	gboolean have_xinerama = FALSE;
#endif

	if (initialized)
		return;

	if (g_getenv ("FAKE_XINERAMA_PANEL") != NULL) {
		/* fake xinerama setup for debugging */
		screens = 2;
		rectangles = g_new0 (GdkRectangle, 2);
		rectangles[0].x = 0;
		rectangles[0].y = 0;
		rectangles[0].width = gdk_screen_width () / 2;
		rectangles[0].height = gdk_screen_height () / 2;
		rectangles[1].x = gdk_screen_width () / 2;
		rectangles[1].y = gdk_screen_height () / 2;
		rectangles[1].width = gdk_screen_width () - rectangles[0].x;
		rectangles[1].height = gdk_screen_height () - rectangles[0].y;

		initialized = TRUE;

		return;
	}

#ifdef HAVE_LIBXINERAMA
	gdk_flush ();
	gdk_error_trap_push ();
	have_xinerama = XineramaIsActive (GDK_DISPLAY ());
	gdk_flush ();
	if (gdk_error_trap_pop () != 0)
		have_xinerama = FALSE;

	if (have_xinerama) {
		int screen_num, i;
		XineramaScreenInfo *xscreens =
			XineramaQueryScreens (GDK_DISPLAY (),
					      &screen_num);


		if (screen_num <= 0) {
			/* EEEEEK!, should never happen */
			goto no_xinerama;
		}

		rectangles = g_new0 (GdkRectangle, screen_num);
		screens = screen_num;

		for (i = 0; i < screen_num; i++) {
			rectangles[i].x = xscreens[i].x_org;
			rectangles[i].y = xscreens[i].y_org;
			rectangles[i].width = xscreens[i].width;
			rectangles[i].height = xscreens[i].height;
		}

		XFree (xscreens);
	} else
#endif
	{
#ifdef HAVE_LIBXINERAMA
no_xinerama:
#endif
		/* no xinerama */
		screens = 1;
		rectangles = g_new0 (GdkRectangle, 1);
		rectangles[0].x = 0;
		rectangles[0].y = 0;
		rectangles[0].width = gdk_screen_width ();
		rectangles[0].height = gdk_screen_height ();
	}

	initialized = TRUE;
}

int
multiscreen_screens (void)
{
	g_return_val_if_fail (initialized, 1);

	return screens;
}

int
multiscreen_x (int screen)
{
	g_return_val_if_fail (initialized, 0);
	g_return_val_if_fail (screen >= 0, 0);

	if (screen < screens)
		return rectangles[screen].x;
	else
		return gdk_screen_width () + 10;
}

int
multiscreen_y (int screen)
{
	g_return_val_if_fail (initialized, 0);
	g_return_val_if_fail (screen >= 0, 0);

	if (screen < screens)
		return rectangles[screen].y;
	else
		return gdk_screen_height () + 10;
}

int
multiscreen_width (int screen)
{
	g_return_val_if_fail (initialized, 0);
	g_return_val_if_fail (screen >= 0, 0);

	if (screen < screens)
		return rectangles[screen].width;
	else
		return gdk_screen_width ();
}

int
multiscreen_height (int screen)
{
	g_return_val_if_fail (initialized, 0);
	g_return_val_if_fail (screen >= 0, 0);

	if (screen < screens)
		return rectangles[screen].height;
	else
		return gdk_screen_height ();
}

int
multiscreen_screen_from_pos (int x, int y)
{
	int i;
	for (i = 0; i < screens; i++) {
		if (x >= rectangles[i].x &&
		    x <= rectangles[i].x + rectangles[i].width &&
		    y >= rectangles[i].y &&
		    y <= rectangles[i].y + rectangles[i].height)
			return i;
	}
	return -1;
}

int
multiscreen_screen_from_panel (GtkWidget *widget)
{
	g_return_val_if_fail (widget != NULL, 0);
	g_return_val_if_fail (BASEP_IS_WIDGET (widget) ||
			      FOOBAR_IS_WIDGET (widget), 0);
	
	if (BASEP_IS_WIDGET (widget))
		return BASEP_WIDGET (widget)->screen;
	else if (FOOBAR_IS_WIDGET (widget))
		return FOOBAR_WIDGET (widget)->screen;
	else
		return 0;
}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us