2004-04-16 Boyd Timothy <btimothy@novell.com>

* gdk/Global.custom : properties to expose window manager spec
	properties.
	* gdk/glue/windowmanager.c : glue to retrieve window manager props
	using gdk_property_get.
	* gdk/glue/Makefile.am : add new file.
	* gdk/glue/makefile.win32 : add new file.

svn path=/trunk/gtk-sharp/; revision=25611
This commit is contained in:
Mike Kestner 2004-04-16 17:31:30 +00:00
parent 3595f79bc3
commit ed507416b2
5 changed files with 362 additions and 2 deletions

View File

@ -1,3 +1,12 @@
2004-04-16 Boyd Timothy <btimothy@novell.com>
* gdk/Global.custom : properties to expose window manager spec
properties.
* gdk/glue/windowmanager.c : glue to retrieve window manager props
using gdk_property_get.
* gdk/glue/Makefile.am : add new file.
* gdk/glue/makefile.win32 : add new file.
2004-04-13 Mike Kestner <mkestner@ximian.com>
* glib/Value.cs : fix a csc-breaker.

View File

@ -1,6 +1,7 @@
// Global.custom - customizations to Gdk.Global
//
// Authors: Mike Kestner <mkestner@ximian.com>
// Boyd Timothy <btimothy@novell.com>
//
// Copyright (c) 2004 Novell, Inc.
@ -34,3 +35,89 @@
return result;
}
[DllImport ("gdksharpglue")]
static extern IntPtr gtksharp_get_gdk_net_supported ();
public static Gdk.Atom[] SupportedWindowManagerHints {
get {
IntPtr raw_ret = gtksharp_get_gdk_net_supported ();
if (raw_ret == IntPtr.Zero)
return new Gdk.Atom [0];
GLib.List list = new GLib.List (raw_ret, typeof (Gdk.Atom));
Gdk.Atom[] atoms = new Gdk.Atom [list.Count];
for (int i = 0; i < list.Count; i++)
atoms [i] = list [i] as Gdk.Atom;
return atoms;
}
}
[DllImport ("gdksharpglue")]
static extern IntPtr gtksharp_get_gdk_net_client_list (out int count);
public static Gdk.Window[] WindowManagerClientWindows {
get {
int count;
IntPtr raw_ret = gtksharp_get_gdk_net_client_list (out count);
if (raw_ret == IntPtr.Zero)
return new Gdk.Window [0];
Gdk.Window [] windows = new Gdk.Window [count];
int offset = 0;
for (int i = 0; i < count; i++) {
int windowID = Marshal.ReadInt32 (raw_ret, offset);
Console.WriteLine ("WinID: {0}", windowID);
offset += IntPtr.Size;
windows [i] = Gdk.Window.ForeignNew ((uint) windowID);
}
return windows;
}
}
[DllImport ("gdksharpglue")]
static extern int gtksharp_get_gdk_net_number_of_desktops ();
public static int NumberOfDesktops {
get {
return gtksharp_get_gdk_net_number_of_desktops ();
}
}
[DllImport ("gdksharpglue")]
static extern int gtksharp_get_gdk_net_current_desktop ();
public static int CurrentDesktop {
get {
return gtksharp_get_gdk_net_current_desktop ();
}
}
[DllImport ("gdksharpglue")]
static extern uint gtksharp_get_gdk_net_active_window ();
public static Gdk.Window ActiveWindow {
get {
uint windowID = gtksharp_get_gdk_net_active_window ();
if (windowID == 0)
return Gdk.Global.DefaultRootWindow;
Console.WriteLine ("Active Window ID: {0}", windowID);
Gdk.Window window = Gdk.Window.ForeignNew (windowID);
return window;
}
}
[DllImport ("gdksharpglue")]
static extern IntPtr gtksharp_get_gdk_net_workarea ();
public static Gdk.Rectangle[] DesktopWorkareas {
get {
IntPtr raw_ret = gtksharp_get_gdk_net_workarea ();
if (raw_ret == IntPtr.Zero)
return new Gdk.Rectangle [0];
GLib.List list = new GLib.List (raw_ret, typeof (Gdk.Rectangle));
Gdk.Rectangle[] workareas = new Gdk.Rectangle [list.Count];
for (int i = 0; i < list.Count; i++)
workareas [i] = (Gdk.Rectangle) list [i];
return workareas;
}
}

View File

@ -4,7 +4,8 @@ libgdksharpglue_la_SOURCES = \
dragcontext.c \
event.c \
selection.c \
vmglueheaders.h
vmglueheaders.h \
windowmanager.c
# Adding a new glue file?
# Please remember to update makefile.win32

View File

@ -7,7 +7,8 @@ GLUE_OBJS = \
dragcontext.o \
event.o \
selection.o \
win32dll.o
win32dll.o \
windowmanager.o
all: gdksharpglue.dll

262
gdk/glue/windowmanager.c Normal file
View File

@ -0,0 +1,262 @@
/* windowmanager.c : Glue to access the extended window
* manager hints via the root window properties using
* gdk_property_get ()
*
* This work is based on the specification found here:
* http://www.freedesktop.org/standards/wm-spec/
*
* Author: Boyd Timothy <btimothy@novell.com>
*
* Copyright (c) 2004 Novell, Inc.
*/
#include <gdk/gdkscreen.h>
#include <gdk/gdkwindow.h>
#include <gdk/gdkproperty.h>
GList * gtksharp_get_gdk_net_supported (void);
guint * gtksharp_get_gdk_net_client_list (int *count);
gint gtksharp_get_gdk_net_number_of_desktops (void);
gint gtksharp_get_gdk_net_current_desktop (void);
guint gtksharp_get_gdk_net_active_window (void);
GList * gtksharp_get_gdk_net_workarea (void);
GList *
gtksharp_get_gdk_net_supported (void)
{
GdkAtom actual_property_type;
int actual_format;
int actual_length;
long *data = NULL;
GList *list = NULL;
int i;
if (!gdk_property_get (
gdk_screen_get_root_window (gdk_screen_get_default ()),
gdk_atom_intern ("_NET_SUPPORTED", FALSE),
gdk_atom_intern ("ATOM", FALSE),
0,
G_MAXLONG,
FALSE,
&actual_property_type,
&actual_format,
&actual_length,
(guchar **) &data)) {
gchar *actual_property_type_name;
g_critical ("Unable to get _NET_SUPPORTED");
actual_property_type_name = gdk_atom_name (actual_property_type);
if (actual_property_type_name) {
g_message ("actual_property_type: %s", actual_property_type_name);
g_free (actual_property_type_name);
}
return NULL;
}
/* Put all of the GdkAtoms into a GList to return */
for (i = 0; i < actual_length / sizeof (long); i ++) {
list = g_list_append (list, (GdkAtom) data [i]);
}
g_free (data);
return list;
}
guint *
gtksharp_get_gdk_net_client_list (int *count)
{
GdkAtom actual_property_type;
int actual_format;
int actual_length;
long *data = NULL;
guint * list = NULL;
int i;
if (!gdk_property_get (
gdk_screen_get_root_window (gdk_screen_get_default ()),
gdk_atom_intern ("_NET_CLIENT_LIST", FALSE),
gdk_atom_intern ("WINDOW", FALSE),
0,
G_MAXLONG,
FALSE,
&actual_property_type,
&actual_format,
&actual_length,
(guchar **) &data)) {
gchar *actual_property_type_name;
g_critical ("Unable to get _NET_CLIENT_LIST");
actual_property_type_name = gdk_atom_name (actual_property_type);
if (actual_property_type_name) {
g_message ("actual_property_type: %s", actual_property_type_name);
g_free (actual_property_type_name);
}
return NULL;
}
*count = actual_length / sizeof (long);
list = g_malloc (*count * sizeof (guint));
/* Put all of the windows into a GList to return */
for (i = 0; i < *count; i ++) {
list [i] = data [i];
g_message ("WinID: %d", list [i]);
}
g_free (data);
return list;
}
gint
gtksharp_get_gdk_net_number_of_desktops (void)
{
GdkAtom actual_property_type;
int actual_format;
int actual_length;
long *data = NULL;
gint num_of_desktops;
if (!gdk_property_get (
gdk_screen_get_root_window (gdk_screen_get_default ()),
gdk_atom_intern ("_NET_NUMBER_OF_DESKTOPS", FALSE),
gdk_atom_intern ("CARDINAL", FALSE),
0,
G_MAXLONG,
FALSE,
&actual_property_type,
&actual_format,
&actual_length,
(guchar **) &data)) {
gchar *actual_property_type_name;
g_critical ("Unable to get _NET_NUMBER_OF_DESKTOPS");
actual_property_type_name = gdk_atom_name (actual_property_type);
if (actual_property_type_name) {
g_message ("actual_property_type: %s", actual_property_type_name);
g_free (actual_property_type_name);
}
return -1;
}
num_of_desktops = (gint) data[0];
g_free (data);
return num_of_desktops;
}
gint
gtksharp_get_gdk_net_current_desktop (void)
{
GdkAtom actual_property_type;
int actual_format;
int actual_length;
long *data = NULL;
gint current_desktop;
if (!gdk_property_get (
gdk_screen_get_root_window (gdk_screen_get_default ()),
gdk_atom_intern ("_NET_CURRENT_DESKTOP", FALSE),
gdk_atom_intern ("CARDINAL", FALSE),
0,
G_MAXLONG,
FALSE,
&actual_property_type,
&actual_format,
&actual_length,
(guchar **) &data)) {
gchar *actual_property_type_name;
g_critical ("Unable to get _NET_CURRENT_DESKTOP");
actual_property_type_name = gdk_atom_name (actual_property_type);
if (actual_property_type_name) {
g_message ("actual_property_type: %s", actual_property_type_name);
g_free (actual_property_type_name);
}
return -1;
}
current_desktop = (gint) data[0];
g_free (data);
return current_desktop;
}
guint
gtksharp_get_gdk_net_active_window (void)
{
GdkAtom actual_property_type;
int actual_format;
int actual_length;
long *data = NULL;
guint windowID = 0;
if (!gdk_property_get (
gdk_screen_get_root_window (gdk_screen_get_default ()),
gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE),
gdk_atom_intern ("WINDOW", FALSE),
0,
G_MAXLONG,
FALSE,
&actual_property_type,
&actual_format,
&actual_length,
(guchar **) &data)) {
gchar *actualPropertyTypeName;
g_critical ("Unable to get _NET_ACTIVE_WINDOW");
actualPropertyTypeName = gdk_atom_name (actual_property_type);
if (actualPropertyTypeName) {
g_message ("actual_property_type: %s", actualPropertyTypeName);
g_free(actualPropertyTypeName);
}
return -1;
}
windowID = (gint) data [0];
g_free (data);
return windowID;
}
GList *
gtksharp_get_gdk_net_workarea (void)
{
GdkAtom actual_property_type;
int actual_format;
int actual_length;
long *data = NULL;
int i = 0;
GList *list = NULL;
if (!gdk_property_get (
gdk_screen_get_root_window (gdk_screen_get_default ()),
gdk_atom_intern ("_NET_WORKAREA", FALSE),
gdk_atom_intern ("CARDINAL", FALSE),
0,
G_MAXLONG,
FALSE,
&actual_property_type,
&actual_format,
&actual_length,
(guchar **) &data)) {
gchar *actualPropertyTypeName;
g_critical ("Unable to get _NET_WORKAREA");
actualPropertyTypeName = gdk_atom_name (actual_property_type);
if (actualPropertyTypeName) {
g_message ("actual_property_type: %s", actualPropertyTypeName);
g_free(actualPropertyTypeName);
}
return FALSE;
}
for (i = 0; i < actual_length / sizeof (long); i += 4) {
GdkRectangle *rectangle = g_malloc(sizeof (GdkRectangle));
rectangle->x = (int) data [i];
rectangle->y = (int) data [i + 1];
rectangle->width = (int) data [i + 2];
rectangle->height = (int) data [i + 3];
list = g_list_append (list, rectangle);
}
if (data != NULL)
g_free(data);
return list;
}