From d7095d495c5188856b2c259ce4871f2c64ed0861 Mon Sep 17 00:00:00 2001 From: Christian Hoff Date: Tue, 17 Mar 2009 18:40:35 +0000 Subject: [PATCH] 2009-03-17 Christian Hoff * gdk/Property.custom: add new overloads to the Get method for the most common property types * gdk/Global.custom: Use the new overloads of Property.Get instead of glue svn path=/trunk/gtk-sharp/; revision=129618 --- ChangeLog | 6 + gdk/Global.custom | 77 ++++------- gdk/Property.custom | 109 +++++++++++++++- gdk/glue/Makefile.am | 3 +- gdk/glue/windowmanager.c | 276 --------------------------------------- 5 files changed, 139 insertions(+), 332 deletions(-) delete mode 100644 gdk/glue/windowmanager.c diff --git a/ChangeLog b/ChangeLog index 7cf5098c9..d1c8805ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-03-17 Christian Hoff + + * gdk/Property.custom: add new overloads to the Get method + for the most common property types + * gdk/Global.custom: Use the new overloads of Property.Get instead of glue + 2009-03-16 Mike Kestner * gtk/NodeSelection.cs: use new Adapter prop on NodeStore. diff --git a/gdk/Global.custom b/gdk/Global.custom index 135aefd37..9aefadf3b 100644 --- a/gdk/Global.custom +++ b/gdk/Global.custom @@ -49,88 +49,61 @@ return result; } - [DllImport ("gdksharpglue-2")] - 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; + Gdk.Atom[] atoms; + if (!Gdk.Property.Get (Screen.Default.RootWindow, Atom.Intern ("_NET_SUPPORTED", false), false, out atoms)) + throw new ApplicationException ("Unable to get _NET_SUPPORTED property"); return atoms; } } - [DllImport ("gdksharpglue-2")] - 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); - } + Gdk.Window [] windows; + if (!Gdk.Property.Get (Screen.Default.RootWindow, Atom.Intern ("_NET_CLIENT_LIST", false), false, out windows)) + throw new ApplicationException ("Unable to get _NET_CLIENT_LIST property"); + return windows; } } - [DllImport ("gdksharpglue-2")] - static extern int gtksharp_get_gdk_net_number_of_desktops (); - public static int NumberOfDesktops { get { - return gtksharp_get_gdk_net_number_of_desktops (); + int[] data; + if (!Gdk.Property.Get (Screen.Default.RootWindow, Atom.Intern ("_NET_NUMBER_OF_DESKTOPS", false), false, out data)) + throw new ApplicationException ("Unable to get _NET_NUMBER_OF_DESKTOPS property"); + + return data [0]; } } - [DllImport ("gdksharpglue-2")] - static extern int gtksharp_get_gdk_net_current_desktop (); - public static int CurrentDesktop { get { - return gtksharp_get_gdk_net_current_desktop (); + int[] data; + if (!Gdk.Property.Get (Screen.Default.RootWindow, Atom.Intern ("_NET_CURRENT_DESKTOP", false), false, out data)) + throw new ApplicationException ("Unable to get _NET_CURRENT_DESKTOP property"); + + return data [0]; } } - [DllImport ("gdksharpglue-2")] - 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; + Gdk.Window [] windows; + if (!Gdk.Property.Get (Screen.Default.RootWindow, Atom.Intern ("_NET_ACTIVE_WINDOW", false), false, out windows)) + throw new ApplicationException ("Unable to get _NET_ACTIVE_WINDOW property"); + + return windows [0]; } } - [DllImport ("gdksharpglue-2")] - 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]; + Gdk.Rectangle[] workareas; + if (!Gdk.Property.Get (Screen.Default.RootWindow, Atom.Intern ("_NET_WORKAREA", false), false, out workareas)) + throw new ApplicationException ("Unable to get _NET_WORKAREA property"); return workareas; } diff --git a/gdk/Property.custom b/gdk/Property.custom index 5b8400361..8160eb24a 100644 --- a/gdk/Property.custom +++ b/gdk/Property.custom @@ -3,6 +3,7 @@ // Authors: Mike Kestner // // Copyright (c) 2007 Novell, Inc. +// Copyright (c) 2009 Christian Hoff // // This program is free software; you can redistribute it and/or // modify it under the terms of version 2 of the Lesser GNU General @@ -30,12 +31,12 @@ } [DllImport("libgdk-win32-2.0-0.dll")] - static extern bool gdk_property_get(IntPtr window, IntPtr property, IntPtr type, UIntPtr offset, UIntPtr length, int pdelete, out IntPtr actual_property_type, out int actual_format, out int actual_length, out IntPtr data); + static extern bool gdk_property_get(IntPtr window, IntPtr property, IntPtr type, UIntPtr offset, UIntPtr length, bool pdelete, out IntPtr actual_property_type, out int actual_format, out int actual_length, out IntPtr data); public static bool Get(Gdk.Window window, Gdk.Atom property, Gdk.Atom type, ulong offset, ulong length, int pdelete, out Gdk.Atom actual_property_type, out int actual_format, out int actual_length, out byte[] data) { IntPtr actual_property_type_as_native; IntPtr actual_data; - bool raw_ret = gdk_property_get(window == null ? IntPtr.Zero : window.Handle, property == null ? IntPtr.Zero : property.Handle, type == null ? IntPtr.Zero : type.Handle, new UIntPtr (offset), new UIntPtr (length), pdelete, out actual_property_type_as_native, out actual_format, out actual_length, out actual_data); + bool raw_ret = gdk_property_get(window == null ? IntPtr.Zero : window.Handle, property == null ? IntPtr.Zero : property.Handle, type == null ? IntPtr.Zero : type.Handle, new UIntPtr (offset), new UIntPtr (length), pdelete == 0 ? false : true, out actual_property_type_as_native, out actual_format, out actual_length, out actual_data); data = null; if (raw_ret) { data = new byte [actual_length]; @@ -48,3 +49,107 @@ return ret; } + public static bool Get (Gdk.Window window, Gdk.Atom property, Gdk.Atom type, ulong offset, ulong length, bool pdelete, out int[] data) { + IntPtr actual_property_type, raw_data; + int actual_length, format; + bool ret = gdk_property_get(window == null ? IntPtr.Zero : window.Handle, property == null ? IntPtr.Zero : property.Handle, type == null ? IntPtr.Zero : type.Handle, new UIntPtr (offset), new UIntPtr (length), pdelete, out actual_property_type, out format, out actual_length, out raw_data); + if (ret) { + try { + int block_size; + if (format == 32) { // data returned in blocks the size of a C long +#if WIN64LONGS + block_size = int.Size; +#else + block_size = IntPtr.Size; +#endif + } else if (format == 8 || format == 16) + block_size = format; + else + throw new NotSupportedException (String.Format ("Unable to read properties in {0}-bit format", format)); + + int size = actual_length / block_size; + data = new int [size]; + for (int idx = 0; idx < size; idx++) { + IntPtr elem_ptr = new IntPtr (raw_data.ToInt64 () + idx * block_size); + switch (format) { + case 8: + data [idx] = Marshal.ReadByte (elem_ptr); + break; + case 16: + data [idx] = Marshal.ReadInt16 (elem_ptr); + break; + case 32: + data [idx] = Marshal.ReadInt32 (elem_ptr); + break; + } + } + } finally { + GLib.Marshaller.Free (raw_data); + } + } else + data = null; + + return ret; + } + + public static bool Get (Gdk.Window window, Gdk.Atom property, bool pdelete, out int[] data) { + return Get (window, property, 0, uint.MaxValue - 3, pdelete, out data); + } + + public static bool Get (Gdk.Window window, Gdk.Atom property, ulong offset, ulong length, bool pdelete, out int[] data) { + return Get (window, property, Gdk.Atom.Intern ("CARDINAL", false), offset, length, pdelete, out data); + } + + public static bool Get (Gdk.Window window, Gdk.Atom property, bool pdelete, out Gdk.Atom[] data) { + return Get (window, property, 0, uint.MaxValue - 3, pdelete, out data); + } + + public static bool Get (Gdk.Window window, Gdk.Atom property, ulong offset, ulong length, bool pdelete, out Gdk.Atom[] atoms) { + int[] raw_atoms; + if (!Get (window, property, Gdk.Atom.Intern ("ATOM", false), offset, length, pdelete, out raw_atoms)) { + atoms = null; + return false; + } + + atoms = new Gdk.Atom [raw_atoms.GetLength (0)]; + for (int idx = 0; idx < raw_atoms.GetLength (0); idx++) { + atoms [idx] = new Gdk.Atom (new IntPtr (raw_atoms [idx])); + } + return true; + } + + public static bool Get (Gdk.Window window, Gdk.Atom property, bool pdelete, out Gdk.Rectangle[] rects) { + return Get (window, property, 0, uint.MaxValue - 3, pdelete, out rects); + } + + public static bool Get (Gdk.Window window, Gdk.Atom property, ulong offset, ulong length, bool pdelete, out Gdk.Rectangle[] rects) { + int[] raw_rects; + if (!Get (window, property, Gdk.Atom.Intern ("CARDINAL", false), offset, length, pdelete, out raw_rects)) { + rects = null; + return false; + } + + rects = new Gdk.Rectangle [raw_rects.GetLength (0) / 4]; + for (int idx = 0; idx < rects.GetLength (0); idx ++) { + rects [idx] = new Gdk.Rectangle (raw_rects [idx * 4], raw_rects [idx * 4 + 1], raw_rects [idx * 4 + 2], raw_rects [idx * 4 + 3]); + } + return true; + } + + public static bool Get (Gdk.Window window, Gdk.Atom property, bool pdelete, out Gdk.Window[] windows) { + return Get (window, property, 0, uint.MaxValue - 3, pdelete, out windows); + } + + public static bool Get (Gdk.Window window, Gdk.Atom property, ulong offset, ulong length, bool pdelete, out Gdk.Window[] windows) { + int[] raw_windows; + if (!Get (window, property, Gdk.Atom.Intern ("WINDOW", false), offset, length, pdelete, out raw_windows)) { + windows = null; + return false; + } + + windows = new Gdk.Window [raw_windows.GetLength (0)]; + for (int idx = 0; idx < raw_windows.GetLength (0); idx ++) { + windows [idx] = Gdk.Window.ForeignNew ((uint) raw_windows [idx]); + } + return true; + } diff --git a/gdk/glue/Makefile.am b/gdk/glue/Makefile.am index add761996..768ae0f9f 100644 --- a/gdk/glue/Makefile.am +++ b/gdk/glue/Makefile.am @@ -3,8 +3,7 @@ lib_LTLIBRARIES = libgdksharpglue-2.la libgdksharpglue_2_la_SOURCES = \ dragcontext.c \ device.c \ - vmglueheaders.h \ - windowmanager.c + vmglueheaders.h nodist_libgdksharpglue_2_la_SOURCES = generated.c diff --git a/gdk/glue/windowmanager.c b/gdk/glue/windowmanager.c deleted file mode 100644 index 8eeb7134e..000000000 --- a/gdk/glue/windowmanager.c +++ /dev/null @@ -1,276 +0,0 @@ -/* 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 - * - * Copyright (c) 2004 Novell, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the Lesser GNU General - * Public License as published by the Free Software Foundation. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser 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 -#include -#include - -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; -} -