diff options
author | Owen Taylor <otaylor@src.gnome.org> | 1999-11-08 20:17:18 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 1999-11-08 20:17:18 +0000 |
commit | a650699a948fb46ccfd2a495311589d64696378b (patch) | |
tree | 0bc82de81900844913dd6791ec5cfb95310ba949 | |
parent | 16d5a3563f8de7ec05e2ace538bf04c8ed7b0c9d (diff) | |
download | gtk+-gtk-1-0.tar.gz |
Remove files that leaked in from head branch due to CVS magicgtk-1-0
-rw-r--r-- | gdk/x11/MwmUtil.h | 132 | ||||
-rw-r--r-- | gdk/x11/gdkcc-x11.c | 1725 | ||||
-rw-r--r-- | gdk/x11/gdkcolor-x11.c | 749 | ||||
-rw-r--r-- | gdk/x11/gdkcursor-x11.c | 84 | ||||
-rw-r--r-- | gdk/x11/gdkdnd-x11.c | 158 | ||||
-rw-r--r-- | gdk/x11/gdkfont-x11.c | 387 | ||||
-rw-r--r-- | gdk/x11/gdkglobals-x11.c | 55 | ||||
-rw-r--r-- | gdk/x11/gdkimage-x11.c | 496 | ||||
-rw-r--r-- | gdk/x11/gdkinput-gxi.c | 642 | ||||
-rw-r--r-- | gdk/x11/gdkinput-none.c | 74 | ||||
-rw-r--r-- | gdk/x11/gdkinput-x11.c | 883 | ||||
-rw-r--r-- | gdk/x11/gdkinput-xfree.c | 367 | ||||
-rw-r--r-- | gdk/x11/gdkinput.c | 345 | ||||
-rw-r--r-- | gdk/x11/gdkmain-x11.c | 4219 | ||||
-rw-r--r-- | gdk/x11/gdkpixmap-x11.c | 782 | ||||
-rw-r--r-- | gdk/x11/gdkproperty-x11.c | 214 | ||||
-rw-r--r-- | gdk/x11/gdkregion-x11.c | 302 | ||||
-rw-r--r-- | gdk/x11/gdkselection-x11.c | 246 | ||||
-rw-r--r-- | gdk/x11/gdkvisual-x11.c | 443 | ||||
-rw-r--r-- | gdk/x11/gdkwindow-x11.c | 1983 | ||||
-rw-r--r-- | gdk/x11/gdkx.h | 49 | ||||
-rw-r--r-- | gdk/x11/gdkxid.c | 75 | ||||
-rw-r--r-- | gdk/x11/gxid.c | 863 | ||||
-rw-r--r-- | gdk/x11/gxid_lib.c | 125 | ||||
-rw-r--r-- | gdk/x11/gxid_lib.h | 6 | ||||
-rw-r--r-- | gdk/x11/gxid_proto.h | 39 |
26 files changed, 0 insertions, 15443 deletions
diff --git a/gdk/x11/MwmUtil.h b/gdk/x11/MwmUtil.h deleted file mode 100644 index 9f4e3a29b2..0000000000 --- a/gdk/x11/MwmUtil.h +++ /dev/null @@ -1,132 +0,0 @@ -/** - * - * $Id$ - * - * Copyright (C) 1995 Free Software Foundation, Inc. - * - * This file is part of the GNU LessTif Library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - **/ - -#ifndef MWMUTIL_H_INCLUDED -#define MWMUTIL_H_INCLUDED - -#include <X11/Xmd.h> - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - CARD32 flags; - CARD32 functions; - CARD32 decorations; - INT32 input_mode; - CARD32 status; -} MotifWmHints, MwmHints; - -#define MWM_HINTS_FUNCTIONS (1L << 0) -#define MWM_HINTS_DECORATIONS (1L << 1) -#define MWM_HINTS_INPUT_MODE (1L << 2) -#define MWM_HINTS_STATUS (1L << 3) - -#define MWM_FUNC_ALL (1L << 0) -#define MWM_FUNC_RESIZE (1L << 1) -#define MWM_FUNC_MOVE (1L << 2) -#define MWM_FUNC_MINIMIZE (1L << 3) -#define MWM_FUNC_MAXIMIZE (1L << 4) -#define MWM_FUNC_CLOSE (1L << 5) - -#define MWM_DECOR_ALL (1L << 0) -#define MWM_DECOR_BORDER (1L << 1) -#define MWM_DECOR_RESIZEH (1L << 2) -#define MWM_DECOR_TITLE (1L << 3) -#define MWM_DECOR_MENU (1L << 4) -#define MWM_DECOR_MINIMIZE (1L << 5) -#define MWM_DECOR_MAXIMIZE (1L << 6) - -#define MWM_INPUT_MODELESS 0 -#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 -#define MWM_INPUT_SYSTEM_MODAL 2 -#define MWM_INPUT_FULL_APPLICATION_MODAL 3 -#define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL - -#define MWM_TEAROFF_WINDOW (1L<<0) - -/* - * atoms - */ -#define _XA_MOTIF_BINDINGS "_MOTIF_BINDINGS" -#define _XA_MOTIF_WM_HINTS "_MOTIF_WM_HINTS" -#define _XA_MOTIF_WM_MESSAGES "_MOTIF_WM_MESSAGES" -#define _XA_MOTIF_WM_OFFSET "_MOTIF_WM_OFFSET" -#define _XA_MOTIF_WM_MENU "_MOTIF_WM_MENU" -#define _XA_MOTIF_WM_INFO "_MOTIF_WM_INFO" -#define _XA_MWM_HINTS _XA_MOTIF_WM_HINTS -#define _XA_MWM_MESSAGES _XA_MOTIF_WM_MESSAGES -#define _XA_MWM_MENU _XA_MOTIF_WM_MENU -#define _XA_MWM_INFO _XA_MOTIF_WM_INFO - - -/* - * _MWM_INFO property - */ -typedef struct { - long flags; - Window wm_window; -} MotifWmInfo; - -typedef MotifWmInfo MwmInfo; - -#define MWM_INFO_STARTUP_STANDARD (1L<<0) -#define MWM_INFO_STARTUP_CUSTOM (1L<<1) - -/* - * _MWM_HINTS property - */ -typedef struct { - CARD32 flags; - CARD32 functions; - CARD32 decorations; - INT32 inputMode; - CARD32 status; -} PropMotifWmHints; - -typedef PropMotifWmHints PropMwmHints; - -#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 -#define PROP_MWM_HINTS_ELEMENTS PROP_MOTIF_WM_HINTS_ELEMENTS - -/* - * _MWM_INFO property, slight return - */ -typedef struct { - CARD32 flags; - CARD32 wmWindow; -} PropMotifWmInfo; - -typedef PropMotifWmInfo PropMwmInfo; - -#define PROP_MOTIF_WM_INFO_ELEMENTS 2 -#define PROP_MWM_INFO_ELEMENTS PROP_MOTIF_WM_INFO_ELEMENTS - -#ifdef __cplusplus -} -#endif - -#endif /* MWMUTIL_H_INCLUDED */ diff --git a/gdk/x11/gdkcc-x11.c b/gdk/x11/gdkcc-x11.c deleted file mode 100644 index ed9444aed4..0000000000 --- a/gdk/x11/gdkcc-x11.c +++ /dev/null @@ -1,1725 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* Color Context module - * Copyright 1994,1995 John L. Cwikla - * Copyright (C) 1997 by Ripley Software Development - * Copyright (C) 1997 by Federico Mena (port to Gtk/Gdk) - */ - -/* Copyright 1994,1995 John L. Cwikla - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appears in all copies and that - * both that copyright notice and this permission notice appear in - * supporting documentation, and that the name of John L. Cwikla or - * Wolfram Research, Inc not be used in advertising or publicity - * pertaining to distribution of the software without specific, written - * prior permission. John L. Cwikla and Wolfram Research, Inc make no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - * John L. Cwikla and Wolfram Research, Inc disclaim all warranties with - * regard to this software, including all implied warranties of - * merchantability and fitness, in no event shall John L. Cwikla or - * Wolfram Research, Inc be liable for any special, indirect or - * consequential damages or any damages whatsoever resulting from loss of - * use, data or profits, whether in an action of contract, negligence or - * other tortious action, arising out of or in connection with the use or - * performance of this software. - * - * Author: - * John L. Cwikla - * X Programmer - * Wolfram Research Inc. - * - * cwikla@wri.com - */ - - -#include <X11/Xlib.h> -#include <stdlib.h> -#include <string.h> -#include "gdk.h" -#include "gdkprivate.h" -#include "gdkx.h" - - -#define MAX_IMAGE_COLORS 256 - - -static guint -hash_color (gpointer key) -{ - GdkColor *color = key; - - return (color->red * 33023 + color->green * 30013 + color->blue * 27011); -} - -static gint -compare_colors (gpointer a, - gpointer b) -{ - GdkColor *aa = a; - GdkColor *bb = b; - - return ((aa->red == bb->red) && (aa->green == bb->green) && (aa->blue == bb->blue)); -} - -static void -free_hash_entry (gpointer key, - gpointer value, - gpointer user_data) -{ - g_free (key); /* key and value are the same GdkColor */ -} - -static int -pixel_sort (const void *a, const void *b) -{ - return ((GdkColor *) a)->pixel - ((GdkColor *) b)->pixel; -} - -/* XXX: This function does an XQueryColors() the hard way, because there is - * no corresponding function in Gdk. - */ - -static void -my_x_query_colors (GdkColormap *colormap, - GdkColor *colors, - gint ncolors) -{ - XColor *xcolors; - gint i; - - xcolors = g_new (XColor, ncolors); - for (i = 0; i < ncolors; i++) - xcolors[i].pixel = colors[i].pixel; - - XQueryColors (gdk_display, GDK_COLORMAP_XCOLORMAP (colormap), xcolors, ncolors); - - for (i = 0; i < ncolors; i++) - { - colors[i].red = xcolors[i].red; - colors[i].green = xcolors[i].green; - colors[i].blue = xcolors[i].blue; - } - - g_free (xcolors); -} - -static void -query_colors (GdkColorContext *cc) -{ - gint i; - GdkColorContextPrivate *ccp = (GdkColorContextPrivate *) cc; - cc->cmap = g_new (GdkColor, cc->num_colors); - - for (i = 0; i < cc->num_colors; i++) - cc->cmap[i].pixel = cc->clut ? cc->clut[i] : ccp->std_cmap.base_pixel + i; - - my_x_query_colors (cc->colormap, cc->cmap, cc->num_colors); - - qsort (cc->cmap, cc->num_colors, sizeof (GdkColor), pixel_sort); -} - -static void -init_bw (GdkColorContext *cc) -{ - GdkColor color; - - g_warning ("init_bw: failed to allocate colors, falling back to black and white"); - - cc->mode = GDK_CC_MODE_BW; - - color.red = color.green = color.blue = 0; - - if (!gdk_color_alloc (cc->colormap, &color)) - cc->black_pixel = 0; - else - cc->black_pixel = color.pixel; - - color.red = color.green = color.blue = 0xffff; - - if (!gdk_color_alloc (cc->colormap, &color)) - cc->white_pixel = cc->black_pixel ? 0 : 1; - else - cc->white_pixel = color.pixel; - - cc->num_colors = 2; -} - -static void -init_gray (GdkColorContext *cc) -{ - GdkColorContextPrivate *ccp = (GdkColorContextPrivate *) cc; - GdkColor *clrs, *cstart; - gint i; - gdouble dinc; - - cc->num_colors = GDK_VISUAL_XVISUAL (cc->visual)->map_entries; - - cc->clut = g_new (gulong, cc->num_colors); - cstart = g_new (GdkColor, cc->num_colors); - -retrygray: - - dinc = 65535.0 / (cc->num_colors - 1); - - clrs = cstart; - - for (i = 0; i < cc->num_colors; i++) - { - clrs->red = clrs->green = clrs->blue = dinc * i; - - if (!gdk_color_alloc (cc->colormap, clrs)) - { - gdk_colors_free (cc->colormap, cc->clut, i, 0); - - cc->num_colors /= 2; - - if (cc->num_colors > 1) - goto retrygray; - else - { - g_free (cc->clut); - cc->clut = NULL; - init_bw (cc); - g_free (cstart); - return; - } - } - - cc->clut[i] = clrs++->pixel; - } - - g_free (cstart); - - /* XXX: is this the right thing to do? */ - ccp->std_cmap.colormap = GDK_COLORMAP_XCOLORMAP (cc->colormap); - ccp->std_cmap.base_pixel = 0; - ccp->std_cmap.red_max = cc->num_colors - 1; - ccp->std_cmap.green_max = 0; - ccp->std_cmap.blue_max = 0; - ccp->std_cmap.red_mult = 1; - ccp->std_cmap.green_mult = 0; - ccp->std_cmap.blue_mult = 0; - - cc->white_pixel = WhitePixel (ccp->xdisplay, gdk_screen); - cc->black_pixel = BlackPixel (ccp->xdisplay, gdk_screen); - - query_colors (cc); - - cc->mode = GDK_CC_MODE_MY_GRAY; -} - -static void -init_color (GdkColorContext *cc) -{ - GdkColorContextPrivate *ccp = (GdkColorContextPrivate *) cc; - gint cubeval; - - cubeval = 1; - while ((cubeval * cubeval * cubeval) < GDK_VISUAL_XVISUAL (cc->visual)->map_entries) - cubeval++; - cubeval--; - - cc->num_colors = cubeval * cubeval * cubeval; - - ccp->std_cmap.red_max = cubeval - 1; - ccp->std_cmap.green_max = cubeval - 1; - ccp->std_cmap.blue_max = cubeval - 1; - ccp->std_cmap.red_mult = cubeval * cubeval; - ccp->std_cmap.green_mult = cubeval; - ccp->std_cmap.blue_mult = 1; - ccp->std_cmap.base_pixel = 0; - - cc->white_pixel = WhitePixel (ccp->xdisplay, gdk_screen); - cc->black_pixel = BlackPixel (ccp->xdisplay, gdk_screen); - cc->num_colors = DisplayCells (ccp->xdisplay, gdk_screen); - - /* a CLUT for storing allocated pixel indices */ - - cc->max_colors = cc->num_colors; - cc->clut = g_new (gulong, cc->max_colors); - - for (cubeval = 0; cubeval < cc->max_colors; cubeval++) - cc->clut[cubeval] = cubeval; - - query_colors (cc); - - cc->mode = GDK_CC_MODE_STD_CMAP; -} - - -static void -init_true_color (GdkColorContext *cc) -{ - GdkColorContextPrivate *ccp = (GdkColorContextPrivate *) cc; - gulong rmask, gmask, bmask; - - cc->mode = GDK_CC_MODE_TRUE; - - /* Red */ - - rmask = cc->masks.red = cc->visual->red_mask; - - cc->shifts.red = 0; - cc->bits.red = 0; - - while (!(rmask & 1)) - { - rmask >>= 1; - cc->shifts.red++; - } - - while (rmask & 1) - { - rmask >>= 1; - cc->bits.red++; - } - - /* Green */ - - gmask = cc->masks.green = cc->visual->green_mask; - - cc->shifts.green = 0; - cc->bits.green = 0; - - while (!(gmask & 1)) - { - gmask >>= 1; - cc->shifts.green++; - } - - while (gmask & 1) - { - gmask >>= 1; - cc->bits.green++; - } - - /* Blue */ - - bmask = cc->masks.blue = cc->visual->blue_mask; - - cc->shifts.blue = 0; - cc->bits.blue = 0; - - while (!(bmask & 1)) - { - bmask >>= 1; - cc->shifts.blue++; - } - - while (bmask & 1) - { - bmask >>= 1; - cc->bits.blue++; - } - - cc->num_colors = (cc->visual->red_mask | cc->visual->green_mask | cc->visual->blue_mask) + 1; - cc->white_pixel = WhitePixel (ccp->xdisplay, gdk_screen); - cc->black_pixel = BlackPixel (ccp->xdisplay, gdk_screen); -} - -static void -init_direct_color (GdkColorContext *cc) -{ - gint n, count; - GdkColor *clrs, *cstart; - gulong rval, gval, bval; - gulong *rtable; - gulong *gtable; - gulong *btable; - gdouble dinc; - - init_true_color (cc); /* for shift stuff */ - - rval = cc->visual->red_mask >> cc->shifts.red; - gval = cc->visual->green_mask >> cc->shifts.green; - bval = cc->visual->blue_mask >> cc->shifts.blue; - - rtable = g_new (gulong, rval + 1); - gtable = g_new (gulong, gval + 1); - btable = g_new (gulong, bval + 1); - - cc->max_entry = MAX (rval, gval); - cc->max_entry = MAX (cc->max_entry, bval); - - cstart = g_new (GdkColor, cc->max_entry + 1); - cc->clut = g_new (gulong, cc->max_entry + 1); - -retrydirect: - - for (n = 0; n < rval; n++) - rtable[n] = rval ? (65535.0 / rval * n) : 0; - - for (n = 0; n < gval; n++) - gtable[n] = gval ? (65535.0 / gval * n) : 0; - - for (n = 0; n < bval; n++) - btable[n] = bval ? (65535.0 / bval * n) : 0; - - cc->max_entry = MAX (rval, gval); - cc->max_entry = MAX (cc->max_entry, bval); - - count = 0; - clrs = cstart; - cc->num_colors = (rval + 1) * (gval + 1) * (bval + 1); - - for (n = 0; n < cc->max_entry; n++) - { - dinc = (double) n / cc->max_entry; - - clrs->red = rtable[(int) (dinc * rval)]; - clrs->green = gtable[(int) (dinc * gval)]; - clrs->blue = btable[(int) (dinc * bval)]; - - if (gdk_color_alloc (cc->colormap, clrs)) - { - cc->clut[count++] = clrs->pixel; - clrs++; - } - else - { - gdk_colors_free (cc->colormap, cc->clut, count, 0); - - rval >>= 1; - gval >>= 1; - bval >>= 1; - - cc->masks.red = (cc->masks.red >> 1) & cc->visual->red_mask; - cc->masks.green = (cc->masks.green >> 1) & cc->visual->green_mask; - cc->masks.blue = (cc->masks.blue >> 1) & cc->visual->blue_mask; - - cc->shifts.red++; - cc->shifts.green++; - cc->shifts.blue++; - - cc->bits.red--; - cc->bits.green--; - cc->bits.blue--; - - cc->num_colors = (rval + 1) * (gval + 1) * (bval + 1); - - if (cc->num_colors >1) - goto retrydirect; - else - { - g_free (cc->clut); - cc->clut = NULL; - init_bw (cc); - break; - } - } - } - - /* Update allocated color count; original num_colors is max_entry, which - * is not necessarily the same as the really allocated number of colors. - */ - - cc->num_colors = count; - - g_free (rtable); - g_free (gtable); - g_free (btable); - g_free (cstart); -} - -static void -init_palette (GdkColorContext *cc) -{ - /* restore correct mode for this cc */ - - switch (cc->visual->type) - { - case GDK_VISUAL_STATIC_GRAY: - case GDK_VISUAL_GRAYSCALE: - if (GDK_VISUAL_XVISUAL (cc->visual)->map_entries == 2) - cc->mode = GDK_CC_MODE_BW; - else - cc->mode = GDK_CC_MODE_MY_GRAY; - break; - - case GDK_VISUAL_TRUE_COLOR: - case GDK_VISUAL_DIRECT_COLOR: - cc->mode = GDK_CC_MODE_TRUE; - break; - - case GDK_VISUAL_STATIC_COLOR: - case GDK_VISUAL_PSEUDO_COLOR: - cc->mode = GDK_CC_MODE_STD_CMAP; - break; - - default: - cc->mode = GDK_CC_MODE_UNDEFINED; - break; - } - - /* previous palette */ - - if (cc->num_palette) - g_free (cc->palette); - - if (cc->fast_dither) - g_free (cc->fast_dither); - - /* clear hash table if present */ - - if (cc->color_hash) - { - /* XXX: quick-and-dirty way to remove everything */ - - g_hash_table_destroy (cc->color_hash); - cc->color_hash = g_hash_table_new (hash_color, compare_colors); - } - - cc->palette = NULL; - cc->num_palette = 0; - cc->fast_dither = NULL; -} - -GdkColorContext * -gdk_color_context_new (GdkVisual *visual, - GdkColormap *colormap) -{ - GdkColorContextPrivate *ccp; - gint use_private_colormap = FALSE; /* XXX: maybe restore full functionality later? */ - GdkColorContext *cc; - gint retry_count; - GdkColormap *default_colormap; - - g_assert (visual != NULL); - g_assert (colormap != NULL); - - ccp = g_new (GdkColorContextPrivate, 1); - cc = (GdkColorContext *) ccp; - ccp->xdisplay = gdk_display; - cc->visual = visual; - cc->colormap = colormap; - cc->clut = NULL; - cc->cmap = NULL; - cc->mode = GDK_CC_MODE_UNDEFINED; - cc->need_to_free_colormap = FALSE; - - cc->color_hash = NULL; - cc->palette = NULL; - cc->num_palette = 0; - cc->fast_dither = NULL; - - default_colormap = gdk_colormap_get_system (); - - retry_count = 0; - - while (retry_count < 2) - { - /* Only create a private colormap if the visual found isn't equal - * to the default visual and we don't have a private colormap, - * -or- if we are instructed to create a private colormap (which - * never is the case for XmHTML). - */ - - if (use_private_colormap - || ((cc->visual != gdk_visual_get_system ()) /* default visual? */ - && (GDK_COLORMAP_XCOLORMAP (colormap) == GDK_COLORMAP_XCOLORMAP (default_colormap)))) - { - g_warning ("gdk_color_context_new: non-default visual detected, " - "using private colormap"); - - cc->colormap = gdk_colormap_new (cc->visual, FALSE); - - cc->need_to_free_colormap = (GDK_COLORMAP_XCOLORMAP (colormap) - != GDK_COLORMAP_XCOLORMAP (default_colormap)); - } - - switch (visual->type) - { - case GDK_VISUAL_STATIC_GRAY: - case GDK_VISUAL_GRAYSCALE: - GDK_NOTE (COLOR_CONTEXT, - g_print ("gdk_color_context_new: visual class is %s\n", - (visual->type == GDK_VISUAL_STATIC_GRAY) ? - "GDK_VISUAL_STATIC_GRAY" : - "GDK_VISUAL_GRAYSCALE")); - - if (GDK_VISUAL_XVISUAL (cc->visual)->map_entries == 2) - init_bw (cc); - else - init_gray (cc); - - break; - - case GDK_VISUAL_TRUE_COLOR: /* shifts */ - GDK_NOTE (COLOR_CONTEXT, - g_print ("gdk_color_context_new: visual class is GDK_VISUAL_TRUE_COLOR\n")); - - init_true_color (cc); - break; - - case GDK_VISUAL_DIRECT_COLOR: /* shifts and fake CLUT */ - GDK_NOTE (COLOR_CONTEXT, - g_print ("gdk_color_context_new: visual class is GDK_VISUAL_DIRECT_COLOR\n")); - - init_direct_color (cc); - break; - - case GDK_VISUAL_STATIC_COLOR: - case GDK_VISUAL_PSEUDO_COLOR: - GDK_NOTE (COLOR_CONTEXT, - g_print ("gdk_color_context_new: visual class is %s\n", - (visual->type == GDK_VISUAL_STATIC_COLOR) ? - "GDK_VISUAL_STATIC_COLOR" : - "GDK_VISUAL_PSEUDO_COLOR")); - - init_color (cc); - break; - - default: - g_assert_not_reached (); - } - - if ((cc->mode == GDK_CC_MODE_BW) && (cc->visual->depth > 1)) - { - use_private_colormap = TRUE; - retry_count++; - } - else - break; - } - - /* no. of colors allocated yet */ - - cc->num_allocated = 0; - - GDK_NOTE (COLOR_CONTEXT, - g_print ("gdk_color_context_new: screen depth is %i, no. of colors is %i\n", - cc->visual->depth, cc->num_colors)); - - /* check if we need to initialize a hash table */ - - if ((cc->mode == GDK_CC_MODE_STD_CMAP) || (cc->mode == GDK_CC_MODE_UNDEFINED)) - cc->color_hash = g_hash_table_new (hash_color, compare_colors); - - return (GdkColorContext *) cc; -} - -GdkColorContext * -gdk_color_context_new_mono (GdkVisual *visual, - GdkColormap *colormap) -{ - GdkColorContextPrivate *ccp; - GdkColorContext *cc; - - g_assert (visual != NULL); - g_assert (colormap != NULL); - - cc = g_new (GdkColorContext, 1); - ccp = (GdkColorContextPrivate *) cc; - ccp->xdisplay = gdk_display; - cc->visual = visual; - cc->colormap = colormap; - cc->clut = NULL; - cc->cmap = NULL; - cc->mode = GDK_CC_MODE_UNDEFINED; - cc->need_to_free_colormap = FALSE; - - init_bw (cc); - - return (GdkColorContext *) cc; -} - -/* This doesn't currently free black/white, hmm... */ - -void -gdk_color_context_free (GdkColorContext *cc) -{ - g_assert (cc != NULL); - - if ((cc->visual->type == GDK_VISUAL_STATIC_COLOR) - || (cc->visual->type == GDK_VISUAL_PSEUDO_COLOR)) - { - gdk_colors_free (cc->colormap, cc->clut, cc->num_allocated, 0); - g_free (cc->clut); - } - else if (cc->clut != NULL) - { - gdk_colors_free (cc->colormap, cc->clut, cc->num_colors, 0); - g_free (cc->clut); - } - - if (cc->cmap != NULL) - g_free (cc->cmap); - - if (cc->need_to_free_colormap) - gdk_colormap_unref (cc->colormap); - - /* free any palette that has been associated with this GdkColorContext */ - - init_palette (cc); - - if (cc->color_hash) - { - g_hash_table_foreach (cc->color_hash, - free_hash_entry, - NULL); - g_hash_table_destroy (cc->color_hash); - } - - g_free (cc); -} - -gulong -gdk_color_context_get_pixel (GdkColorContext *cc, - gushort red, - gushort green, - gushort blue, - gint *failed) -{ - GdkColorContextPrivate *ccp = (GdkColorContextPrivate *) cc; - g_assert (cc != NULL); - g_assert (failed != NULL); - - *failed = FALSE; - - switch (cc->mode) - { - case GDK_CC_MODE_BW: - { - gdouble value; - - value = (red / 65535.0 * 0.30 - + green / 65535.0 * 0.59 - + blue / 65535.0 * 0.11); - - if (value > 0.5) - return cc->white_pixel; - - return cc->black_pixel; - } - - case GDK_CC_MODE_MY_GRAY: - { - gulong ired, igreen, iblue; - - red = red * 0.30 + green * 0.59 + blue * 0.11; - green = 0; - blue = 0; - - if ((ired = red * (ccp->std_cmap.red_max + 1) / 0xffff) > ccp->std_cmap.red_max) - ired = ccp->std_cmap.red_max; - - ired *= ccp->std_cmap.red_mult; - - if ((igreen = green * (ccp->std_cmap.green_max + 1) / 0xffff) > ccp->std_cmap.green_max) - igreen = ccp->std_cmap.green_max; - - igreen *= ccp->std_cmap.green_mult; - - if ((iblue = blue * (ccp->std_cmap.blue_max + 1) / 0xffff) > ccp->std_cmap.blue_max) - iblue = ccp->std_cmap.blue_max; - - iblue *= ccp->std_cmap.blue_mult; - - if (cc->clut != NULL) - return cc->clut[ccp->std_cmap.base_pixel + ired + igreen + iblue]; - - return ccp->std_cmap.base_pixel + ired + igreen + iblue; - } - - case GDK_CC_MODE_TRUE: - { - gulong ired, igreen, iblue; - - if (cc->clut == NULL) - { - red >>= 16 - cc->bits.red; - green >>= 16 - cc->bits.green; - blue >>= 16 - cc->bits.blue; - - ired = (red << cc->shifts.red) & cc->masks.red; - igreen = (green << cc->shifts.green) & cc->masks.green; - iblue = (blue << cc->shifts.blue) & cc->masks.blue; - - return ired | igreen | iblue; - } - - ired = cc->clut[red * cc->max_entry / 65535] & cc->masks.red; - igreen = cc->clut[green * cc->max_entry / 65535] & cc->masks.green; - iblue = cc->clut[blue * cc->max_entry / 65535] & cc->masks.blue; - - return ired | igreen | iblue; - } - - case GDK_CC_MODE_PALETTE: - return gdk_color_context_get_pixel_from_palette (cc, &red, &green, &blue, failed); - - case GDK_CC_MODE_STD_CMAP: - default: - { - GdkColor color; - GdkColor *result; - - color.red = red; - color.green = green; - color.blue = blue; - - result = g_hash_table_lookup (cc->color_hash, &color); - - if (!result) - { - color.red = red; - color.green = green; - color.blue = blue; - color.pixel = 0; - - if (!gdk_color_alloc (cc->colormap, &color)) - *failed = TRUE; - else - { - GdkColor *cnew; - - /* XXX: the following comment comes directly from - * XCC.c. I don't know if it is relevant for - * gdk_color_alloc() as it is for XAllocColor() - * - Federico - */ - /* - * I can't figure this out entirely, but it *is* possible - * that XAllocColor succeeds, even if the number of - * allocations we've made exceeds the number of available - * colors in the current colormap. And therefore it - * might be necessary for us to resize the CLUT. - */ - - if (cc->num_allocated == cc->max_colors) - { - cc->max_colors *= 2; - - GDK_NOTE (COLOR_CONTEXT, - g_print ("gdk_color_context_get_pixel: " - "resizing CLUT to %i entries\n", - cc->max_colors)); - - cc->clut = g_realloc (cc->clut, - cc->max_colors * sizeof (gulong)); - } - - /* Key and value are the same color structure */ - - cnew = g_new (GdkColor, 1); - *cnew = color; - g_hash_table_insert (cc->color_hash, cnew, cnew); - - cc->clut[cc->num_allocated] = color.pixel; - cc->num_allocated++; - return color.pixel; - } - } - - return result->pixel; - } - } -} - -void -gdk_color_context_get_pixels (GdkColorContext *cc, - gushort *reds, - gushort *greens, - gushort *blues, - gint ncolors, - gulong *colors, - gint *nallocated) -{ - gint i, k, idx; - gint cmapsize, ncols = 0, nopen = 0, counter = 0; - gint bad_alloc = FALSE; - gint failed[MAX_IMAGE_COLORS], allocated[MAX_IMAGE_COLORS]; - GdkColor defs[MAX_IMAGE_COLORS], cmap[MAX_IMAGE_COLORS]; -#ifdef G_ENABLE_DEBUG - gint exact_col = 0, subst_col = 0, close_col = 0, black_col = 0; -#endif - g_assert (cc != NULL); - g_assert (reds != NULL); - g_assert (greens != NULL); - g_assert (blues != NULL); - g_assert (colors != NULL); - g_assert (nallocated != NULL); - - memset (defs, 0, MAX_IMAGE_COLORS * sizeof (GdkColor)); - memset (failed, 0, MAX_IMAGE_COLORS * sizeof (gint)); - memset (allocated, 0, MAX_IMAGE_COLORS * sizeof (gint)); - - /* Will only have a value if used by the progressive image loader */ - - ncols = *nallocated; - - *nallocated = 0; - - /* First allocate all pixels */ - - for (i = 0; i < ncolors; i++) - { - /* colors[i] is only zero if the pixel at that location hasn't - * been allocated yet. This is a sanity check required for proper - * color allocation by the progressive image loader - */ - - if (colors[i] == 0) - { - defs[i].red = reds[i]; - defs[i].green = greens[i]; - defs[i].blue = blues[i]; - - colors[i] = gdk_color_context_get_pixel (cc, reds[i], greens[i], blues[i], - &bad_alloc); - - /* successfully allocated, store it */ - - if (!bad_alloc) - { - defs[i].pixel = colors[i]; - allocated[ncols++] = colors[i]; - } - else - failed[nopen++] = i; - } - } - - *nallocated = ncols; - - /* all colors available, all done */ - - if ((ncols == ncolors) || (nopen == 0)) - { - GDK_NOTE (COLOR_CONTEXT, - g_print ("gdk_color_context_get_pixels: got all %i colors; " - "(%i colors allocated so far)\n", ncolors, cc->num_allocated)); - - return; - } - - /* The fun part. We now try to allocate the colors we couldn't allocate - * directly. The first step will map a color onto its nearest color - * that has been allocated (either by us or someone else). If any colors - * remain unallocated, we map these onto the colors that we have allocated - * ourselves. - */ - - /* read up to MAX_IMAGE_COLORS colors of the current colormap */ - - cmapsize = MIN (cc->num_colors, MAX_IMAGE_COLORS); - - /* see if the colormap has any colors to read */ - - if (cmapsize < 0) - { - g_warning ("gdk_color_context_get_pixels: oops! no colors available, " - "your images will look *really* ugly."); - - return; - } - -#ifdef G_ENABLE_DEBUG - exact_col = ncols; -#endif - - /* initialize pixels */ - - for (i = 0; i < cmapsize; i++) - { - cmap[i].pixel = i; - cmap[i].red = cmap[i].green = cmap[i].blue = 0; - } - - /* read the colormap */ - - my_x_query_colors (cc->colormap, cmap, cmapsize); - - /* get a close match for any unallocated colors */ - - counter = nopen; - nopen = 0; - idx = 0; - - do - { - gint d, j, mdist, close, ri, gi, bi; - gint rd, gd, bd; - - i = failed[idx]; - - mdist = 0x1000000; - close = -1; - - /* Store these vals. Small performance increase as this skips three - * indexing operations in the loop code. - */ - - ri = reds[i]; - gi = greens[i]; - bi = blues[i]; - - /* Walk all colors in the colormap and see which one is the - * closest. Uses plain least squares. - */ - - for (j = 0; (j < cmapsize) && (mdist != 0); j++) - { - /* Don't replace these by shifts; the sign may get clobbered */ - - rd = (ri - cmap[j].red) / 256; - gd = (gi - cmap[j].green) / 256; - bd = (bi - cmap[j].blue) / 256; - - d = rd * rd + gd * gd + bd * bd; - - if (d < mdist) - { - close = j; - mdist = d; - } - } - - if (close != -1) - { - rd = cmap[close].red; - gd = cmap[close].green; - bd = cmap[close].blue; - - /* allocate */ - - colors[i] = gdk_color_context_get_pixel (cc, rd, gd, bd, &bad_alloc); - - /* store */ - - if (!bad_alloc) - { - defs[i] = cmap[close]; - defs[i].pixel = colors[i]; - allocated[ncols++] = colors[i]; -#ifdef G_ENABLE_DEBUG - close_col++; -#endif - } else - failed[nopen++] = i; - } else - failed[nopen++] = i; - /* deal with in next stage if allocation failed */ - } - while (++idx < counter); - - *nallocated = ncols; - - /* This is the maximum no. of allocated colors. See also the nopen == 0 - * note above. - */ - - if ((ncols == ncolors) || (nopen == 0)) - { - GDK_NOTE (COLOR_CONTEXT, - g_print ("gdk_color_context_get_pixels: got %i colors, %i exact and " - "%i close (%i colors allocated so far)\n", - ncolors, exact_col, close_col, cc->num_allocated)); - - return; - } - - /* Now map any remaining unallocated pixels into the colors we did get */ - - idx = 0; - - do - { - gint d, mdist, close, ri, gi, bi; - gint j, rd, gd, bd; - - i = failed[idx]; - - mdist = 0x1000000; - close = -1; - - /* store */ - - ri = reds[i]; - gi = greens[i]; - bi = blues[i]; - - /* search allocated colors */ - - for (j = 0; (j < ncols) && (mdist != 0); j++) - { - k = allocated[j]; - - /* Don't replace these by shifts; the sign may get clobbered */ - - rd = (ri - defs[k].red) / 256; - gd = (gi - defs[k].green) / 256; - bd = (bi - defs[k].blue) / 256; - - d = rd * rd + gd * gd + bd * bd; - - if (d < mdist) - { - close = k; - mdist = d; - } - } - - if (close < 0) - { - /* too bad, map to black */ - - defs[i].pixel = cc->black_pixel; - defs[i].red = defs[i].green = defs[i].blue = 0; -#ifdef G_ENABLE_DEBUG - black_col++; -#endif - } - else - { - defs[i] = defs[close]; -#ifdef G_ENABLE_DEBUG - subst_col++; -#endif - } - - colors[i] = defs[i].pixel; - } - while (++idx < nopen); - - GDK_NOTE (COLOR_CONTEXT, - g_print ("gdk_color_context_get_pixels: got %i colors, %i exact, %i close, " - "%i substituted, %i to black (%i colors allocated so far)\n", - ncolors, exact_col, close_col, subst_col, black_col, cc->num_allocated)); -} - -void -gdk_color_context_get_pixels_incremental (GdkColorContext *cc, - gushort *reds, - gushort *greens, - gushort *blues, - gint ncolors, - gint *used, - gulong *colors, - gint *nallocated) -{ - gint i, k, idx; - gint cmapsize, ncols = 0, nopen = 0, counter = 0; - gint bad_alloc = FALSE; - gint failed[MAX_IMAGE_COLORS], allocated[MAX_IMAGE_COLORS]; - GdkColor defs[MAX_IMAGE_COLORS], cmap[MAX_IMAGE_COLORS]; -#ifdef G_ENABLE_DEBUG - gint exact_col = 0, subst_col = 0, close_col = 0, black_col = 0; -#endif - - g_assert (cc != NULL); - g_assert (reds != NULL); - g_assert (greens != NULL); - g_assert (blues != NULL); - g_assert (used != NULL); - g_assert (colors != NULL); - g_assert (nallocated != NULL); - - memset (defs, 0, MAX_IMAGE_COLORS * sizeof (GdkColor)); - memset (failed, 0, MAX_IMAGE_COLORS * sizeof (gint)); - memset (allocated, 0, MAX_IMAGE_COLORS * sizeof (gint)); - - /* Will only have a value if used by the progressive image loader */ - - ncols = *nallocated; - - *nallocated = 0; - - /* First allocate all pixels */ - - for (i = 0; i < ncolors; i++) - { - /* used[i] is only -1 if the pixel at that location hasn't - * been allocated yet. This is a sanity check required for proper - * color allocation by the progressive image loader. - * When colors[i] == 0 it indicates the slot is available for - * allocation. - */ - - if (used[i] != FALSE) - { - if (colors[i] == 0) - { - defs[i].red = reds[i]; - defs[i].green = greens[i]; - defs[i].blue = blues[i]; - - colors[i] = gdk_color_context_get_pixel (cc, reds[i], greens[i], blues[i], &bad_alloc); - - /* successfully allocated, store it */ - - if (!bad_alloc) - { - defs[i].pixel = colors[i]; - allocated[ncols++] = colors[i]; - } - else - failed[nopen++] = i; - } -#ifdef DEBUG - else - GDK_NOTE (COLOR_CONTEXT, - g_print ("gdk_color_context_get_pixels_incremental: " - "pixel at slot %i already allocated, skipping\n", i)); -#endif - } - } - - *nallocated = ncols; - - if ((ncols == ncolors) || (nopen == 0)) - { - GDK_NOTE (COLOR_CONTEXT, - g_print ("gdk_color_context_get_pixels_incremental: got all %i colors " - "(%i colors allocated so far)\n", - ncolors, cc->num_allocated)); - - return; - } - - cmapsize = MIN (cc->num_colors, MAX_IMAGE_COLORS); - - if (cmapsize < 0) - { - g_warning ("gdk_color_context_get_pixels_incremental: oops! " - "No colors available images will look *really* ugly."); - return; - } - -#ifdef G_ENABLE_DEBUG - exact_col = ncols; -#endif - - /* initialize pixels */ - - for (i = 0; i < cmapsize; i++) - { - cmap[i].pixel = i; - cmap[i].red = cmap[i].green = cmap[i].blue = 0; - } - - /* read */ - - my_x_query_colors (cc->colormap, cmap, cmapsize); - - /* now match any unallocated colors */ - - counter = nopen; - nopen = 0; - idx = 0; - - do - { - gint d, j, mdist, close, ri, gi, bi; - gint rd, gd, bd; - - i = failed[idx]; - - mdist = 0x1000000; - close = -1; - - /* store */ - - ri = reds[i]; - gi = greens[i]; - bi = blues[i]; - - for (j = 0; (j < cmapsize) && (mdist != 0); j++) - { - /* Don't replace these by shifts; the sign may get clobbered */ - - rd = (ri - cmap[j].red) / 256; - gd = (gi - cmap[j].green) / 256; - bd = (bi - cmap[j].blue) / 256; - - d = rd * rd + gd * gd + bd * bd; - - if (d < mdist) - { - close = j; - mdist = d; - } - } - - if (close != -1) - { - rd = cmap[close].red; - gd = cmap[close].green; - bd = cmap[close].blue; - - /* allocate */ - - colors[i] = gdk_color_context_get_pixel (cc, rd, gd, bd, &bad_alloc); - - /* store */ - - if (!bad_alloc) - { - defs[i] = cmap[close]; - defs[i].pixel = colors[i]; - allocated[ncols++] = colors[i]; -#ifdef G_ENABLE_DEBUG - close_col++; -#endif - } - else - failed[nopen++] = i; - } - else - failed[nopen++] = i; - /* deal with in next stage if allocation failed */ - } - while (++idx < counter); - - *nallocated = ncols; - - if ((ncols == ncolors) || (nopen == 0)) - { - GDK_NOTE (COLOR_CONTEXT, - g_print ("gdk_color_context_get_pixels_incremental: " - "got %i colors, %i exact and %i close " - "(%i colors allocated so far)\n", - ncolors, exact_col, close_col, cc->num_allocated)); - - return; - } - - /* map remaining unallocated pixels into colors we did get */ - - idx = 0; - - do - { - gint d, mdist, close, ri, gi, bi; - gint j, rd, gd, bd; - - i = failed[idx]; - - mdist = 0x1000000; - close = -1; - - ri = reds[i]; - gi = greens[i]; - bi = blues[i]; - - /* search allocated colors */ - - for (j = 0; (j < ncols) && (mdist != 0); j++) - { - k = allocated[j]; - - /* downscale */ - /* Don't replace these by shifts; the sign may get clobbered */ - - rd = (ri - defs[k].red) / 256; - gd = (gi - defs[k].green) / 256; - bd = (bi - defs[k].blue) / 256; - - d = rd * rd + gd * gd + bd * bd; - - if (d < mdist) - { - close = k; - mdist = d; - } - } - - if (close < 0) - { - /* too bad, map to black */ - - defs[i].pixel = cc->black_pixel; - defs[i].red = defs[i].green = defs[i].blue = 0; -#ifdef G_ENABLE_DEBUG - black_col++; -#endif - } - else - { - defs[i] = defs[close]; -#ifdef G_ENABLE_DEBUG - subst_col++; -#endif - } - - colors[i] = defs[i].pixel; - } - while (++idx < nopen); - - GDK_NOTE (COLOR_CONTEXT, - g_print ("gdk_color_context_get_pixels_incremental: " - "got %i colors, %i exact, %i close, %i substituted, %i to black " - "(%i colors allocated so far)\n", - ncolors, exact_col, close_col, subst_col, black_col, cc->num_allocated)); -} - -gint -gdk_color_context_query_color (GdkColorContext *cc, - GdkColor *color) -{ - return gdk_color_context_query_colors (cc, color, 1); -} - -gint -gdk_color_context_query_colors (GdkColorContext *cc, - GdkColor *colors, - gint num_colors) -{ - gint i; - GdkColor *tc; - - g_assert (cc != NULL); - g_assert (colors != NULL); - - switch (cc->mode) - { - case GDK_CC_MODE_BW: - for (i = 0, tc = colors; i < num_colors; i++, tc++) - { - if (tc->pixel == cc->white_pixel) - tc->red = tc->green = tc->blue = 65535; - else - tc->red = tc->green = tc->blue = 0; - } - break; - - case GDK_CC_MODE_TRUE: - if (cc->clut == NULL) - for (i = 0, tc = colors; i < num_colors; i++, tc++) - { - tc->red = ((tc->pixel & cc->masks.red) >> cc->shifts.red) << (16 - cc->bits.red); - tc->green = ((tc->pixel & cc->masks.green) >> cc->shifts.green) << (16 - cc->bits.green); - tc->blue = ((tc->pixel & cc->masks.blue) >> cc->shifts.blue) << (16 - cc->bits.blue); - } - else - { - my_x_query_colors (cc->colormap, colors, num_colors); - return 1; - } - break; - - case GDK_CC_MODE_STD_CMAP: - default: - if (cc->cmap == NULL) - { - my_x_query_colors (cc->colormap, colors, num_colors); - return 1; - } - else - { - gint first, last, half; - gulong half_pixel; - - for (i = 0, tc = colors; i < num_colors; i++) - { - first = 0; - last = cc->num_colors - 1; - - while (first <= last) - { - half = (first + last) / 2; - half_pixel = cc->cmap[half].pixel; - - if (tc->pixel == half_pixel) - { - tc->red = cc->cmap[half].red; - tc->green = cc->cmap[half].green; - tc->blue = cc->cmap[half].blue; - first = last + 1; /* false break */ - } - else - { - if (tc->pixel > half_pixel) - first = half + 1; - else - last = half - 1; - } - } - } - return 1; - } - break; - } - return 1; -} - -gint -gdk_color_context_add_palette (GdkColorContext *cc, - GdkColor *palette, - gint num_palette) -{ - gint i, j, erg; - gushort r, g, b; - gulong pixel[1]; - - g_assert (cc != NULL); - - /* initialize this palette (will also erase previous palette as well) */ - - init_palette (cc); - - /* restore previous mode if we aren't adding a new palette */ - - if (num_palette == 0) - { - /* GDK_CC_MODE_STD_CMAP uses a hash table, so we'd better initialize one */ - - /* XXX: here, the hash table is already initialized */ - - return 0; - } - - /* Initialize a hash table for this palette (we need one for allocating - * the pixels in the palette using the current settings) - */ - - if (cc->color_hash == NULL) - cc->color_hash = g_hash_table_new (hash_color, compare_colors); - - /* copy incoming palette */ - - cc->palette = g_new0(GdkColor, num_palette); - - j = 0; - - for (i = 0; i < num_palette; i++) - { - erg = 0; - pixel[0] = 0; - - /* try to allocate this color */ - - r = palette[i].red; - g = palette[i].green; - b = palette[i].blue; - - gdk_color_context_get_pixels (cc, &r, &g, &b, 1, pixel, &erg); - - /* only store if we succeed */ - - if (erg) - { - /* store in palette */ - - cc->palette[j].red = r; - cc->palette[j].green = g; - cc->palette[j].blue = b; - cc->palette[j].pixel = pixel[0]; - - /* move to next slot */ - - j++; - } - } - - /* resize to fit */ - - if (j != num_palette) - cc->palette = g_realloc (cc->palette, j * sizeof (GdkColor)); - - /* clear the hash table, we don't use it when dithering */ - - if (cc->color_hash) - { - g_hash_table_destroy (cc->color_hash); - cc->color_hash = NULL; - } - - /* store real palette size */ - - cc->num_palette = j; - - /* switch to palette mode */ - - cc->mode = GDK_CC_MODE_PALETTE; - - /* sort palette */ - - qsort (cc->palette, cc->num_palette, sizeof (GdkColor), pixel_sort); - - cc->fast_dither = NULL; - - return j; -} - -void -gdk_color_context_init_dither (GdkColorContext *cc) -{ - gint rr, gg, bb, err, erg, erb; - gint success = FALSE; - - g_assert (cc != NULL); - - /* now we can initialize the fast dither matrix */ - - if (cc->fast_dither == NULL) - cc->fast_dither = g_new (GdkColorContextDither, 1); - - /* Fill it. We ignore unsuccessful allocations, they are just mapped - * to black instead */ - - for (rr = 0; rr < 32; rr++) - for (gg = 0; gg < 32; gg++) - for (bb = 0; bb < 32; bb++) - { - err = (rr << 3) | (rr >> 2); - erg = (gg << 3) | (gg >> 2); - erb = (bb << 3) | (bb >> 2); - - cc->fast_dither->fast_rgb[rr][gg][bb] = - gdk_color_context_get_index_from_palette (cc, &err, &erg, &erb, &success); - cc->fast_dither->fast_err[rr][gg][bb] = err; - cc->fast_dither->fast_erg[rr][gg][bb] = erg; - cc->fast_dither->fast_erb[rr][gg][bb] = erb; - } -} - -void -gdk_color_context_free_dither (GdkColorContext *cc) -{ - g_assert (cc != NULL); - - if (cc->fast_dither) - g_free (cc->fast_dither); - - cc->fast_dither = NULL; -} - -gulong -gdk_color_context_get_pixel_from_palette (GdkColorContext *cc, - gushort *red, - gushort *green, - gushort *blue, - gint *failed) -{ - gulong pixel = 0; - gint dif, dr, dg, db, j = -1; - gint mindif = 0x7fffffff; - gint err = 0, erg = 0, erb = 0; - gint i; - - g_assert (cc != NULL); - g_assert (red != NULL); - g_assert (green != NULL); - g_assert (blue != NULL); - g_assert (failed != NULL); - - *failed = FALSE; - - for (i = 0; i < cc->num_palette; i++) - { - dr = *red - cc->palette[i].red; - dg = *green - cc->palette[i].green; - db = *blue - cc->palette[i].blue; - - dif = dr * dr + dg * dg + db * db; - - if (dif < mindif) - { - mindif = dif; - j = i; - pixel = cc->palette[i].pixel; - err = dr; - erg = dg; - erb = db; - - if (mindif == 0) - break; - } - } - - /* we failed to map onto a color */ - - if (j == -1) - *failed = TRUE; - else - { - *red = ABS (err); - *green = ABS (erg); - *blue = ABS (erb); - } - - return pixel; -} - -guchar -gdk_color_context_get_index_from_palette (GdkColorContext *cc, - gint *red, - gint *green, - gint *blue, - gint *failed) -{ - gint dif, dr, dg, db, j = -1; - gint mindif = 0x7fffffff; - gint err = 0, erg = 0, erb = 0; - gint i; - - g_assert (cc != NULL); - g_assert (red != NULL); - g_assert (green != NULL); - g_assert (blue != NULL); - g_assert (failed != NULL); - - *failed = FALSE; - - for (i = 0; i < cc->num_palette; i++) - { - dr = *red - cc->palette[i].red; - dg = *green - cc->palette[i].green; - db = *blue - cc->palette[i].blue; - - dif = dr * dr + dg * dg + db * db; - - if (dif < mindif) - { - mindif = dif; - j = i; - err = dr; - erg = dg; - erb = db; - - if (mindif == 0) - break; - } - } - - /* we failed to map onto a color */ - - if (j == -1) - { - *failed = TRUE; - j = 0; - } - else - { - /* return error fractions */ - - *red = err; - *green = erg; - *blue = erb; - } - - return j; -} diff --git a/gdk/x11/gdkcolor-x11.c b/gdk/x11/gdkcolor-x11.c deleted file mode 100644 index f55869b719..0000000000 --- a/gdk/x11/gdkcolor-x11.c +++ /dev/null @@ -1,749 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#include <X11/Xlib.h> -#include "gdk.h" -#include "gdkprivate.h" - - -static gint gdk_colormap_match_color (GdkColormap *cmap, - GdkColor *color, - const gchar *available); -static void gdk_colormap_add (GdkColormap *cmap); -static void gdk_colormap_remove (GdkColormap *cmap); -static guint gdk_colormap_hash (Colormap *cmap); -static gint gdk_colormap_cmp (Colormap *a, - Colormap *b); -static void gdk_colormap_real_destroy (GdkColormap *colormap); - -static GHashTable *colormap_hash = NULL; - - -GdkColormap* -gdk_colormap_new (GdkVisual *visual, - gint private_cmap) -{ - GdkColormap *colormap; - GdkColormapPrivate *private; - Visual *xvisual; - int size; - int i; - - g_return_val_if_fail (visual != NULL, NULL); - - private = g_new (GdkColormapPrivate, 1); - colormap = (GdkColormap*) private; - - private->xdisplay = gdk_display; - private->visual = visual; - private->next_color = 0; - private->ref_count = 1; - xvisual = ((GdkVisualPrivate*) visual)->xvisual; - - colormap->size = visual->colormap_size; - colormap->colors = g_new (GdkColor, colormap->size); - - switch (visual->type) - { - case GDK_VISUAL_GRAYSCALE: - case GDK_VISUAL_PSEUDO_COLOR: - private->private_val = private_cmap; - private->xcolormap = XCreateColormap (private->xdisplay, gdk_root_window, - xvisual, (private_cmap) ? (AllocAll) : (AllocNone)); - - if (private_cmap) - { - XColor *default_colors; - - default_colors = g_new (XColor, colormap->size); - - for (i = 0; i < colormap->size; i++) - default_colors[i].pixel = i; - - XQueryColors (private->xdisplay, - DefaultColormap (private->xdisplay, gdk_screen), - default_colors, colormap->size); - - for (i = 0; i < colormap->size; i++) - { - colormap->colors[i].pixel = default_colors[i].pixel; - colormap->colors[i].red = default_colors[i].red; - colormap->colors[i].green = default_colors[i].green; - colormap->colors[i].blue = default_colors[i].blue; - } - - gdk_colormap_change (colormap, colormap->size); - - g_free (default_colors); - } - break; - - case GDK_VISUAL_DIRECT_COLOR: - private->private_val = TRUE; - private->xcolormap = XCreateColormap (private->xdisplay, gdk_root_window, - xvisual, AllocAll); - - size = 1 << visual->red_prec; - for (i = 0; i < size; i++) - colormap->colors[i].red = i * 65535 / (size - 1); - - size = 1 << visual->green_prec; - for (i = 0; i < size; i++) - colormap->colors[i].green = i * 65535 / (size - 1); - - size = 1 << visual->blue_prec; - for (i = 0; i < size; i++) - colormap->colors[i].blue = i * 65535 / (size - 1); - - gdk_colormap_change (colormap, colormap->size); - break; - - case GDK_VISUAL_STATIC_GRAY: - case GDK_VISUAL_STATIC_COLOR: - case GDK_VISUAL_TRUE_COLOR: - private->private_val = FALSE; - private->xcolormap = XCreateColormap (private->xdisplay, gdk_root_window, - xvisual, AllocNone); - break; - } - - gdk_colormap_add (colormap); - - return colormap; -} - -static void -gdk_colormap_real_destroy (GdkColormap *colormap) -{ - GdkColormapPrivate *private = (GdkColormapPrivate*) colormap; - - g_return_if_fail (colormap != NULL); - - if (private->ref_count > 0) - return; - - gdk_colormap_remove (colormap); - XFreeColormap (private->xdisplay, private->xcolormap); - g_free (colormap->colors); - g_free (colormap); -} - -GdkColormap* -gdk_colormap_ref (GdkColormap *cmap) -{ - GdkColormapPrivate *private = (GdkColormapPrivate *)cmap; - g_return_val_if_fail (cmap != NULL, NULL); - - private->ref_count += 1; - return cmap; -} - -void -gdk_colormap_unref (GdkColormap *cmap) -{ - GdkColormapPrivate *private = (GdkColormapPrivate *)cmap; - g_return_if_fail (cmap != NULL); - - private->ref_count -= 1; - if (private->ref_count == 0) - gdk_colormap_real_destroy (cmap); -} - -GdkColormap* -gdk_colormap_get_system (void) -{ - static GdkColormap *colormap = NULL; - GdkColormapPrivate *private; - XColor *xpalette; - gint i; - - if (!colormap) - { - private = g_new (GdkColormapPrivate, 1); - colormap = (GdkColormap*) private; - - private->xdisplay = gdk_display; - private->xcolormap = DefaultColormap (gdk_display, gdk_screen); - private->visual = gdk_visual_get_system (); - private->private_val = FALSE; - private->next_color = 0; - private->ref_count = 1; - - colormap->size = private->visual->colormap_size; - colormap->colors = g_new (GdkColor, colormap->size); - - if ((private->visual->type == GDK_VISUAL_GRAYSCALE) || - (private->visual->type == GDK_VISUAL_PSEUDO_COLOR)) - { - xpalette = g_new (XColor, colormap->size); - - for (i = 0; i < colormap->size; i++) - { - xpalette[i].pixel = i; - xpalette[i].red = 0; - xpalette[i].green = 0; - xpalette[i].blue = 0; - } - - XQueryColors (gdk_display, private->xcolormap, xpalette, - colormap->size); - - for (i = 0; i < colormap->size; i++) - { - colormap->colors[i].pixel = xpalette[i].pixel; - colormap->colors[i].red = xpalette[i].red; - colormap->colors[i].green = xpalette[i].green; - colormap->colors[i].blue = xpalette[i].blue; - } - - g_free (xpalette); - } - - gdk_colormap_add (colormap); - } - - return colormap; -} - -gint -gdk_colormap_get_system_size (void) -{ - return DisplayCells (gdk_display, gdk_screen); -} - -void -gdk_colormap_change (GdkColormap *colormap, - gint ncolors) -{ - GdkColormapPrivate *private; - GdkVisual *visual; - XColor *palette; - gint shift; - int max_colors; - int size; - int i; - - g_return_if_fail (colormap != NULL); - - palette = g_new (XColor, ncolors); - - private = (GdkColormapPrivate*) colormap; - switch (private->visual->type) - { - case GDK_VISUAL_GRAYSCALE: - case GDK_VISUAL_PSEUDO_COLOR: - for (i = 0; i < ncolors; i++) - { - palette[i].pixel = colormap->colors[i].pixel; - palette[i].red = colormap->colors[i].red; - palette[i].green = colormap->colors[i].green; - palette[i].blue = colormap->colors[i].blue; - palette[i].flags = DoRed | DoGreen | DoBlue; - } - - XStoreColors (private->xdisplay, private->xcolormap, palette, ncolors); - private->next_color = MAX (private->next_color, ncolors); - break; - - case GDK_VISUAL_DIRECT_COLOR: - visual = private->visual; - - shift = visual->red_shift; - max_colors = 1 << visual->red_prec; - size = (ncolors < max_colors) ? (ncolors) : (max_colors); - - for (i = 0; i < size; i++) - { - palette[i].pixel = i << shift; - palette[i].red = colormap->colors[i].red; - palette[i].flags = DoRed; - } - - XStoreColors (private->xdisplay, private->xcolormap, palette, size); - - shift = visual->green_shift; - max_colors = 1 << visual->green_prec; - size = (ncolors < max_colors) ? (ncolors) : (max_colors); - - for (i = 0; i < size; i++) - { - palette[i].pixel = i << shift; - palette[i].green = colormap->colors[i].green; - palette[i].flags = DoGreen; - } - - XStoreColors (private->xdisplay, private->xcolormap, palette, size); - - shift = visual->blue_shift; - max_colors = 1 << visual->blue_prec; - size = (ncolors < max_colors) ? (ncolors) : (max_colors); - - for (i = 0; i < size; i++) - { - palette[i].pixel = i << shift; - palette[i].blue = colormap->colors[i].blue; - palette[i].flags = DoBlue; - } - - XStoreColors (private->xdisplay, private->xcolormap, palette, size); - break; - - default: - break; - } - - g_free (palette); -} - -void -gdk_colors_store (GdkColormap *colormap, - GdkColor *colors, - gint ncolors) -{ - gint i; - - for (i = 0; i < ncolors; i++) - { - colormap->colors[i].pixel = colors[i].pixel; - colormap->colors[i].red = colors[i].red; - colormap->colors[i].green = colors[i].green; - colormap->colors[i].blue = colors[i].blue; - } - - gdk_colormap_change (colormap, ncolors); -} - -gint -gdk_colors_alloc (GdkColormap *colormap, - gint contiguous, - gulong *planes, - gint nplanes, - gulong *pixels, - gint npixels) -{ - GdkColormapPrivate *private; - gint return_val; - - g_return_val_if_fail (colormap != NULL, 0); - - private = (GdkColormapPrivate*) colormap; - - return_val = XAllocColorCells (private->xdisplay, private->xcolormap, - contiguous, planes, nplanes, pixels, npixels); - - return return_val; -} - -void -gdk_colors_free (GdkColormap *colormap, - gulong *pixels, - gint npixels, - gulong planes) -{ - GdkColormapPrivate *private; - - g_return_if_fail (colormap != NULL); - - private = (GdkColormapPrivate*) colormap; - - XFreeColors (private->xdisplay, private->xcolormap, - pixels, npixels, planes); -} - -gint -gdk_color_white (GdkColormap *colormap, - GdkColor *color) -{ - gint return_val; - - g_return_val_if_fail (colormap != NULL, FALSE); - - if (color) - { - color->pixel = WhitePixel (gdk_display, gdk_screen); - color->red = 65535; - color->green = 65535; - color->blue = 65535; - - return_val = gdk_color_alloc (colormap, color); - } - else - return_val = FALSE; - - return return_val; -} - -gint -gdk_color_black (GdkColormap *colormap, - GdkColor *color) -{ - gint return_val; - - g_return_val_if_fail (colormap != NULL, FALSE); - - if (color) - { - color->pixel = BlackPixel (gdk_display, gdk_screen); - color->red = 0; - color->green = 0; - color->blue = 0; - - return_val = gdk_color_alloc (colormap, color); - } - else - return_val = FALSE; - - return return_val; -} - -gint -gdk_color_parse (const gchar *spec, - GdkColor *color) -{ - Colormap xcolormap; - XColor xcolor; - gint return_val; - - g_return_val_if_fail (spec != NULL, FALSE); - g_return_val_if_fail (color != NULL, FALSE); - - xcolormap = DefaultColormap (gdk_display, gdk_screen); - - if (XParseColor (gdk_display, xcolormap, spec, &xcolor)) - { - return_val = TRUE; - color->red = xcolor.red; - color->green = xcolor.green; - color->blue = xcolor.blue; - } - else - return_val = FALSE; - - return return_val; -} - -gint -gdk_color_alloc (GdkColormap *colormap, - GdkColor *color) -{ - GdkColormapPrivate *private; - GdkVisual *visual; - XColor xcolor; - gchar *available = NULL; - gint return_val; - gint i, index; - - g_return_val_if_fail (colormap != NULL, FALSE); - g_return_val_if_fail (color != NULL, FALSE); - - xcolor.red = color->red; - xcolor.green = color->green; - xcolor.blue = color->blue; - xcolor.pixel = color->pixel; - xcolor.flags = DoRed | DoGreen | DoBlue; - - return_val = FALSE; - private = (GdkColormapPrivate*) colormap; - - switch (private->visual->type) - { - case GDK_VISUAL_GRAYSCALE: - case GDK_VISUAL_PSEUDO_COLOR: - if (private->private_val) - { - if (private->next_color >= colormap->size) - { - available = g_new (gchar, colormap->size); - for (i = 0; i < colormap->size; i++) - available[i] = TRUE; - - index = gdk_colormap_match_color (colormap, color, available); - if (index != -1) - { - available[index] = FALSE; - *color = colormap->colors[index]; - return_val = TRUE; - } - else - { - return_val = FALSE; - } - } - else - { - xcolor.pixel = colormap->size - 1 -private->next_color; - color->pixel = xcolor.pixel; - private->next_color += 1; - - XStoreColor (private->xdisplay, private->xcolormap, &xcolor); - return_val = TRUE; - } - } - else - { - while (1) - { - if (XAllocColor (private->xdisplay, private->xcolormap, &xcolor)) - { - color->pixel = xcolor.pixel; - color->red = xcolor.red; - color->green = xcolor.green; - color->blue = xcolor.blue; - - if (color->pixel < colormap->size) - colormap->colors[color->pixel] = *color; - - return_val = TRUE; - break; - } - else - { - if (available == NULL) - { - available = g_new (gchar, colormap->size); - for (i = 0; i < colormap->size; i++) - available[i] = TRUE; - } - - index = gdk_colormap_match_color (colormap, color, available); - if (index != -1) - { - available[index] = FALSE; - xcolor.red = colormap->colors[index].red; - xcolor.green = colormap->colors[index].green; - xcolor.blue = colormap->colors[index].blue; - } - else - { - return_val = FALSE; - break; - } - } - } - } - break; - - case GDK_VISUAL_DIRECT_COLOR: - visual = private->visual; - xcolor.pixel = (((xcolor.red >> (16 - visual->red_prec)) << visual->red_shift) + - ((xcolor.green >> (16 - visual->green_prec)) << visual->green_shift) + - ((xcolor.blue >> (16 - visual->blue_prec)) << visual->blue_shift)); - color->pixel = xcolor.pixel; - return_val = TRUE; - break; - - case GDK_VISUAL_STATIC_GRAY: - case GDK_VISUAL_STATIC_COLOR: - case GDK_VISUAL_TRUE_COLOR: - if (XAllocColor (private->xdisplay, private->xcolormap, &xcolor)) - { - color->pixel = xcolor.pixel; - return_val = TRUE; - } - else - return_val = FALSE; - break; - } - - if (available) - g_free (available); - - return return_val; -} - -gint -gdk_color_change (GdkColormap *colormap, - GdkColor *color) -{ - GdkColormapPrivate *private; - XColor xcolor; - - g_return_val_if_fail (colormap != NULL, FALSE); - g_return_val_if_fail (color != NULL, FALSE); - - xcolor.pixel = color->pixel; - xcolor.red = color->red; - xcolor.green = color->green; - xcolor.blue = color->blue; - xcolor.flags = DoRed | DoGreen | DoBlue; - - private = (GdkColormapPrivate*) colormap; - XStoreColor (private->xdisplay, private->xcolormap, &xcolor); - - return TRUE; -} - -gint -gdk_color_equal (GdkColor *colora, - GdkColor *colorb) -{ - g_return_val_if_fail (colora != NULL, FALSE); - g_return_val_if_fail (colorb != NULL, FALSE); - - return ((colora->red == colorb->red) && - (colora->green == colorb->green) && - (colora->blue == colorb->blue)); -} - -GdkColormap* -gdkx_colormap_get (Colormap xcolormap) -{ - GdkColormap *colormap; - GdkColormapPrivate *private; - - colormap = gdk_colormap_lookup (xcolormap); - if (colormap) - return colormap; - - if (xcolormap == DefaultColormap (gdk_display, gdk_screen)) - return gdk_colormap_get_system (); - - private = g_new (GdkColormapPrivate, 1); - colormap = (GdkColormap*) private; - - private->xdisplay = gdk_display; - private->xcolormap = xcolormap; - private->visual = NULL; - private->private_val = TRUE; - private->next_color = 0; - - /* To do the following safely, we would have to have some way of finding - * out what the size or visual of the given colormap is. It seems - * X doesn't allow this - */ - -#if 0 - for (i = 0; i < 256; i++) - { - xpalette[i].pixel = i; - xpalette[i].red = 0; - xpalette[i].green = 0; - xpalette[i].blue = 0; - } - - XQueryColors (gdk_display, private->xcolormap, xpalette, 256); - - for (i = 0; i < 256; i++) - { - colormap->colors[i].pixel = xpalette[i].pixel; - colormap->colors[i].red = xpalette[i].red; - colormap->colors[i].green = xpalette[i].green; - colormap->colors[i].blue = xpalette[i].blue; - } -#endif - - colormap->colors = NULL; - colormap->size = 0; - - gdk_colormap_add (colormap); - - return colormap; -} - - -static gint -gdk_colormap_match_color (GdkColormap *cmap, - GdkColor *color, - const gchar *available) -{ - GdkColor *colors; - guint sum, max; - gint rdiff, gdiff, bdiff; - gint i, index; - - g_return_val_if_fail (cmap != NULL, 0); - g_return_val_if_fail (color != NULL, 0); - - colors = cmap->colors; - max = 3 * (65536); - index = -1; - - for (i = 0; i < cmap->size; i++) - { - if ((!available) || (available && available[i])) - { - rdiff = (color->red - colors[i].red); - gdiff = (color->green - colors[i].green); - bdiff = (color->blue - colors[i].blue); - - sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff); - - if (sum < max) - { - index = i; - max = sum; - } - } - } - - return index; -} - - -GdkColormap* -gdk_colormap_lookup (Colormap xcolormap) -{ - GdkColormap *cmap; - - if (!colormap_hash) - return NULL; - - cmap = g_hash_table_lookup (colormap_hash, &xcolormap); - return cmap; -} - -static void -gdk_colormap_add (GdkColormap *cmap) -{ - GdkColormapPrivate *private; - - if (!colormap_hash) - colormap_hash = g_hash_table_new ((GHashFunc) gdk_colormap_hash, - (GCompareFunc) gdk_colormap_cmp); - - private = (GdkColormapPrivate*) cmap; - - g_hash_table_insert (colormap_hash, &private->xcolormap, cmap); -} - -static void -gdk_colormap_remove (GdkColormap *cmap) -{ - GdkColormapPrivate *private; - - if (!colormap_hash) - colormap_hash = g_hash_table_new ((GHashFunc) gdk_colormap_hash, - (GCompareFunc) gdk_colormap_cmp); - - private = (GdkColormapPrivate*) cmap; - - g_hash_table_remove (colormap_hash, &private->xcolormap); -} - -static guint -gdk_colormap_hash (Colormap *cmap) -{ - return *cmap; -} - -static gint -gdk_colormap_cmp (Colormap *a, - Colormap *b) -{ - return (*a == *b); -} diff --git a/gdk/x11/gdkcursor-x11.c b/gdk/x11/gdkcursor-x11.c deleted file mode 100644 index 185419374c..0000000000 --- a/gdk/x11/gdkcursor-x11.c +++ /dev/null @@ -1,84 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#include <X11/Xlib.h> -#include <X11/cursorfont.h> -#include "gdk.h" -#include "gdkprivate.h" - - -GdkCursor* -gdk_cursor_new (GdkCursorType cursor_type) -{ - GdkCursorPrivate *private; - GdkCursor *cursor; - Cursor xcursor; - - xcursor = XCreateFontCursor (gdk_display, cursor_type); - private = g_new (GdkCursorPrivate, 1); - private->xdisplay = gdk_display; - private->xcursor = xcursor; - cursor = (GdkCursor*) private; - cursor->type = cursor_type; - - return cursor; -} - -GdkCursor* -gdk_cursor_new_from_pixmap (GdkPixmap *source, GdkPixmap *mask, GdkColor *fg, GdkColor *bg, gint x, gint y) -{ - GdkCursorPrivate *private; - GdkCursor *cursor; - Pixmap source_pixmap, mask_pixmap; - Cursor xcursor; - XColor xfg, xbg; - - source_pixmap = ((GdkPixmapPrivate *) source)->xwindow; - mask_pixmap = ((GdkPixmapPrivate *) mask)->xwindow; - - xfg.pixel = fg->pixel; - xfg.red = fg->red; - xfg.blue = fg->blue; - xfg.green = fg->green; - xbg.pixel = bg->pixel; - xbg.red = bg->red; - xbg.blue = bg->blue; - xbg.green = bg->green; - - xcursor = XCreatePixmapCursor (gdk_display, source_pixmap, mask_pixmap, &xfg, &xbg, x, y); - private = g_new (GdkCursorPrivate, 1); - private->xdisplay = gdk_display; - private->xcursor = xcursor; - cursor = (GdkCursor *) private; - cursor->type = GDK_CURSOR_IS_PIXMAP; - - return cursor; -} - -void -gdk_cursor_destroy (GdkCursor *cursor) -{ - GdkCursorPrivate *private; - - g_return_if_fail (cursor != NULL); - - private = (GdkCursorPrivate *) cursor; - XFreeCursor (private->xdisplay, private->xcursor); - - g_free (private); -} diff --git a/gdk/x11/gdkdnd-x11.c b/gdk/x11/gdkdnd-x11.c deleted file mode 100644 index 6a74022c55..0000000000 --- a/gdk/x11/gdkdnd-x11.c +++ /dev/null @@ -1,158 +0,0 @@ -#include <X11/Xlib.h> -#include <X11/Xatom.h> -#include <string.h> -#include "gdkx.h" -#include "gdk.h" - -/* Nothing much here now, but we have to make a start some time ;-) */ - -void -gdk_dnd_set_drag_cursors(GdkCursor *default_cursor, GdkCursor *goahead_cursor) -{ - gdk_dnd.c->gdk_cursor_dragdefault = - ((GdkCursorPrivate *)default_cursor)->xcursor; - gdk_dnd.c->gdk_cursor_dragok = ((GdkCursorPrivate *)goahead_cursor)->xcursor; - - if(gdk_dnd.dnd_grabbed) - { - if(gdk_dnd.c->drag_pm_default) - /* We were displaying pixmaps for the drag */ - { - gdk_window_hide(gdk_dnd.c->drag_pm_default); - gdk_window_unref(gdk_dnd.c->drag_pm_default); - if(gdk_dnd.c->drag_pm_ok) - { - gdk_window_hide(gdk_dnd.c->drag_pm_ok); - gdk_window_unref(gdk_dnd.c->drag_pm_ok); - } - gdk_dnd.c->drag_pm_default = gdk_dnd.c->drag_pm_ok = NULL; - g_list_free(gdk_dnd.c->xids); - gdk_dnd.c->xids = NULL; - } - gdk_dnd_display_drag_cursor(-1, -1, - gdk_dnd.dnd_drag_target?TRUE:FALSE, - TRUE); - } -} - -void -gdk_dnd_set_drag_shape(GdkWindow *default_pixmapwin, - GdkPoint *default_hotspot, - GdkWindow *goahead_pixmapwin, - GdkPoint *goahead_hotspot) -{ - g_return_if_fail(default_pixmapwin != NULL); - - g_list_free(gdk_dnd.c->xids); gdk_dnd.c->xids = NULL; - if(gdk_dnd.c->drag_pm_default) - { - gdk_window_hide(gdk_dnd.c->drag_pm_default); - gdk_window_unref(gdk_dnd.c->drag_pm_default); - } - if(gdk_dnd.c->drag_pm_ok) - { - gdk_window_hide(gdk_dnd.c->drag_pm_ok); - gdk_window_unref(gdk_dnd.c->drag_pm_ok); - } - - gdk_dnd.c->drag_pm_ok = NULL; - - gdk_window_ref(default_pixmapwin); - gdk_dnd.c->drag_pm_default = default_pixmapwin; - gdk_dnd.c->default_hotspot = *default_hotspot; - gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, GUINT_TO_POINTER (((GdkWindowPrivate *)default_pixmapwin)->xwindow)); - if(goahead_pixmapwin) - { - gdk_window_ref(goahead_pixmapwin); - gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, GUINT_TO_POINTER (((GdkWindowPrivate *)goahead_pixmapwin)->xwindow)); - gdk_dnd.c->drag_pm_ok = goahead_pixmapwin; - gdk_dnd.c->ok_hotspot = *goahead_hotspot; - } - - if(gdk_dnd.dnd_grabbed) - { - gdk_dnd_display_drag_cursor(-1, -1, - gdk_dnd.dnd_drag_target?TRUE:FALSE, - TRUE); - XChangeActivePointerGrab (gdk_display, - ButtonMotionMask | - ButtonPressMask | - ButtonReleaseMask | - EnterWindowMask | LeaveWindowMask, - None, - CurrentTime); - } -} - -void -gdk_dnd_display_drag_cursor(gint x, gint y, gboolean drag_ok, - gboolean change_made) -{ - if(!gdk_dnd.dnd_grabbed) - return; - - if(gdk_dnd.c->drag_pm_default) - { - /* We're doing pixmaps here... */ - GdkWindow *mypix, *opix; - GdkPoint *myhotspot; - gint itmp; - guint masktmp; - Window wtmp; - - if(x == -2 && y == -2) /* Hide the cursors */ - { - gdk_window_hide(gdk_dnd.c->drag_pm_ok); - gdk_window_hide(gdk_dnd.c->drag_pm_default); - GDK_NOTE(DND, g_print("Hiding both drag cursors\n")); - return; - } - - if(x == -1 && y == -1) /* We're supposed to find it out for ourselves */ - XQueryPointer(gdk_display, gdk_root_window, - &wtmp, &wtmp, &x, &y, &itmp, &itmp, &masktmp); - - if(drag_ok) - { - GDK_NOTE(DND, g_print("Switching to drag_ok cursor\n")); - mypix = gdk_dnd.c->drag_pm_ok; - opix = gdk_dnd.c->drag_pm_default; - myhotspot = &gdk_dnd.c->ok_hotspot; - } - else - { - GDK_NOTE(DND, g_print("Switching to drag_default cursor\n")); - mypix = gdk_dnd.c->drag_pm_default; - opix = gdk_dnd.c->drag_pm_ok; - myhotspot = &gdk_dnd.c->default_hotspot; - } - gdk_window_move(mypix, x - myhotspot->x, y - myhotspot->y); - if(change_made) - { - GDK_NOTE(DND, g_print("Cursors switched, hide & show\n")); - gdk_window_hide(opix); - } - gdk_window_move(mypix, x - myhotspot->x, y - myhotspot->y); - if (change_made) - { - gdk_window_show(mypix); /* There ought to be a way to know if - a window is already mapped etc. */ - } - } - else if(change_made) - { - Cursor c; - /* Move cursors around */ - if(drag_ok) - c = gdk_dnd.c->gdk_cursor_dragok; - else - c = gdk_dnd.c->gdk_cursor_dragdefault; - XChangeActivePointerGrab (gdk_display, - ButtonMotionMask | - ButtonPressMask | - ButtonReleaseMask | - EnterWindowMask | LeaveWindowMask, - c, - CurrentTime); - } -} diff --git a/gdk/x11/gdkfont-x11.c b/gdk/x11/gdkfont-x11.c deleted file mode 100644 index 888afbf69e..0000000000 --- a/gdk/x11/gdkfont-x11.c +++ /dev/null @@ -1,387 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#include <X11/Xlib.h> -#include <X11/Xos.h> -#include "gdk.h" -#include "gdkprivate.h" - -GdkFont* -gdk_font_load (const gchar *font_name) -{ - GdkFont *font; - GdkFontPrivate *private; - - private = g_new (GdkFontPrivate, 1); - font = (GdkFont*) private; - - private->xdisplay = gdk_display; - private->xfont = XLoadQueryFont (private->xdisplay, font_name); - private->ref_count = 1; - - if (!private->xfont) - { - g_free (font); - return NULL; - } - else - { - font->type = GDK_FONT_FONT; - font->ascent = ((XFontStruct *) private->xfont)->ascent; - font->descent = ((XFontStruct *) private->xfont)->descent; - } - - gdk_xid_table_insert (&((XFontStruct *) private->xfont)->fid, font); - - return font; -} - -GdkFont* -gdk_fontset_load (gchar *fontset_name) -{ - GdkFont *font; - GdkFontPrivate *private; - XFontSet fontset; - gint missing_charset_count; - gchar **missing_charset_list; - gchar *def_string; - - private = g_new (GdkFontPrivate, 1); - font = (GdkFont*) private; - - private->xdisplay = gdk_display; - fontset = XCreateFontSet (gdk_display, fontset_name, - &missing_charset_list, &missing_charset_count, - &def_string); - - if (missing_charset_count) - { - gint i; - g_print ("Missing charsets in FontSet creation\n"); - for (i=0;i<missing_charset_count;i++) - g_print (" %s\n", missing_charset_list[i]); - XFreeStringList (missing_charset_list); - } - - private->ref_count = 1; - - if (!fontset) - { - g_free (font); - return NULL; - } - else - { - gint num_fonts; - gint i; - XFontStruct **font_structs; - gchar **font_names; - - private->xfont = fontset; - font->type = GDK_FONT_FONTSET; - num_fonts = XFontsOfFontSet (fontset, &font_structs, &font_names); - - font->ascent = font->descent = 0; - - for (i = 0; i < num_fonts; i++) - { - font->ascent = MAX (font->ascent, font_structs[i]->ascent); - font->descent = MAX (font->descent, font_structs[i]->descent); - } - } - return font; -} - -GdkFont* -gdk_font_ref (GdkFont *font) -{ - GdkFontPrivate *private; - - g_return_val_if_fail (font != NULL, NULL); - - private = (GdkFontPrivate*) font; - private->ref_count += 1; - return font; -} - -void -gdk_font_unref (GdkFont *font) -{ - GdkFontPrivate *private; - - g_return_if_fail (font != NULL); - - private = (GdkFontPrivate*) font; - - private->ref_count -= 1; - if (private->ref_count == 0) - { - switch (font->type) - { - case GDK_FONT_FONT: - gdk_xid_table_remove (((XFontStruct *) private->xfont)->fid); - XFreeFont (private->xdisplay, (XFontStruct *) private->xfont); - break; - case GDK_FONT_FONTSET: - XFreeFontSet (private->xdisplay, (XFontSet) private->xfont); - break; - default: - g_error ("unknown font type."); - break; - } - g_free (font); - } -} - -gint -gdk_font_id (GdkFont *font) -{ - GdkFontPrivate *font_private; - - g_return_val_if_fail (font != NULL, 0); - - font_private = (GdkFontPrivate*) font; - - if (font->type == GDK_FONT_FONT) - { - return ((XFontStruct *) font_private->xfont)->fid; - } - else - { - return 0; - } -} - -gint -gdk_font_equal (GdkFont *fonta, - GdkFont *fontb) -{ - GdkFontPrivate *privatea; - GdkFontPrivate *privateb; - - g_return_val_if_fail (fonta != NULL, FALSE); - g_return_val_if_fail (fontb != NULL, FALSE); - - privatea = (GdkFontPrivate*) fonta; - privateb = (GdkFontPrivate*) fontb; - - if (fonta->type == GDK_FONT_FONT && fontb->type == GDK_FONT_FONT) - { - return (((XFontStruct *) privatea->xfont)->fid == - ((XFontStruct *) privateb->xfont)->fid); - } - else if (fonta->type == GDK_FONT_FONTSET && fontb->type == GDK_FONT_FONTSET) - { - /* how to compare two fontsets ?? by basename or XFontSet ?? */ - return (((XFontSet) privatea->xfont) == ((XFontSet) privateb->xfont)); - } - else - /* fontset != font */ - return 0; -} - -gint -gdk_string_width (GdkFont *font, - const gchar *string) -{ - GdkFontPrivate *font_private; - gint width; - XFontStruct *xfont; - XFontSet fontset; - - g_return_val_if_fail (font != NULL, -1); - g_return_val_if_fail (string != NULL, -1); - - font_private = (GdkFontPrivate*) font; - - switch (font->type) - { - case GDK_FONT_FONT: - xfont = (XFontStruct *) font_private->xfont; - if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0)) - { - width = XTextWidth (xfont, string, strlen (string)); - } - else - { - width = XTextWidth16 (xfont, (XChar2b *) string, strlen (string) / 2); - } - break; - case GDK_FONT_FONTSET: - fontset = (XFontSet) font_private->xfont; - width = XmbTextEscapement (fontset, string, strlen(string)); - break; - default: - width = 0; - } - - return width; -} - -gint -gdk_text_width (GdkFont *font, - const gchar *text, - gint text_length) -{ - GdkFontPrivate *private; - gint width; - XFontStruct *xfont; - XFontSet fontset; - - g_return_val_if_fail (font != NULL, -1); - g_return_val_if_fail (text != NULL, -1); - - private = (GdkFontPrivate*) font; - - switch (font->type) - { - case GDK_FONT_FONT: - xfont = (XFontStruct *) private->xfont; - if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0)) - { - width = XTextWidth (xfont, text, text_length); - } - else - { - width = XTextWidth16 (xfont, (XChar2b *) text, text_length / 2); - } - break; - case GDK_FONT_FONTSET: - fontset = (XFontSet) private->xfont; - width = XmbTextEscapement (fontset, text, text_length); - break; - default: - width = 0; - } - return width; -} - -/* Problem: What if a character is a 16 bits character ?? */ -gint -gdk_char_width (GdkFont *font, - gchar character) -{ - GdkFontPrivate *private; - XCharStruct *chars; - gint width; - guint ch = character & 0xff; /* get rid of sign-extension */ - XFontStruct *xfont; - XFontSet fontset; - - g_return_val_if_fail (font != NULL, -1); - - private = (GdkFontPrivate*) font; - - switch (font->type) - { - case GDK_FONT_FONT: - /* only 8 bits characters are considered here */ - xfont = (XFontStruct *) private->xfont; - if ((xfont->min_byte1 == 0) && - (xfont->max_byte1 == 0) && - (ch >= xfont->min_char_or_byte2) && - (ch <= xfont->max_char_or_byte2)) - { - chars = xfont->per_char; - if (chars) - width = chars[ch - xfont->min_char_or_byte2].width; - else - width = xfont->min_bounds.width; - } - else - { - width = XTextWidth (xfont, &character, 1); - } - break; - case GDK_FONT_FONTSET: - fontset = (XFontSet) private->xfont; - width = XmbTextEscapement (fontset, &character, 1) ; - break; - default: - width = 0; - } - return width; -} - -gint -gdk_string_measure (GdkFont *font, - const gchar *string) -{ - g_return_val_if_fail (font != NULL, -1); - g_return_val_if_fail (string != NULL, -1); - - return gdk_text_measure (font, string, strlen (string)); -} - -gint -gdk_text_measure (GdkFont *font, - const gchar *text, - gint text_length) -{ - GdkFontPrivate *private; - XCharStruct overall; - XFontStruct *xfont; - XFontSet fontset; - XRectangle ink, log; - int direction; - int font_ascent; - int font_descent; - gint width; - - g_return_val_if_fail (font != NULL, -1); - g_return_val_if_fail (text != NULL, -1); - - private = (GdkFontPrivate*) font; - - switch (font->type) - { - case GDK_FONT_FONT: - xfont = (XFontStruct *) private->xfont; - if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0)) - { - XTextExtents (xfont, text, text_length, - &direction, &font_ascent, &font_descent, - &overall); - } - else - { - XTextExtents16 (xfont, (XChar2b *) text, text_length / 2, - &direction, &font_ascent, &font_descent, - &overall); - } - width = overall.rbearing; - break; - case GDK_FONT_FONTSET: - fontset = (XFontSet) private->xfont; - XmbTextExtents (fontset, text, text_length, &ink, &log); - width = log.width; - break; - default: - width = 0; - } - return width; -} - -gint -gdk_char_measure (GdkFont *font, - gchar character) -{ - g_return_val_if_fail (font != NULL, -1); - - return gdk_text_measure (font, &character, 1); -} diff --git a/gdk/x11/gdkglobals-x11.c b/gdk/x11/gdkglobals-x11.c deleted file mode 100644 index 6e34bfa883..0000000000 --- a/gdk/x11/gdkglobals-x11.c +++ /dev/null @@ -1,55 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#include <stdio.h> -#include <X11/Xlib.h> -#include "gdktypes.h" -#include "gdkprivate.h" - -guint gdk_debug_flags = 0; -gint gdk_use_xshm = TRUE; -gchar *gdk_display_name = NULL; -Display *gdk_display = NULL; -gint gdk_screen; -Window gdk_root_window; -Window gdk_leader_window; -GdkWindowPrivate gdk_root_parent; -Atom gdk_wm_delete_window; -Atom gdk_wm_take_focus; -Atom gdk_wm_protocols; -Atom gdk_wm_window_protocols[2]; -Atom gdk_selection_property; -GdkDndCursorInfo gdk_dnd_cursorinfo = {None, None, NULL, NULL, - {0,0}, {0,0}, NULL}; -GdkDndGlobals gdk_dnd = {None,None,None, - None,None,None, - None, - &gdk_dnd_cursorinfo, - NULL, - 0, - FALSE, FALSE, FALSE, - None, - {0,0}, - {0,0}, {0,0}, - {0,0,0,0}, NULL, None, 0}; -gchar *gdk_progname = NULL; -gchar *gdk_progclass = NULL; -gint gdk_error_code; -gint gdk_error_warnings = TRUE; -gint gdk_null_window_warnings = TRUE; -GList *gdk_default_filters = NULL; diff --git a/gdk/x11/gdkimage-x11.c b/gdk/x11/gdkimage-x11.c deleted file mode 100644 index c31ab4e5be..0000000000 --- a/gdk/x11/gdkimage-x11.c +++ /dev/null @@ -1,496 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#include "../config.h" - -#include <sys/types.h> - -#if defined (HAVE_IPC_H) && defined (HAVE_SHM_H) && defined (HAVE_XSHM_H) -#define USE_SHM -#endif - -#ifdef USE_SHM -#include <sys/ipc.h> -#include <sys/shm.h> -#endif /* USE_SHM */ - -#include <X11/Xlib.h> -#include <X11/Xutil.h> - -#ifdef USE_SHM -#include <X11/extensions/XShm.h> -#endif /* USE_SHM */ - -#include "gdk.h" -#include "gdkprivate.h" - - -static void gdk_image_put_normal (GdkDrawable *drawable, - GdkGC *gc, - GdkImage *image, - gint xsrc, - gint ysrc, - gint xdest, - gint ydest, - gint width, - gint height); -static void gdk_image_put_shared (GdkDrawable *drawable, - GdkGC *gc, - GdkImage *image, - gint xsrc, - gint ysrc, - gint xdest, - gint ydest, - gint width, - gint height); - - -static GList *image_list = NULL; - - -void -gdk_image_exit (void) -{ - GdkImage *image; - - while (image_list) - { - image = image_list->data; - gdk_image_destroy (image); - } -} - -GdkImage * -gdk_image_new_bitmap(GdkVisual *visual, gpointer data, gint w, gint h) -/* - * Desc: create a new bitmap image - */ -{ - Visual *xvisual; - GdkImage *image; - GdkImagePrivate *private; - private = g_new(GdkImagePrivate, 1); - image = (GdkImage *) private; - private->xdisplay = gdk_display; - private->image_put = gdk_image_put_normal; - image->type = GDK_IMAGE_NORMAL; - image->visual = visual; - image->width = w; - image->height = h; - image->depth = 1; - xvisual = ((GdkVisualPrivate*) visual)->xvisual; - private->ximage = XCreateImage(private->xdisplay, xvisual, 1, XYBitmap, - 0, 0, w ,h, 8, 0); - private->ximage->data = data; - private->ximage->bitmap_bit_order = MSBFirst; - private->ximage->byte_order = MSBFirst; - image->byte_order = MSBFirst; - image->mem = private->ximage->data; - image->bpl = private->ximage->bytes_per_line; - image->bpp = 1; - return(image); -} /* gdk_image_new_bitmap() */ - -static int -gdk_image_check_xshm(Display *display) -/* - * Desc: query the server for support for the MIT_SHM extension - * Return: 0 = not available - * 1 = shared XImage support available - * 2 = shared Pixmap support available also - */ -{ -#ifdef USE_SHM - int major, minor, ignore; - Bool pixmaps; - - if (XQueryExtension(display, "MIT-SHM", &ignore, &ignore, &ignore)) - { - if (XShmQueryVersion(display, &major, &minor, &pixmaps )==True) - { - return (pixmaps==True) ? 2 : 1; - } - } -#endif /* USE_SHM */ - return 0; -} - -void -gdk_image_init (void) -{ - if (gdk_use_xshm) - { - if (!gdk_image_check_xshm (gdk_display)) - { - gdk_use_xshm = False; - } - } -} - -GdkImage* -gdk_image_new (GdkImageType type, - GdkVisual *visual, - gint width, - gint height) -{ - GdkImage *image; - GdkImagePrivate *private; -#ifdef USE_SHM - XShmSegmentInfo *x_shm_info; -#endif /* USE_SHM */ - Visual *xvisual; - - switch (type) - { - case GDK_IMAGE_FASTEST: - image = gdk_image_new (GDK_IMAGE_SHARED, visual, width, height); - - if (!image) - image = gdk_image_new (GDK_IMAGE_NORMAL, visual, width, height); - break; - - default: - private = g_new (GdkImagePrivate, 1); - image = (GdkImage*) private; - - private->xdisplay = gdk_display; - private->image_put = NULL; - - image->type = type; - image->visual = visual; - image->width = width; - image->height = height; - image->depth = visual->depth; - - xvisual = ((GdkVisualPrivate*) visual)->xvisual; - - switch (type) - { - case GDK_IMAGE_SHARED: -#ifdef USE_SHM - if (gdk_use_xshm) - { - private->image_put = gdk_image_put_shared; - - private->x_shm_info = g_new (XShmSegmentInfo, 1); - x_shm_info = private->x_shm_info; - - private->ximage = XShmCreateImage (private->xdisplay, xvisual, visual->depth, - ZPixmap, NULL, x_shm_info, width, height); - if (private->ximage == NULL) - { - g_warning ("XShmCreateImage failed"); - - g_free (image); - gdk_use_xshm = False; - return NULL; - } - - x_shm_info->shmid = shmget (IPC_PRIVATE, - private->ximage->bytes_per_line * private->ximage->height, - IPC_CREAT | 0777); - - if (x_shm_info->shmid == -1) - { - g_warning ("shmget failed!"); - - XDestroyImage (private->ximage); - g_free (private->x_shm_info); - g_free (image); - - gdk_use_xshm = False; - return NULL; - } - - x_shm_info->readOnly = False; - x_shm_info->shmaddr = shmat (x_shm_info->shmid, 0, 0); - private->ximage->data = x_shm_info->shmaddr; - - if (x_shm_info->shmaddr == (char*) -1) - { - g_warning ("shmat failed!"); - - XDestroyImage (private->ximage); - shmctl (x_shm_info->shmid, IPC_RMID, 0); - - g_free (private->x_shm_info); - g_free (image); - - return NULL; - } - -#ifdef IPC_RMID_DEFERRED_RELEASE - if (x_shm_info->shmaddr != (char*) -1) - shmctl (x_shm_info->shmid, IPC_RMID, 0); -#endif - - gdk_error_code = 0; - gdk_error_warnings = 0; - - XShmAttach (private->xdisplay, x_shm_info); - XSync (private->xdisplay, False); - - gdk_error_warnings = 1; - if (gdk_error_code == -1) - { - /* this is the common failure case so omit warning */ - XDestroyImage (private->ximage); - shmdt (x_shm_info->shmaddr); - shmctl (x_shm_info->shmid, IPC_RMID, 0); - - g_free (private->x_shm_info); - g_free (image); - - gdk_use_xshm = False; - return NULL; - } - - if (image) - image_list = g_list_prepend (image_list, image); - } - else - { - g_free (image); - return NULL; - } - break; -#else /* USE_SHM */ - g_free (image); - return NULL; -#endif /* USE_SHM */ - case GDK_IMAGE_NORMAL: - private->image_put = gdk_image_put_normal; - - private->ximage = XCreateImage (private->xdisplay, xvisual, visual->depth, - ZPixmap, 0, 0, width, height, 32, 0); - - private->ximage->data = g_new (char, private->ximage->bytes_per_line * - private->ximage->height); - break; - - case GDK_IMAGE_FASTEST: - g_assert_not_reached (); - } - - if (image) - { - image->byte_order = private->ximage->byte_order; - image->mem = private->ximage->data; - image->bpl = private->ximage->bytes_per_line; - - switch (private->ximage->bits_per_pixel) - { - case 8: - image->bpp = 1; - break; - case 16: - image->bpp = 2; - break; - case 24: - image->bpp = 3; - break; - case 32: - image->bpp = 4; - break; - } - } - } - - return image; -} - -GdkImage* -gdk_image_get (GdkWindow *window, - gint x, - gint y, - gint width, - gint height) -{ - GdkImage *image; - GdkImagePrivate *private; - GdkWindowPrivate *win_private; - - g_return_val_if_fail (window != NULL, NULL); - - win_private = (GdkWindowPrivate *) window; - if (win_private->destroyed) - return NULL; - - private = g_new (GdkImagePrivate, 1); - image = (GdkImage*) private; - - private->xdisplay = gdk_display; - private->image_put = gdk_image_put_normal; - private->ximage = XGetImage (private->xdisplay, - win_private->xwindow, - x, y, width, height, - AllPlanes, ZPixmap); - - image->type = GDK_IMAGE_NORMAL; - image->visual = gdk_window_get_visual (window); - image->width = width; - image->height = height; - image->depth = private->ximage->depth; - - image->mem = private->ximage->data; - image->bpl = private->ximage->bytes_per_line; - image->bpp = 1; - - return image; -} - -guint32 -gdk_image_get_pixel (GdkImage *image, - gint x, - gint y) -{ - guint32 pixel; - GdkImagePrivate *private; - - g_return_val_if_fail (image != NULL, 0); - - private = (GdkImagePrivate *) image; - - pixel = XGetPixel (private->ximage, x, y); - - return pixel; -} - -void -gdk_image_put_pixel (GdkImage *image, - gint x, - gint y, - guint32 pixel) -{ - GdkImagePrivate *private; - - g_return_if_fail (image != NULL); - - private = (GdkImagePrivate *) image; - - pixel = XPutPixel (private->ximage, x, y, pixel); -} - -void -gdk_image_destroy (GdkImage *image) -{ - GdkImagePrivate *private; -#ifdef USE_SHM - XShmSegmentInfo *x_shm_info; -#endif /* USE_SHM */ - - g_return_if_fail (image != NULL); - - private = (GdkImagePrivate*) image; - switch (image->type) - { - case GDK_IMAGE_NORMAL: - XDestroyImage (private->ximage); - break; - - case GDK_IMAGE_SHARED: -#ifdef USE_SHM - XShmDetach (private->xdisplay, private->x_shm_info); - XDestroyImage (private->ximage); - - x_shm_info = private->x_shm_info; - shmdt (x_shm_info->shmaddr); - shmctl (x_shm_info->shmid, IPC_RMID, 0); - - g_free (private->x_shm_info); - - image_list = g_list_remove (image_list, image); -#else /* USE_SHM */ - g_error ("trying to destroy shared memory image when gdk was compiled without shared memory support"); -#endif /* USE_SHM */ - break; - - case GDK_IMAGE_FASTEST: - g_assert_not_reached (); - } - - g_free (image); -} - -static void -gdk_image_put_normal (GdkDrawable *drawable, - GdkGC *gc, - GdkImage *image, - gint xsrc, - gint ysrc, - gint xdest, - gint ydest, - gint width, - gint height) -{ - GdkWindowPrivate *drawable_private; - GdkImagePrivate *image_private; - GdkGCPrivate *gc_private; - - g_return_if_fail (drawable != NULL); - g_return_if_fail (image != NULL); - g_return_if_fail (gc != NULL); - - drawable_private = (GdkWindowPrivate*) drawable; - if (drawable_private->destroyed) - return; - image_private = (GdkImagePrivate*) image; - gc_private = (GdkGCPrivate*) gc; - - g_return_if_fail (image->type == GDK_IMAGE_NORMAL); - - XPutImage (drawable_private->xdisplay, drawable_private->xwindow, - gc_private->xgc, image_private->ximage, - xsrc, ysrc, xdest, ydest, width, height); -} - -static void -gdk_image_put_shared (GdkDrawable *drawable, - GdkGC *gc, - GdkImage *image, - gint xsrc, - gint ysrc, - gint xdest, - gint ydest, - gint width, - gint height) -{ -#ifdef USE_SHM - GdkWindowPrivate *drawable_private; - GdkImagePrivate *image_private; - GdkGCPrivate *gc_private; - - g_return_if_fail (drawable != NULL); - g_return_if_fail (image != NULL); - g_return_if_fail (gc != NULL); - - drawable_private = (GdkWindowPrivate*) drawable; - if (drawable_private->destroyed) - return; - image_private = (GdkImagePrivate*) image; - gc_private = (GdkGCPrivate*) gc; - - g_return_if_fail (image->type == GDK_IMAGE_SHARED); - - XShmPutImage (drawable_private->xdisplay, drawable_private->xwindow, - gc_private->xgc, image_private->ximage, - xsrc, ysrc, xdest, ydest, width, height, False); -#else /* USE_SHM */ - g_error ("trying to draw shared memory image when gdk was compiled without shared memory support"); -#endif /* USE_SHM */ -} diff --git a/gdk/x11/gdkinput-gxi.c b/gdk/x11/gdkinput-gxi.c deleted file mode 100644 index d9d351c92e..0000000000 --- a/gdk/x11/gdkinput-gxi.c +++ /dev/null @@ -1,642 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef XINPUT_GXI - -/* #define DEBUG_SWITCHING */ - -#include <gxid_lib.h> - -/* Forward declarations */ -static void gdk_input_gxi_select_notify (GdkDevicePrivate *gdkdev); -static gint gdk_input_gxi_set_mode (guint32 deviceid, GdkInputMode mode); -static gint gdk_input_is_extension_device (guint32 deviceid); -static void gdk_input_gxi_configure_event (XConfigureEvent *xevent, - GdkWindow *window); -static void gdk_input_gxi_enter_event (XCrossingEvent *xevent, - GdkWindow *window); -static gint gdk_input_gxi_other_event (GdkEvent *event, - XEvent *xevent, - GdkWindow *window); -static void gdk_input_gxi_update_device (GdkDevicePrivate *gdkdev); - -static gint gdk_input_gxi_window_none_event (GdkEvent *event, XEvent *xevent); -static gint gdk_input_gxi_enable_window (GdkWindow *window, - GdkDevicePrivate *gdkdev); -static gint gdk_input_gxi_disable_window (GdkWindow *window, - GdkDevicePrivate *gdkdev); -static Window gdk_input_find_root_child(Display *dpy, Window w); -static void gdk_input_compute_obscuring(GdkInputWindow *input_window); -static gint gdk_input_is_obscured(GdkInputWindow *input_window, gdouble x, - gdouble y); -static GdkTimeCoord *gdk_input_gxi_motion_events (GdkWindow *window, - guint32 deviceid, - guint32 start, - guint32 stop, - gint *nevents_return); -static void gdk_input_gxi_get_pointer (GdkWindow *window, - guint32 deviceid, - gdouble *x, - gdouble *y, - gdouble *pressure, - gdouble *xtilt, - gdouble *ytilt, - GdkModifierType *mask); -static gint gdk_input_gxi_grab_pointer (GdkWindow * window, - gint owner_events, - GdkEventMask event_mask, - GdkWindow * confine_to, - guint32 time); -static void gdk_input_gxi_ungrab_pointer (guint32 time); - -/* Local variables */ - -static GdkDevicePrivate *gdk_input_current_device; -static GdkDevicePrivate *gdk_input_core_pointer; - -void -gdk_input_init(void) -{ - GList *tmp_list; - - gdk_input_vtable.set_mode = gdk_input_gxi_set_mode; - gdk_input_vtable.set_axes = gdk_input_common_set_axes; - gdk_input_vtable.set_key = gdk_input_common_set_key; - gdk_input_vtable.motion_events = gdk_input_gxi_motion_events; - gdk_input_vtable.get_pointer = gdk_input_gxi_get_pointer; - gdk_input_vtable.grab_pointer = gdk_input_gxi_grab_pointer; - gdk_input_vtable.ungrab_pointer = gdk_input_gxi_ungrab_pointer; - gdk_input_vtable.configure_event = gdk_input_gxi_configure_event; - gdk_input_vtable.enter_event = gdk_input_gxi_enter_event; - gdk_input_vtable.other_event = gdk_input_gxi_other_event; - gdk_input_vtable.window_none_event = gdk_input_gxi_window_none_event; - gdk_input_vtable.enable_window = gdk_input_gxi_enable_window; - gdk_input_vtable.disable_window = gdk_input_gxi_disable_window; - - gdk_input_ignore_core = FALSE; - gdk_input_core_pointer = NULL; - - if (!gdk_input_gxid_host) - { - gdk_input_gxid_host = getenv("GXID_HOST"); - } - if (!gdk_input_gxid_port) - { - char *t = getenv("GXID_PORT"); - if (t) - gdk_input_gxid_port = atoi(t); - } - - gdk_input_common_init(TRUE); - - /* find initial core pointer */ - - for (tmp_list = gdk_input_devices; tmp_list; tmp_list = tmp_list->next) - { - GdkDevicePrivate *gdkdev = (GdkDevicePrivate *)tmp_list->data; - if (gdk_input_is_extension_device(gdkdev->info.deviceid)) - { - gdk_input_gxi_select_notify (gdkdev); - } - else - { - if (gdkdev->info.deviceid != GDK_CORE_POINTER) - gdk_input_core_pointer = gdkdev; - } - } -} - -static void -gdk_input_gxi_select_notify (GdkDevicePrivate *gdkdev) -{ - XEventClass class; - - ChangeDeviceNotify (gdkdev->xdevice, gdkdev->changenotify_type, class); - - XSelectExtensionEvent (gdk_display, gdk_root_window, &class, 1); -} - -/* Set the core pointer. Device should already be enabled. */ -static gint -gdk_input_gxi_set_core_pointer(GdkDevicePrivate *gdkdev) -{ - int x_axis,y_axis; - - g_return_val_if_fail(gdkdev->xdevice,FALSE); - - x_axis = gdkdev->axis_for_use[GDK_AXIS_X]; - y_axis = gdkdev->axis_for_use[GDK_AXIS_Y]; - - g_return_val_if_fail(x_axis != -1 && y_axis != -1,FALSE); - - /* core_pointer might not be up to date so we check with the server - before change the pointer */ - - if ( !gdk_input_is_extension_device(gdkdev->info.deviceid) ) - { -#if 0 - if (gdkdev != gdk_input_core_pointer) - g_warning("core pointer inconsistency"); -#endif - return TRUE; - } - - if ( XChangePointerDevice(gdk_display,gdkdev->xdevice, x_axis, y_axis) - != Success ) - { - return FALSE; - } - else - { - gdk_input_gxi_update_device (gdk_input_core_pointer); - gdk_input_core_pointer = gdkdev; - return TRUE; - } -} - - -/* FIXME, merge with gdk_input_xfree_set_mode */ - -static gint -gdk_input_gxi_set_mode (guint32 deviceid, GdkInputMode mode) -{ - GList *tmp_list; - GdkDevicePrivate *gdkdev; - GdkInputMode old_mode; - GdkInputWindow *input_window; - - gdkdev = gdk_input_find_device(deviceid); - g_return_val_if_fail (gdkdev != NULL,FALSE); - old_mode = gdkdev->info.mode; - - if (gdkdev->info.mode == mode) - return TRUE; - - gdkdev->info.mode = mode; - - if (old_mode != GDK_MODE_DISABLED) - { - for (tmp_list = gdk_input_windows; tmp_list; tmp_list = tmp_list->next) - { - input_window = (GdkInputWindow *)tmp_list->data; - if (input_window->mode != GDK_EXTENSION_EVENTS_CURSOR) - gdk_input_disable_window (input_window->window, gdkdev); - } - } - - if (mode != GDK_MODE_DISABLED) - { - for (tmp_list = gdk_input_windows; tmp_list; tmp_list = tmp_list->next) - { - input_window = (GdkInputWindow *)tmp_list->data; - if (input_window->mode != GDK_EXTENSION_EVENTS_CURSOR) - if (!gdk_input_enable_window(input_window->window, gdkdev)) - { - gdk_input_set_mode(deviceid, old_mode); - return FALSE; - } - } - } - - return TRUE; - -} - -gint -gdk_input_is_extension_device (guint32 deviceid) -{ - XDeviceInfo *devices; - int num_devices, loop; - - if (deviceid == GDK_CORE_POINTER) - return FALSE; - - devices = XListInputDevices(gdk_display, &num_devices); - for(loop=0; loop<num_devices; loop++) - { - if ((devices[loop].id == deviceid) && (devices[loop].use == IsXExtensionDevice)) - { - XFreeDeviceList(devices); - return TRUE; - } - } - - XFreeDeviceList(devices); - return FALSE; -} - -static void -gdk_input_gxi_configure_event (XConfigureEvent *xevent, GdkWindow *window) -{ - GdkInputWindow *input_window; - gint root_x, root_y; - - input_window = gdk_input_window_find(window); - g_return_if_fail (input_window != NULL); - - gdk_input_get_root_relative_geometry(gdk_display,GDK_WINDOW_XWINDOW(window), - &root_x, &root_y, NULL, NULL); - input_window->root_x = root_x; - input_window->root_y = root_y; - gdk_input_compute_obscuring(input_window); -} - -static void -gdk_input_gxi_enter_event (XCrossingEvent *xevent, GdkWindow *window) -{ - GdkInputWindow *input_window; - - input_window = gdk_input_window_find(window); - g_return_if_fail (input_window != NULL); - - gdk_input_compute_obscuring(input_window); -} - -static gint -gdk_input_gxi_other_event (GdkEvent *event, - XEvent *xevent, - GdkWindow *window) -{ - GdkInputWindow *input_window; - - GdkDevicePrivate *gdkdev; - gint return_val; - - input_window = gdk_input_window_find(window); - g_return_val_if_fail (window != NULL, -1); - - /* This is a sort of a hack, as there isn't any XDeviceAnyEvent - - but it's potentially faster than scanning through the types of - every device. If we were deceived, then it won't match any of - the types for the device anyways */ - gdkdev = gdk_input_find_device(((XDeviceButtonEvent *)xevent)->deviceid); - - if (!gdkdev) { - return -1; /* we don't handle it - not an XInput event */ - } - - if (gdkdev->info.mode == GDK_MODE_DISABLED || - input_window->mode == GDK_EXTENSION_EVENTS_CURSOR) - return FALSE; - - if (gdkdev != gdk_input_current_device && - xevent->type != gdkdev->changenotify_type) - { - gdk_input_current_device = gdkdev; - } - - return_val = gdk_input_common_other_event (event, xevent, - input_window, gdkdev); - - if (return_val > 0 && event->type == GDK_MOTION_NOTIFY && - (!gdkdev->button_state) && (!input_window->grabbed) && - ((event->motion.x < 0) || (event->motion.y < 0) || - (event->motion.x > ((GdkWindowPrivate *)window)->width) || - (event->motion.y > ((GdkWindowPrivate *)window)->height) || - gdk_input_is_obscured(input_window,event->motion.x,event->motion.y))) - { -#ifdef DEBUG_SWITCHING - g_print("gdkinput: Setting core pointer to %d on motion at (%f,%f)\n", - gdkdev->info.deviceid,event->motion.x,event->motion.y); - g_print(" window geometry is: %dx%d\n", - ((GdkWindowPrivate *)window)->width, - ((GdkWindowPrivate *)window)->height); -#endif - gdk_input_gxi_set_core_pointer(gdkdev); - return FALSE; - } - else - return return_val; - -} - -static void -gdk_input_gxi_update_device (GdkDevicePrivate *gdkdev) -{ - GList *t; - - if (gdk_input_is_extension_device (gdkdev->info.deviceid)) - { - if (!gdkdev->xdevice) - { - gdkdev->xdevice = XOpenDevice(gdk_display, gdkdev->info.deviceid); - gdk_input_gxi_select_notify (gdkdev); - gdkdev->needs_update = 1; - } - if (gdkdev->needs_update && gdkdev->xdevice) - { - for (t = gdk_input_windows; t; t = t->next) - gdk_input_common_select_events (((GdkInputWindow *)t->data)->window, - gdkdev); - gdkdev->needs_update = 0; - } - } -} - -static gint -gdk_input_gxi_window_none_event (GdkEvent *event, XEvent *xevent) -{ - GdkDevicePrivate *gdkdev = - gdk_input_find_device(((XDeviceButtonEvent *)xevent)->deviceid); - - if (!gdkdev) { - return -1; /* we don't handle it - not an XInput event */ - } - - if (xevent->type == gdkdev->changenotify_type) - { - if (gdk_input_core_pointer != gdkdev) - { -#ifdef DEBUG_SWITCHING - g_print("ChangeNotify from %d to %d:\n", - gdk_input_core_pointer->info.deviceid, - gdkdev->info.deviceid); -#endif - gdk_input_gxi_update_device (gdk_input_core_pointer); - gdk_input_core_pointer = gdkdev; - } - } - - return FALSE; -} - -static gint -gdk_input_gxi_enable_window (GdkWindow *window, GdkDevicePrivate *gdkdev) -{ - GdkInputWindow *input_window; - - input_window = gdk_input_window_find (window); - g_return_val_if_fail (input_window != NULL, FALSE); - - if (!gdkdev->claimed) - { - if (gxid_claim_device(gdk_input_gxid_host, gdk_input_gxid_port, - gdkdev->info.deviceid, - GDK_WINDOW_XWINDOW(window), FALSE) != - GXID_RETURN_OK) - { - g_warning("Could not get device (is gxid running?)\n"); - return FALSE; - } - gdkdev->claimed = TRUE; - } - - if (gdkdev->xdevice && gdkdev != gdk_input_core_pointer) - gdk_input_common_select_events(window, gdkdev); - else - gdkdev->needs_update = TRUE; - - return TRUE; -} - -static gint -gdk_input_gxi_disable_window(GdkWindow *window, GdkDevicePrivate *gdkdev) -{ - GdkInputWindow *input_window; - - input_window = gdk_input_window_find (window); - g_return_val_if_fail (input_window != NULL, FALSE); - - if (gdkdev->claimed) - { - gxid_release_device(gdk_input_gxid_host, gdk_input_gxid_port, - gdkdev->info.deviceid, - GDK_WINDOW_XWINDOW(window)); - - gdkdev->claimed = FALSE; - } - - if (gdkdev->xdevice && gdkdev != gdk_input_core_pointer) - gdk_input_common_select_events(window, gdkdev); - else - gdkdev->needs_update = TRUE; - - return TRUE; -} - -static gint -gdk_input_is_obscured(GdkInputWindow *input_window, gdouble x, gdouble y) -{ - int i; - for (i=0;i<input_window->num_obscuring;i++) - { - GdkRectangle *rect = &input_window->obscuring[i]; - if ((x >= rect->x) && - (y >= rect->y) && - (x < rect->x + rect->width) && - (y < rect->y + rect->height)) - return TRUE; - } - return FALSE; -} - -/* If this routine needs fixing, the corresponding routine - in gxid.c will need it too. */ - -static Window -gdk_input_find_root_child(Display *dpy, Window w) -{ - Window root,parent; - Window *children; - int nchildren; - - parent = w; - do - { - w = parent; - XQueryTree(dpy,w,&root,&parent,&children,&nchildren); - if (children) XFree(children); - } - while (parent != root); - - return w; -} - -void -gdk_input_compute_obscuring(GdkInputWindow *input_window) -{ - int i; - int x,y,width,height; - int xc,yc,widthc,heightc,border_widthc,depthc; - - Window root,parent; - Window *children; - int nchildren; - - Window w = GDK_WINDOW_XWINDOW(input_window->window); - Window root_child = gdk_input_find_root_child(gdk_display,w); - gdk_input_get_root_relative_geometry(gdk_display,w,&x,&y,&width,&height); - - input_window->root_x = x; - input_window->root_y = y; - - XQueryTree(gdk_display,GDK_ROOT_WINDOW(), - &root,&parent,&children,&nchildren); - - - if (input_window->obscuring) - g_free(input_window->obscuring); - input_window->obscuring = 0; - input_window->num_obscuring = 0; - - for (i=0;i<nchildren;i++) - if (children[i] == root_child) - break; - - if (i>=nchildren-1) - { - if (nchildren) - XFree(children); - return; - } - - input_window->obscuring = g_new(GdkRectangle,(nchildren-i-1)); - - for (i=i+1;i<nchildren;i++) - { - int xmin, xmax, ymin, ymax; - XGetGeometry(gdk_display,children[i],&root,&xc,&yc,&widthc,&heightc, - &border_widthc, &depthc); - xmin = xc>x ? xc : x; - xmax = (xc+widthc)<(x+width) ? xc+widthc : x+width; - ymin = yc>y ? yc : y; - ymax = (yc+heightc)<(y+height) ? yc+heightc : y+height; - if ((xmin < xmax) && (ymin < ymax)) - { - XWindowAttributes attributes; - XGetWindowAttributes(gdk_display,children[i],&attributes); - if (attributes.map_state == IsViewable) - { - GdkRectangle *rect = &input_window->obscuring[input_window->num_obscuring]; - - /* we store the whole window, not just the obscuring part */ - rect->x = xc - x; - rect->y = yc - y; - rect->width = widthc; - rect->height = heightc; - input_window->num_obscuring++; - } - } - } - - if (nchildren) - XFree(children); -} - -static void -gdk_input_gxi_get_pointer (GdkWindow *window, - guint32 deviceid, - gdouble *x, - gdouble *y, - gdouble *pressure, - gdouble *xtilt, - gdouble *ytilt, - GdkModifierType *mask) -{ - GdkDevicePrivate *gdkdev; - - gdkdev = gdk_input_find_device (deviceid); - g_return_if_fail (gdkdev != NULL); - - if (gdkdev == gdk_input_core_pointer) - gdk_input_common_get_pointer (window, GDK_CORE_POINTER, x, y, - pressure, xtilt, ytilt, mask); - else - gdk_input_common_get_pointer (window, deviceid, x, y, - pressure, xtilt, ytilt, mask); -} - -static GdkTimeCoord * -gdk_input_gxi_motion_events (GdkWindow *window, - guint32 deviceid, - guint32 start, - guint32 stop, - gint *nevents_return) -{ - GdkDevicePrivate *gdkdev; - - gdkdev = gdk_input_find_device (deviceid); - g_return_val_if_fail (gdkdev != NULL, NULL); - - - if (gdkdev == gdk_input_core_pointer) - return gdk_input_motion_events (window, GDK_CORE_POINTER, start, stop, - nevents_return); - else - return gdk_input_common_motion_events (window, deviceid, start, stop, - nevents_return); - -} - -static gint -gdk_input_gxi_grab_pointer (GdkWindow * window, - gint owner_events, - GdkEventMask event_mask, - GdkWindow * confine_to, - guint32 time) -{ - GList *tmp_list; - GdkInputWindow *input_window; - GdkDevicePrivate *gdkdev; - - tmp_list = gdk_input_windows; - while (tmp_list) - { - input_window = (GdkInputWindow *)tmp_list->data; - - if (input_window->window == window) - input_window->grabbed = TRUE; - else if (input_window->grabbed) - input_window->grabbed = FALSE; - - tmp_list = tmp_list->next; - } - - tmp_list = gdk_input_devices; - while (tmp_list) - { - gdkdev = (GdkDevicePrivate *)tmp_list->data; - if (gdkdev->info.deviceid != GDK_CORE_POINTER && - gdkdev->xdevice && - (gdkdev->button_state != 0)) - gdkdev->button_state = 0; - - tmp_list = tmp_list->next; - } - - return Success; -} - -static void -gdk_input_gxi_ungrab_pointer (guint32 time) -{ - GdkInputWindow *input_window; - GList *tmp_list; - - tmp_list = gdk_input_windows; - while (tmp_list) - { - input_window = (GdkInputWindow *)tmp_list->data; - if (input_window->grabbed) - input_window->grabbed = FALSE; - tmp_list = tmp_list->next; - } -} - -#endif /* XINPUT_GXI */ diff --git a/gdk/x11/gdkinput-none.c b/gdk/x11/gdkinput-none.c deleted file mode 100644 index aa0cc0b0bc..0000000000 --- a/gdk/x11/gdkinput-none.c +++ /dev/null @@ -1,74 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef XINPUT_NONE - -static void gdk_input_none_get_pointer (GdkWindow *window, - guint32 deviceid, - gdouble *x, - gdouble *y, - gdouble *pressure, - gdouble *xtilt, - gdouble *ytilt, - GdkModifierType *mask); - -void -gdk_input_init (void) -{ - gdk_input_vtable.set_mode = NULL; - gdk_input_vtable.set_axes = NULL; - gdk_input_vtable.set_key = NULL; - gdk_input_vtable.motion_events = NULL; - gdk_input_vtable.get_pointer = gdk_input_none_get_pointer; - gdk_input_vtable.grab_pointer = NULL; - gdk_input_vtable.ungrab_pointer = NULL; - gdk_input_vtable.configure_event = NULL; - gdk_input_vtable.enter_event = NULL; - gdk_input_vtable.other_event = NULL; - gdk_input_vtable.window_none_event = NULL; - gdk_input_vtable.enable_window = NULL; - gdk_input_vtable.disable_window = NULL; - - gdk_input_devices = g_list_append (NULL, &gdk_input_core_info); - - gdk_input_ignore_core = FALSE; -} - -static void -gdk_input_none_get_pointer (GdkWindow *window, - guint32 deviceid, - gdouble *x, - gdouble *y, - gdouble *pressure, - gdouble *xtilt, - gdouble *ytilt, - GdkModifierType *mask) -{ - gint x_int, y_int; - - gdk_window_get_pointer (window, &x_int, &y_int, mask); - - if (x) *x = x_int; - if (y) *y = y_int; - if (pressure) *pressure = 0.5; - if (xtilt) *xtilt = 0; - if (ytilt) *ytilt = 0; -} - -#endif /* XINPUT_NONE */ diff --git a/gdk/x11/gdkinput-x11.c b/gdk/x11/gdkinput-x11.c deleted file mode 100644 index c4e21f4f1c..0000000000 --- a/gdk/x11/gdkinput-x11.c +++ /dev/null @@ -1,883 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#if defined(XINPUT_GXI) || defined(XINPUT_XFREE) - -/* Forward declarations */ -static void gdk_input_get_root_relative_geometry (Display *dpy, Window w, - int *x_ret, int *y_ret, - int *width_ret, - int *height_ret); -static GdkDevicePrivate *gdk_input_device_new(XDeviceInfo *device, - gint include_core); -static void gdk_input_common_find_events(GdkWindow *window, - GdkDevicePrivate *gdkdev, - gint mask, - XEventClass *classes, - int *num_classes); -static void gdk_input_common_select_events(GdkWindow *window, - GdkDevicePrivate *gdkdev); -static void gdk_input_translate_coordinates(GdkDevicePrivate *gdkdev, - GdkInputWindow *input_window, - gint *axis_data, - gdouble *x, gdouble *y, - gdouble *pressure, - gdouble *xtilt, gdouble *ytilt); -static guint gdk_input_translate_state(guint state, guint device_state); -static gint gdk_input_common_init(gint include_core); -static gint gdk_input_common_other_event (GdkEvent *event, - XEvent *xevent, - GdkInputWindow *input_window, - GdkDevicePrivate *gdkdev); -static void gdk_input_common_set_axes (guint32 deviceid, GdkAxisUse *axes); -static GdkTimeCoord * gdk_input_common_motion_events (GdkWindow *window, - guint32 deviceid, - guint32 start, - guint32 stop, - gint *nevents_return); -static void gdk_input_common_get_pointer (GdkWindow *window, - guint32 deviceid, - gdouble *x, - gdouble *y, - gdouble *pressure, - gdouble *xtilt, - gdouble *ytilt, - GdkModifierType *mask); - -#define GDK_MAX_DEVICE_CLASSES 13 - -/* Global variables */ - -static gint gdk_input_root_width; -static gint gdk_input_root_height; - -static void -gdk_input_get_root_relative_geometry(Display *dpy, Window w, int *x_ret, int *y_ret, - int *width_ret, int *height_ret) -{ - Window root,parent; - Window *children; - guint nchildren; - gint x,y; - guint width, height; - gint xc,yc; - guint widthc,heightc,border_widthc,depthc; - - XQueryTree(dpy,w,&root,&parent,&children,&nchildren); - if (children) XFree(children); - XGetGeometry(dpy,w,&root,&x,&y,&width,&height,&border_widthc, - &depthc); - x += border_widthc; - y += border_widthc; - - while (root != parent) - { - w = parent; - XQueryTree(dpy,w,&root,&parent,&children,&nchildren); - if (children) XFree(children); - XGetGeometry(dpy,w,&root,&xc,&yc,&widthc,&heightc, - &border_widthc,&depthc); - x += xc + border_widthc; - y += yc + border_widthc; - } - - if (x_ret) - *x_ret = x; - if (y_ret) - *y_ret = y; - if (width_ret) - *width_ret = width; - if (height_ret) - *height_ret = height; -} - -static GdkDevicePrivate * -gdk_input_device_new(XDeviceInfo *device, gint include_core) -{ - GdkDevicePrivate *gdkdev; - gchar *tmp_name, *p; - XAnyClassPtr class; - gint i,j; - - gdkdev = g_new(GdkDevicePrivate,1); - - gdkdev->info.deviceid = device->id; - if (device->name[0]) { - gdkdev->info.name = g_new(char, strlen(device->name)+1); - strcpy(gdkdev->info.name,device->name); - } else { - /* XFree86 3.2 gives an empty name to the default core devices, - (fixed in 3.2A) */ - gdkdev->info.name = g_strdup("pointer"); - strcpy(gdkdev->info.name,"pointer"); - gdkdev->info.source = GDK_SOURCE_MOUSE; - } - - gdkdev->info.mode = GDK_MODE_DISABLED; - - /* Try to figure out what kind of device this is by its name - - could invite a very, very, long list... Lowercase name - for comparison purposes */ - - tmp_name = g_strdup(gdkdev->info.name); - for (p = tmp_name; *p; p++) - { - if (*p >= 'A' && *p <= 'Z') - *p += 'a' - 'A'; - } - - if (!strcmp (tmp_name, "pointer")) - gdkdev->info.source = GDK_SOURCE_MOUSE; - else if (!strcmp (tmp_name, "wacom") || - !strcmp (tmp_name, "pen")) - gdkdev->info.source = GDK_SOURCE_PEN; - else if (!strcmp (tmp_name, "eraser")) - gdkdev->info.source = GDK_SOURCE_ERASER; - else if (!strcmp (tmp_name, "cursor")) - gdkdev->info.source = GDK_SOURCE_CURSOR; - else - gdkdev->info.source = GDK_SOURCE_PEN; - - g_free(tmp_name); - - gdkdev->xdevice = NULL; - - /* step through the classes */ - - gdkdev->info.num_axes = 0; - gdkdev->info.num_keys = 0; - gdkdev->info.keys = NULL; - gdkdev->axes = 0; - gdkdev->info.has_cursor = 0; - gdkdev->needs_update = FALSE; - gdkdev->claimed = FALSE; - gdkdev->button_state = 0; - - class = device->inputclassinfo; - for (i=0;i<device->num_classes;i++) - { - switch (class->class) { - case ButtonClass: - { - break; - } - case KeyClass: - { - XKeyInfo *xki = (XKeyInfo *)class; - /* Hack to catch XFree86 3.3.1 bug. Other devices better - * not have exactly 25 keys... - */ - if ((xki->min_keycode == 8) && (xki->max_keycode == 32)) - { - gdkdev->info.num_keys = 32; - gdkdev->min_keycode = 1; - } - else - { - gdkdev->info.num_keys = xki->max_keycode - xki->min_keycode + 1; - gdkdev->min_keycode = xki->min_keycode; - } - gdkdev->info.keys = g_new (GdkDeviceKey, gdkdev->info.num_keys); - - for (j=0; j<gdkdev->info.num_keys; j++) - { - gdkdev->info.keys[j].keyval = 0; - gdkdev->info.keys[j].modifiers = 0; - } - - break; - } - case ValuatorClass: - { - XValuatorInfo *xvi = (XValuatorInfo *)class; - gdkdev->info.num_axes = xvi->num_axes; - gdkdev->axes = g_new(GdkAxisInfo, xvi->num_axes); - gdkdev->info.axes = g_new(GdkAxisUse, xvi->num_axes); - for (j=0;j<xvi->num_axes;j++) - { - gdkdev->axes[j].resolution = - gdkdev->axes[j].xresolution = xvi->axes[j].resolution; - gdkdev->axes[j].min_value = - gdkdev->axes[j].xmin_value = xvi->axes[j].min_value; - gdkdev->axes[j].max_value = - gdkdev->axes[j].xmax_value = xvi->axes[j].max_value; - gdkdev->info.axes[j] = GDK_AXIS_IGNORE; - } - j=0; - if (j<xvi->num_axes) - gdkdev->info.axes[j++] = GDK_AXIS_X; - if (j<xvi->num_axes) - gdkdev->info.axes[j++] = GDK_AXIS_Y; - if (j<xvi->num_axes) - gdkdev->info.axes[j++] = GDK_AXIS_PRESSURE; - if (j<xvi->num_axes) - gdkdev->info.axes[j++] = GDK_AXIS_XTILT; - if (j<xvi->num_axes) - gdkdev->info.axes[j++] = GDK_AXIS_YTILT; - - /* set up reverse lookup on axis use */ - for (j=GDK_AXIS_IGNORE;j<GDK_AXIS_LAST;j++) - gdkdev->axis_for_use[j] = -1; - - for (j=0;j<xvi->num_axes;j++) - if (gdkdev->info.axes[j] != GDK_AXIS_IGNORE) - gdkdev->axis_for_use[gdkdev->info.axes[j]] = j; - - break; - } - } - class = (XAnyClassPtr)(((char *)class) + class->length); - } - /* return NULL if no axes */ - if (!gdkdev->info.num_axes || !gdkdev->axes || - (!include_core && device->use == IsXPointer)) - { - g_free(gdkdev->info.name); - if (gdkdev->axes) - g_free(gdkdev->axes); - if (gdkdev->info.keys) - g_free(gdkdev->info.keys); - g_free(gdkdev); - return NULL; - } - - if (device->use != IsXPointer) - { - int error_warn = gdk_error_warnings; - - gdk_error_warnings = 0; - gdk_error_code = 0; - gdkdev->xdevice = XOpenDevice(gdk_display, gdkdev->info.deviceid); - gdk_error_warnings = error_warn; - - /* return NULL if device is not ready */ - if (gdk_error_code) - { - g_free (gdkdev->info.name); - if (gdkdev->axes) - g_free (gdkdev->axes); - if (gdkdev->info.keys) - g_free (gdkdev->info.keys); - if (gdkdev->info.axes) - g_free (gdkdev->info.axes); - g_free (gdkdev); - - return NULL; - } - } - - gdkdev->buttonpress_type = 0; - gdkdev->buttonrelease_type = 0; - gdkdev->keypress_type = 0; - gdkdev->keyrelease_type = 0; - gdkdev->motionnotify_type = 0; - gdkdev->proximityin_type = 0; - gdkdev->proximityout_type = 0; - gdkdev->changenotify_type = 0; - - return gdkdev; -} - -static void -gdk_input_common_find_events(GdkWindow *window, - GdkDevicePrivate *gdkdev, - gint mask, - XEventClass *classes, - int *num_classes) -{ - gint i; - XEventClass class; - - i = 0; - /* We have to track press and release events in pairs to keep - track of button state correctly and implement grabbing for - the gxi support */ - if (mask & GDK_BUTTON_PRESS_MASK || mask & GDK_BUTTON_RELEASE_MASK) - { - DeviceButtonPress (gdkdev->xdevice, gdkdev->buttonpress_type, - class); - if (class != 0) - classes[i++] = class; - DeviceButtonPressGrab (gdkdev->xdevice, 0, class); - if (class != 0) - classes[i++] = class; - DeviceButtonRelease (gdkdev->xdevice, gdkdev->buttonrelease_type, - class); - if (class != 0) - classes[i++] = class; - } - if (mask & GDK_POINTER_MOTION_MASK) - { - DeviceMotionNotify (gdkdev->xdevice, gdkdev->motionnotify_type, class); - if (class != 0) - classes[i++] = class; - } - else - if (mask & (GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | - GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_MOTION_MASK | - GDK_POINTER_MOTION_HINT_MASK)) - { - /* Make sure gdkdev->motionnotify_type is set */ - DeviceMotionNotify (gdkdev->xdevice, gdkdev->motionnotify_type, class); - } - if (mask & GDK_BUTTON1_MOTION_MASK) - { - DeviceButton1Motion (gdkdev->xdevice, 0, class); - if (class != 0) - classes[i++] = class; - } - if (mask & GDK_BUTTON2_MOTION_MASK) - { - DeviceButton2Motion (gdkdev->xdevice, 0, class); - if (class != 0) - classes[i++] = class; - } - if (mask & GDK_BUTTON3_MOTION_MASK) - { - DeviceButton3Motion (gdkdev->xdevice, 0, class); - if (class != 0) - classes[i++] = class; - } - if (mask & GDK_BUTTON_MOTION_MASK) - { - DeviceButtonMotion (gdkdev->xdevice, 0, class); - if (class != 0) - classes[i++] = class; - } - if (mask & GDK_POINTER_MOTION_HINT_MASK) - { - /* We'll get into trouble if the macros change, but at least we'll - know about it, and we avoid warnings now */ - DevicePointerMotionHint (gdkdev->xdevice, 0, class); - if (class != 0) - classes[i++] = class; - } - if (mask & GDK_KEY_PRESS_MASK) - { - DeviceKeyPress (gdkdev->xdevice, gdkdev->keypress_type, class); - if (class != 0) - classes[i++] = class; - } - if (mask & GDK_KEY_RELEASE_MASK) - { - DeviceKeyRelease (gdkdev->xdevice, gdkdev->keyrelease_type, class); - if (class != 0) - classes[i++] = class; - } - if (mask & GDK_PROXIMITY_IN_MASK) - { - ProximityIn (gdkdev->xdevice, gdkdev->proximityin_type, class); - if (class != 0) - classes[i++] = class; - } - if (mask & GDK_PROXIMITY_OUT_MASK) - { - ProximityOut (gdkdev->xdevice, gdkdev->proximityout_type, class); - if (class != 0) - classes[i++] = class; - } - - *num_classes = i; -} - -static void -gdk_input_common_select_events(GdkWindow *window, - GdkDevicePrivate *gdkdev) -{ - XEventClass classes[GDK_MAX_DEVICE_CLASSES]; - gint num_classes; - - if (gdkdev->info.mode == GDK_MODE_DISABLED) - gdk_input_common_find_events(window, gdkdev, 0, classes, &num_classes); - else - gdk_input_common_find_events(window, gdkdev, - ((GdkWindowPrivate *)window)->extension_events, - classes, &num_classes); - - XSelectExtensionEvent (gdk_display, - GDK_WINDOW_XWINDOW(window), - classes, num_classes); -} - -gint -gdk_input_common_init(gint include_core) -{ - char **extensions; - XDeviceInfo *devices; - int num_devices; - int num_extensions, loop; - Display *display = gdk_display; - - /* Init global vars */ - gdk_window_get_geometry(NULL, /* use root window */ - NULL,NULL, - &gdk_input_root_width,&gdk_input_root_height, - NULL); - - /* Init XInput extension */ - - extensions = XListExtensions(display, &num_extensions); - for (loop = 0; loop < num_extensions && - (strcmp(extensions[loop], "XInputExtension") != 0); loop++); - XFreeExtensionList(extensions); - if (loop == num_extensions) /* XInput extension not found */ - return FALSE; - - gdk_input_devices = 0; - devices = XListInputDevices(display, &num_devices); - - for(loop=0; loop<num_devices; loop++) - { - GdkDevicePrivate *gdkdev = gdk_input_device_new(&devices[loop], - include_core); - if (gdkdev) - gdk_input_devices = g_list_append(gdk_input_devices, gdkdev); - } - XFreeDeviceList(devices); - - gdk_input_devices = g_list_append (gdk_input_devices, &gdk_input_core_info); - - return TRUE; -} - -static void -gdk_input_translate_coordinates (GdkDevicePrivate *gdkdev, - GdkInputWindow *input_window, - gint *axis_data, - gdouble *x, gdouble *y, gdouble *pressure, - gdouble *xtilt, gdouble *ytilt) -{ - GdkWindowPrivate *win_priv; - - int x_axis, y_axis, pressure_axis, xtilt_axis, ytilt_axis; - - double device_width, device_height; - double x_offset, y_offset, x_scale, y_scale; - - win_priv = (GdkWindowPrivate *) input_window->window; - - x_axis = gdkdev->axis_for_use[GDK_AXIS_X]; - y_axis = gdkdev->axis_for_use[GDK_AXIS_Y]; - pressure_axis = gdkdev->axis_for_use[GDK_AXIS_PRESSURE]; - xtilt_axis = gdkdev->axis_for_use[GDK_AXIS_XTILT]; - ytilt_axis = gdkdev->axis_for_use[GDK_AXIS_YTILT]; - - device_width = gdkdev->axes[x_axis].max_value - - gdkdev->axes[x_axis].min_value; - device_height = gdkdev->axes[y_axis].max_value - - gdkdev->axes[y_axis].min_value; - - if (gdkdev->info.mode == GDK_MODE_SCREEN) - { - x_scale = gdk_input_root_width / device_width; - y_scale = gdk_input_root_height / device_height; - - x_offset = - input_window->root_x; - y_offset = - input_window->root_y; - } - else /* GDK_MODE_WINDOW */ - { - double device_aspect = (device_height*gdkdev->axes[y_axis].resolution) / - (device_width*gdkdev->axes[x_axis].resolution); - - if (device_aspect * win_priv->width >= win_priv->height) - { - /* device taller than window */ - x_scale = win_priv->width / device_width; - y_scale = (x_scale * gdkdev->axes[x_axis].resolution) - / gdkdev->axes[y_axis].resolution; - - x_offset = 0; - y_offset = -(device_height * y_scale - - win_priv->height)/2; - } - else - { - /* window taller than device */ - y_scale = win_priv->height / device_height; - x_scale = (y_scale * gdkdev->axes[y_axis].resolution) - / gdkdev->axes[x_axis].resolution; - - y_offset = 0; - x_offset = - (device_width * x_scale - win_priv->width)/2; - } - } - - if (x) *x = x_offset + x_scale*axis_data[x_axis]; - if (y) *y = y_offset + y_scale*axis_data[y_axis]; - - if (pressure) - { - if (pressure_axis != -1) - *pressure = ((double)axis_data[pressure_axis] - - gdkdev->axes[pressure_axis].min_value) - / (gdkdev->axes[pressure_axis].max_value - - gdkdev->axes[pressure_axis].min_value); - else - *pressure = 0.5; - } - - if (xtilt) - { - if (xtilt_axis != -1) - { - *xtilt = 2. * (double)(axis_data[xtilt_axis] - - (gdkdev->axes[xtilt_axis].min_value + - gdkdev->axes[xtilt_axis].max_value)/2) / - (gdkdev->axes[xtilt_axis].max_value - - gdkdev->axes[xtilt_axis].min_value); - } - else *xtilt = 0; - } - - if (ytilt) - { - if (ytilt_axis != -1) - { - *ytilt = 2. * (double)(axis_data[ytilt_axis] - - (gdkdev->axes[ytilt_axis].min_value + - gdkdev->axes[ytilt_axis].max_value)/2) / - (gdkdev->axes[ytilt_axis].max_value - - gdkdev->axes[ytilt_axis].min_value); - } - else - *ytilt = 0; - } -} - -/* combine the state of the core device and the device state - into one - for now we do this in a simple-minded manner - - we just take the keyboard portion of the core device and - the button portion (all of?) the device state. - Any button remapping should go on here. */ -static guint -gdk_input_translate_state(guint state, guint device_state) -{ - return device_state | (state & 0xFF); -} - -static gint -gdk_input_common_other_event (GdkEvent *event, - XEvent *xevent, - GdkInputWindow *input_window, - GdkDevicePrivate *gdkdev) -{ - if ((xevent->type == gdkdev->buttonpress_type) || - (xevent->type == gdkdev->buttonrelease_type)) - { - XDeviceButtonEvent *xdbe = (XDeviceButtonEvent *)(xevent); - - if (xdbe->type == gdkdev->buttonpress_type) - { - event->button.type = GDK_BUTTON_PRESS; - gdkdev->button_state |= 1 << xdbe->button; - } - else - { - event->button.type = GDK_BUTTON_RELEASE; - gdkdev->button_state &= ~(1 << xdbe->button); - } - event->button.window = input_window->window; - event->button.time = xdbe->time; - event->button.source = gdkdev->info.source; - event->button.deviceid = xdbe->deviceid; - - gdk_input_translate_coordinates (gdkdev,input_window, xdbe->axis_data, - &event->button.x,&event->button.y, - &event->button.pressure, - &event->button.xtilt, - &event->button.ytilt); - event->button.state = gdk_input_translate_state(xdbe->state,xdbe->device_state); - event->button.button = xdbe->button; - - GDK_NOTE (EVENTS, - g_print ("button %s:\t\twindow: %ld device: %ld x,y: %f %f button: %d\n", - (event->button.type == GDK_BUTTON_PRESS) ? "press" : "release", - xdbe->window, - xdbe->deviceid, - event->button.x, event->button.y, - xdbe->button)); - - return TRUE; - } - - if ((xevent->type == gdkdev->keypress_type) || - (xevent->type == gdkdev->keyrelease_type)) - { - XDeviceKeyEvent *xdke = (XDeviceKeyEvent *)(xevent); - - GDK_NOTE (EVENTS, - g_print ("device key %s:\twindow: %ld device: %ld keycode: %d\n", - (event->key.type == GDK_KEY_PRESS) ? "press" : "release", - xdke->window, - xdke->deviceid, - xdke->keycode)); - - if (xdke->keycode < gdkdev->min_keycode || - xdke->keycode >= gdkdev->min_keycode + gdkdev->info.num_keys) - { - g_warning ("Invalid device key code received"); - return FALSE; - } - - event->key.keyval = gdkdev->info.keys[xdke->keycode - gdkdev->min_keycode].keyval; - - if (event->key.keyval == 0) - { - GDK_NOTE (EVENTS, - g_print ("\t\ttranslation - NONE\n")); - - return FALSE; - } - - event->key.type = (xdke->type == gdkdev->keypress_type) ? - GDK_KEY_PRESS : GDK_KEY_RELEASE; - - event->key.window = input_window->window; - event->key.time = xdke->time; - - event->key.state = gdk_input_translate_state(xdke->state, xdke->device_state) - | gdkdev->info.keys[xdke->keycode - gdkdev->min_keycode].modifiers; - - /* Add a string translation for the key event */ - if ((event->key.keyval >= 0x20) && (event->key.keyval <= 0xFF)) - { - event->key.length = 1; - event->key.string = g_new (gchar, 2); - event->key.string[0] = (gchar)event->key.keyval; - event->key.string[1] = 0; - } - else - { - event->key.length = 0; - event->key.string = g_new0 (gchar, 1); - } - - GDK_NOTE (EVENTS, - g_print ("\t\ttranslation - keyval: %d modifiers: %#x\n", - event->key.keyval, - event->key.state)); - - return TRUE; - } - - if (xevent->type == gdkdev->motionnotify_type) - { - XDeviceMotionEvent *xdme = (XDeviceMotionEvent *)(xevent); - - gdk_input_translate_coordinates(gdkdev,input_window,xdme->axis_data, - &event->motion.x,&event->motion.y, - &event->motion.pressure, - &event->motion.xtilt, - &event->motion.ytilt); - - event->motion.type = GDK_MOTION_NOTIFY; - event->motion.window = input_window->window; - event->motion.time = xdme->time; - event->motion.deviceid = xdme->deviceid; - event->motion.state = gdk_input_translate_state(xdme->state, - xdme->device_state); - event->motion.is_hint = xdme->is_hint; - event->motion.source = gdkdev->info.source; - event->motion.deviceid = xdme->deviceid; - - GDK_NOTE (EVENTS, - g_print ("motion notify:\t\twindow: %ld device: %ld x,y: %f %f state %#4x hint: %s\n", - xdme->window, - xdme->deviceid, - event->motion.x, event->motion.y, - event->motion.state, - (xdme->is_hint) ? "true" : "false")); - - - return TRUE; - } - - if (xevent->type == gdkdev->proximityin_type || - xevent->type == gdkdev->proximityout_type) - { - XProximityNotifyEvent *xpne = (XProximityNotifyEvent *)(xevent); - - event->proximity.type = (xevent->type == gdkdev->proximityin_type)? - GDK_PROXIMITY_IN:GDK_PROXIMITY_OUT; - event->proximity.window = input_window->window; - event->proximity.time = xpne->time; - event->proximity.source = gdkdev->info.source; - event->proximity.deviceid = xpne->deviceid; - - return TRUE; - } - - return -1; /* wasn't one of our event types */ -} - -static void -gdk_input_common_set_axes (guint32 deviceid, GdkAxisUse *axes) -{ - int i; - GdkDevicePrivate *gdkdev = gdk_input_find_device(deviceid); - g_return_if_fail (gdkdev != NULL); - - for (i=GDK_AXIS_IGNORE;i<GDK_AXIS_LAST;i++) - { - gdkdev->axis_for_use[i] = -1; - } - - for (i=0;i<gdkdev->info.num_axes;i++) - { - gdkdev->info.axes[i] = axes[i]; - gdkdev->axis_for_use[axes[i]] = i; - } -} - -void gdk_input_common_set_key (guint32 deviceid, - guint index, - guint keyval, - GdkModifierType modifiers) -{ - GdkDevicePrivate *gdkdev = gdk_input_find_device(deviceid); - - gdkdev = gdk_input_find_device (deviceid); - g_return_if_fail (gdkdev != NULL); - g_return_if_fail (index < gdkdev->info.num_keys); - - gdkdev->info.keys[index].keyval = keyval; - gdkdev->info.keys[index].modifiers = modifiers; -} - -static GdkTimeCoord * -gdk_input_common_motion_events (GdkWindow *window, - guint32 deviceid, - guint32 start, - guint32 stop, - gint *nevents_return) -{ - GdkTimeCoord *coords; - XDeviceTimeCoord *device_coords; - GdkInputWindow *input_window; - GdkDevicePrivate *gdkdev; - - int mode_return; - int axis_count_return; - int i; - - gdkdev = gdk_input_find_device (deviceid); - input_window = gdk_input_window_find (window); - - g_return_val_if_fail (gdkdev != NULL, NULL); - g_return_val_if_fail (gdkdev->xdevice != NULL, NULL); - g_return_val_if_fail (input_window != NULL, NULL); - - device_coords = XGetDeviceMotionEvents (gdk_display, - gdkdev->xdevice, - start, stop, - nevents_return, &mode_return, - &axis_count_return); - - if (device_coords) - { - coords = g_new (GdkTimeCoord, *nevents_return); - - for (i=0; i<*nevents_return; i++) - { - gdk_input_translate_coordinates (gdkdev, input_window, - device_coords[i].data, - &coords[i].x, &coords[i].y, - &coords[i].pressure, - &coords[i].xtilt, &coords[i].ytilt); - } - XFreeDeviceMotionEvents (device_coords); - - return coords; - } - else - return NULL; -} - -static void -gdk_input_common_get_pointer (GdkWindow *window, - guint32 deviceid, - gdouble *x, - gdouble *y, - gdouble *pressure, - gdouble *xtilt, - gdouble *ytilt, - GdkModifierType *mask) -{ - GdkDevicePrivate *gdkdev; - GdkInputWindow *input_window; - XDeviceState *state; - XInputClass *input_class; - gint x_int, y_int; - gint i; - - /* we probably need to get the mask in any case */ - - if (deviceid == GDK_CORE_POINTER) - { - gdk_window_get_pointer (window, &x_int, &y_int, mask); - if (x) *x = x_int; - if (y) *y = y_int; - if (pressure) *pressure = 0.5; - if (xtilt) *xtilt = 0; - if (ytilt) *ytilt = 0; - } - else - { - if (mask) - gdk_window_get_pointer (window, NULL, NULL, mask); - - gdkdev = gdk_input_find_device (deviceid); - input_window = gdk_input_window_find (window); - - g_return_if_fail (gdkdev != NULL); - g_return_if_fail (gdkdev->xdevice != NULL); - g_return_if_fail (input_window != NULL); - - state = XQueryDeviceState (gdk_display, gdkdev->xdevice); - input_class = state->data; - for (i=0; i<state->num_classes; i++) - { - switch (input_class->class) - { - case ValuatorClass: - gdk_input_translate_coordinates (gdkdev, input_window, - ((XValuatorState *)input_class)->valuators, - x, y, pressure, - xtilt, ytilt); - - - break; - case ButtonClass: - if (mask) - { - *mask &= 0xFF; - if (((XButtonState *)input_class)->num_buttons > 0) - *mask |= ((XButtonState *)input_class)->buttons[0] << 7; - /* GDK_BUTTON1_MASK = 1 << 8, and button n is stored - * in bit 1<<(n%8) in byte n/8. n = 1,2,... */ - } - break; - } - input_class = (XInputClass *)(((char *)input_class)+input_class->length); - } - } -} - -#endif diff --git a/gdk/x11/gdkinput-xfree.c b/gdk/x11/gdkinput-xfree.c deleted file mode 100644 index 7b69d6197f..0000000000 --- a/gdk/x11/gdkinput-xfree.c +++ /dev/null @@ -1,367 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef XINPUT_XFREE - -/* forward declarations */ - -static gint gdk_input_xfree_set_mode (guint32 deviceid, GdkInputMode mode); -static void gdk_input_check_proximity (void); -static void gdk_input_xfree_configure_event (XConfigureEvent *xevent, - GdkWindow *window); -static void gdk_input_xfree_enter_event (XCrossingEvent *xevent, - GdkWindow *window); -static gint gdk_input_xfree_other_event (GdkEvent *event, - XEvent *xevent, - GdkWindow *window); -static gint gdk_input_xfree_enable_window(GdkWindow *window, - GdkDevicePrivate *gdkdev); -static gint gdk_input_xfree_disable_window(GdkWindow *window, - GdkDevicePrivate *gdkdev); -static gint gdk_input_xfree_grab_pointer (GdkWindow * window, - gint owner_events, - GdkEventMask event_mask, - GdkWindow * confine_to, - guint32 time); -static void gdk_input_xfree_ungrab_pointer (guint32 time); - -void -gdk_input_init(void) -{ - gdk_input_vtable.set_mode = gdk_input_xfree_set_mode; - gdk_input_vtable.set_axes = gdk_input_common_set_axes; - gdk_input_vtable.set_key = gdk_input_common_set_key; - gdk_input_vtable.motion_events = gdk_input_common_motion_events; - gdk_input_vtable.get_pointer = gdk_input_common_get_pointer; - gdk_input_vtable.grab_pointer = gdk_input_xfree_grab_pointer; - gdk_input_vtable.ungrab_pointer = gdk_input_xfree_ungrab_pointer; - gdk_input_vtable.configure_event = gdk_input_xfree_configure_event; - gdk_input_vtable.enter_event = gdk_input_xfree_enter_event; - gdk_input_vtable.other_event = gdk_input_xfree_other_event; - gdk_input_vtable.window_none_event = NULL; - gdk_input_vtable.enable_window = gdk_input_xfree_enable_window; - gdk_input_vtable.disable_window = gdk_input_xfree_disable_window; - - gdk_input_ignore_core = FALSE; - gdk_input_common_init(FALSE); -} - -static gint -gdk_input_xfree_set_mode (guint32 deviceid, GdkInputMode mode) -{ - GList *tmp_list; - GdkDevicePrivate *gdkdev; - GdkInputMode old_mode; - GdkInputWindow *input_window; - - gdkdev = gdk_input_find_device(deviceid); - g_return_val_if_fail (gdkdev != NULL,FALSE); - old_mode = gdkdev->info.mode; - - if (gdkdev->info.mode == mode) - return TRUE; - - gdkdev->info.mode = mode; - - if (mode == GDK_MODE_WINDOW) - { - gdkdev->info.has_cursor = FALSE; - for (tmp_list = gdk_input_windows; tmp_list; tmp_list = tmp_list->next) - { - input_window = (GdkInputWindow *)tmp_list->data; - if (input_window->mode != GDK_EXTENSION_EVENTS_CURSOR) - gdk_input_enable_window (input_window->window, gdkdev); - else - if (old_mode != GDK_MODE_DISABLED) - gdk_input_disable_window (input_window->window, gdkdev); - } - } - else if (mode == GDK_MODE_SCREEN) - { - gdkdev->info.has_cursor = TRUE; - for (tmp_list = gdk_input_windows; tmp_list; tmp_list = tmp_list->next) - gdk_input_enable_window (((GdkInputWindow *)tmp_list->data)->window, - gdkdev); - } - else /* mode == GDK_MODE_DISABLED */ - { - for (tmp_list = gdk_input_windows; tmp_list; tmp_list = tmp_list->next) - { - input_window = (GdkInputWindow *)tmp_list->data; - if (old_mode != GDK_MODE_WINDOW || - input_window->mode != GDK_EXTENSION_EVENTS_CURSOR) - gdk_input_disable_window (input_window->window, gdkdev); - } - } - - return TRUE; - -} - -static void -gdk_input_check_proximity (void) -{ - gint new_proximity = 0; - GList *tmp_list = gdk_input_devices; - - while (tmp_list && !new_proximity) - { - GdkDevicePrivate *gdkdev = (GdkDevicePrivate *)(tmp_list->data); - - if (gdkdev->info.mode != GDK_MODE_DISABLED - && gdkdev->info.deviceid != GDK_CORE_POINTER - && gdkdev->xdevice) - { - XDeviceState *state = XQueryDeviceState(GDK_DISPLAY(), - gdkdev->xdevice); - XInputClass *xic; - int i; - - xic = state->data; - for (i=0; i<state->num_classes; i++) - { - if (xic->class == ValuatorClass) - { - XValuatorState *xvs = (XValuatorState *)xic; - if ((xvs->mode & ProximityState) == InProximity) - { - new_proximity = TRUE; - } - break; - } - xic = (XInputClass *)((char *)xic + xic->length); - } - } - tmp_list = tmp_list->next; - } - - gdk_input_ignore_core = new_proximity; -} - -static void -gdk_input_xfree_configure_event (XConfigureEvent *xevent, GdkWindow *window) -{ - GdkInputWindow *input_window; - gint root_x, root_y; - - input_window = gdk_input_window_find(window); - g_return_if_fail (window != NULL); - - gdk_input_get_root_relative_geometry(GDK_DISPLAY(),GDK_WINDOW_XWINDOW(window), - &root_x, - &root_y, NULL, NULL); - - input_window->root_x = root_x; - input_window->root_y = root_y; -} - -static void -gdk_input_xfree_enter_event (XCrossingEvent *xevent, - GdkWindow *window) -{ - GdkInputWindow *input_window; - gint root_x, root_y; - - input_window = gdk_input_window_find(window); - g_return_if_fail (window != NULL); - - gdk_input_check_proximity(); - - gdk_input_get_root_relative_geometry(GDK_DISPLAY(),GDK_WINDOW_XWINDOW(window), - &root_x, - &root_y, NULL, NULL); - - input_window->root_x = root_x; - input_window->root_y = root_y; -} - -static gint -gdk_input_xfree_other_event (GdkEvent *event, - XEvent *xevent, - GdkWindow *window) -{ - GdkInputWindow *input_window; - - GdkDevicePrivate *gdkdev; - gint return_val; - - input_window = gdk_input_window_find(window); - g_return_val_if_fail (window != NULL, -1); - - /* This is a sort of a hack, as there isn't any XDeviceAnyEvent - - but it's potentially faster than scanning through the types of - every device. If we were deceived, then it won't match any of - the types for the device anyways */ - gdkdev = gdk_input_find_device(((XDeviceButtonEvent *)xevent)->deviceid); - - if (!gdkdev) { - return -1; /* we don't handle it - not an XInput event */ - } - - /* FIXME: It would be nice if we could just get rid of the events - entirely, instead of having to ignore them */ - if (gdkdev->info.mode == GDK_MODE_DISABLED || - (gdkdev->info.mode == GDK_MODE_WINDOW - && input_window->mode == GDK_EXTENSION_EVENTS_CURSOR)) - return FALSE; - - if (!gdk_input_ignore_core) - gdk_input_check_proximity(); - - return_val = gdk_input_common_other_event (event, xevent, - input_window, gdkdev); - - if (return_val > 0 && event->type == GDK_PROXIMITY_OUT && - gdk_input_ignore_core) - gdk_input_check_proximity(); - - return return_val; -} - -static gint -gdk_input_xfree_enable_window(GdkWindow *window, GdkDevicePrivate *gdkdev) -{ - /* FIXME: watchout, gdkdev might be core pointer, never opened */ - gdk_input_common_select_events (window, gdkdev); - return TRUE; -} - -static gint -gdk_input_xfree_disable_window(GdkWindow *window, GdkDevicePrivate *gdkdev) -{ - gdk_input_common_select_events (window, gdkdev); - return TRUE; -} - -static gint -gdk_input_xfree_grab_pointer (GdkWindow * window, - gint owner_events, - GdkEventMask event_mask, - GdkWindow * confine_to, - guint32 time) -{ - GdkInputWindow *input_window, *new_window; - gboolean need_ungrab; - GdkDevicePrivate *gdkdev; - GList *tmp_list; - XEventClass event_classes[GDK_MAX_DEVICE_CLASSES]; - gint num_classes; - gint result; - - tmp_list = gdk_input_windows; - new_window = NULL; - need_ungrab = FALSE; - - while (tmp_list) - { - input_window = (GdkInputWindow *)tmp_list->data; - - if (input_window->window == window) - new_window = input_window; - else if (input_window->grabbed) - { - input_window->grabbed = FALSE; - need_ungrab = TRUE; - } - - tmp_list = tmp_list->next; - } - - if (new_window) - { - new_window->grabbed = TRUE; - - tmp_list = gdk_input_devices; - while (tmp_list) - { - gdkdev = (GdkDevicePrivate *)tmp_list->data; - if (gdkdev->info.deviceid != GDK_CORE_POINTER && - gdkdev->xdevice) - { - gdk_input_common_find_events (window, gdkdev, - event_mask, - event_classes, &num_classes); - - result = XGrabDevice( GDK_DISPLAY(), gdkdev->xdevice, - GDK_WINDOW_XWINDOW (window), - owner_events, num_classes, event_classes, - GrabModeAsync, GrabModeAsync, time); - - /* FIXME: if failure occurs on something other than the first - device, things will be badly inconsistent */ - if (result != Success) - return result; - } - tmp_list = tmp_list->next; - } - } - else - { - tmp_list = gdk_input_devices; - while (tmp_list) - { - gdkdev = (GdkDevicePrivate *)tmp_list->data; - if (gdkdev->info.deviceid != GDK_CORE_POINTER && gdkdev->xdevice && - ((gdkdev->button_state != 0) || need_ungrab)) - { - XUngrabDevice( gdk_display, gdkdev->xdevice, time); - gdkdev->button_state = 0; - } - - tmp_list = tmp_list->next; - } - } - - return Success; - -} - -static void -gdk_input_xfree_ungrab_pointer (guint32 time) -{ - GdkInputWindow *input_window; - GdkDevicePrivate *gdkdev; - GList *tmp_list; - - tmp_list = gdk_input_windows; - while (tmp_list) - { - input_window = (GdkInputWindow *)tmp_list->data; - if (input_window->grabbed) - break; - tmp_list = tmp_list->next; - } - - if (tmp_list) /* we found a grabbed window */ - { - input_window->grabbed = FALSE; - - tmp_list = gdk_input_devices; - while (tmp_list) - { - gdkdev = (GdkDevicePrivate *)tmp_list->data; - if (gdkdev->info.deviceid != GDK_CORE_POINTER && gdkdev->xdevice) - XUngrabDevice( gdk_display, gdkdev->xdevice, time); - - tmp_list = tmp_list->next; - } - } -} - -#endif /* XINPUT_XFREE */ diff --git a/gdk/x11/gdkinput.c b/gdk/x11/gdkinput.c deleted file mode 100644 index 491131ca27..0000000000 --- a/gdk/x11/gdkinput.c +++ /dev/null @@ -1,345 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#include <stdlib.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include "../config.h" -#include "gdk.h" -#include "gdkx.h" -#include "gdkprivate.h" -#include "gdkinput.h" - - -/* Forward declarations */ - -static gint gdk_input_enable_window (GdkWindow *window, - GdkDevicePrivate *gdkdev); -static gint gdk_input_disable_window (GdkWindow *window, - GdkDevicePrivate *gdkdev); -static GdkInputWindow *gdk_input_window_find (GdkWindow *window); -static GdkDevicePrivate *gdk_input_find_device (guint32 id); - - -/* Incorporate the specific routines depending on compilation options */ - -static GdkAxisUse gdk_input_core_axes[] = { GDK_AXIS_X, GDK_AXIS_Y }; - -static GdkDeviceInfo gdk_input_core_info = -{ - GDK_CORE_POINTER, - "Core Pointer", - GDK_SOURCE_MOUSE, - GDK_MODE_SCREEN, - TRUE, - 2, - gdk_input_core_axes -}; - -/* Global variables */ - -GdkInputVTable gdk_input_vtable; -/* information about network port and host for gxid daemon */ -gchar *gdk_input_gxid_host; -gint gdk_input_gxid_port; -gint gdk_input_ignore_core; - -/* Local variables */ - -static GList *gdk_input_devices; -static GList *gdk_input_windows; - -#include "gdkinputnone.h" -#include "gdkinputcommon.h" -#include "gdkinputxfree.h" -#include "gdkinputgxi.h" - -GList * -gdk_input_list_devices (void) -{ - return gdk_input_devices; -} - -void -gdk_input_set_source (guint32 deviceid, GdkInputSource source) -{ - GdkDevicePrivate *gdkdev = gdk_input_find_device(deviceid); - g_return_if_fail (gdkdev != NULL); - - gdkdev->info.source = source; -} - -gint -gdk_input_set_mode (guint32 deviceid, GdkInputMode mode) -{ - if (deviceid == GDK_CORE_POINTER) - return FALSE; - - if (gdk_input_vtable.set_mode) - return gdk_input_vtable.set_mode(deviceid,mode); - else - return FALSE; -} - -void -gdk_input_set_axes (guint32 deviceid, GdkAxisUse *axes) -{ - if (deviceid != GDK_CORE_POINTER && gdk_input_vtable.set_axes) - gdk_input_vtable.set_axes (deviceid, axes); -} - -void gdk_input_set_key (guint32 deviceid, - guint index, - guint keyval, - GdkModifierType modifiers) -{ - if (deviceid != GDK_CORE_POINTER && gdk_input_vtable.set_key) - gdk_input_vtable.set_key (deviceid, index, keyval, modifiers); -} - -GdkTimeCoord * -gdk_input_motion_events (GdkWindow *window, - guint32 deviceid, - guint32 start, - guint32 stop, - gint *nevents_return) -{ - GdkWindowPrivate *window_private; - XTimeCoord *xcoords; - GdkTimeCoord *coords; - int i; - - g_return_val_if_fail (window != NULL, NULL); - window_private = (GdkWindowPrivate *) window; - if (window_private->destroyed) - return NULL; - - if (deviceid == GDK_CORE_POINTER) - { - xcoords = XGetMotionEvents (gdk_display, - window_private->xwindow, - start, stop, nevents_return); - if (xcoords) - { - coords = g_new (GdkTimeCoord, *nevents_return); - for (i=0; i<*nevents_return; i++) - { - coords[i].time = xcoords[i].time; - coords[i].x = xcoords[i].x; - coords[i].y = xcoords[i].y; - coords[i].pressure = 0.5; - coords[i].xtilt = 0.0; - coords[i].ytilt = 0.0; - } - - XFree(xcoords); - - return coords; - } - else - return NULL; - } - else - { - if (gdk_input_vtable.motion_events) - { - return gdk_input_vtable.motion_events(window, - deviceid, start, stop, - nevents_return); - } - else - { - *nevents_return = 0; - return NULL; - } - } -} - -static gint -gdk_input_enable_window (GdkWindow *window, GdkDevicePrivate *gdkdev) -{ - if (gdk_input_vtable.enable_window) - return gdk_input_vtable.enable_window (window, gdkdev); - else - return TRUE; -} - -static gint -gdk_input_disable_window (GdkWindow *window, GdkDevicePrivate *gdkdev) -{ - if (gdk_input_vtable.disable_window) - return gdk_input_vtable.disable_window(window,gdkdev); - else - return TRUE; -} - - -static GdkInputWindow * -gdk_input_window_find(GdkWindow *window) -{ - GList *tmp_list; - - for (tmp_list=gdk_input_windows; tmp_list; tmp_list=tmp_list->next) - if (((GdkInputWindow *)(tmp_list->data))->window == window) - return (GdkInputWindow *)(tmp_list->data); - - return NULL; /* Not found */ -} - -/* FIXME: this routine currently needs to be called between creation - and the corresponding configure event (because it doesn't get the - root_relative_geometry). This should work with - gtk_window_set_extension_events, but will likely fail in other - cases */ - -void -gdk_input_set_extension_events (GdkWindow *window, gint mask, - GdkExtensionMode mode) -{ - GdkWindowPrivate *window_private; - GList *tmp_list; - GdkInputWindow *iw; - - g_return_if_fail (window != NULL); - window_private = (GdkWindowPrivate*) window; - if (window_private->destroyed) - return; - - if (mode == GDK_EXTENSION_EVENTS_NONE) - mask = 0; - - if (mask != 0) - { - iw = g_new(GdkInputWindow,1); - - iw->window = window; - iw->mode = mode; - - iw->obscuring = NULL; - iw->num_obscuring = 0; - iw->grabbed = FALSE; - - gdk_input_windows = g_list_append(gdk_input_windows,iw); - window_private->extension_events = mask; - - /* Add enter window events to the event mask */ - /* FIXME, this is not needed for XINPUT_NONE */ - gdk_window_set_events (window, - gdk_window_get_events (window) | - GDK_ENTER_NOTIFY_MASK); - } - else - { - iw = gdk_input_window_find (window); - if (iw) - { - gdk_input_windows = g_list_remove(gdk_input_windows,iw); - g_free(iw); - } - - window_private->extension_events = 0; - } - - for (tmp_list = gdk_input_devices; tmp_list; tmp_list = tmp_list->next) - { - GdkDevicePrivate *gdkdev = (GdkDevicePrivate *)(tmp_list->data); - - if (gdkdev->info.deviceid != GDK_CORE_POINTER) - { - if (mask != 0 && gdkdev->info.mode != GDK_MODE_DISABLED - && (gdkdev->info.has_cursor || mode == GDK_EXTENSION_EVENTS_ALL)) - gdk_input_enable_window(window,gdkdev); - else - gdk_input_disable_window(window,gdkdev); - } - } -} - -void -gdk_input_window_destroy (GdkWindow *window) -{ - GdkInputWindow *input_window; - - input_window = gdk_input_window_find (window); - g_return_if_fail (input_window != NULL); - - gdk_input_windows = g_list_remove (gdk_input_windows,input_window); - g_free(input_window); -} - -void -gdk_input_exit (void) -{ - GList *tmp_list; - GdkDevicePrivate *gdkdev; - - for (tmp_list = gdk_input_devices; tmp_list; tmp_list = tmp_list->next) - { - gdkdev = (GdkDevicePrivate *)(tmp_list->data); - if (gdkdev->info.deviceid != GDK_CORE_POINTER) - { - gdk_input_set_mode(gdkdev->info.deviceid,GDK_MODE_DISABLED); - - g_free(gdkdev->info.name); -#ifndef XINPUT_NONE - g_free(gdkdev->axes); -#endif - g_free(gdkdev->info.axes); - g_free(gdkdev->info.keys); - g_free(gdkdev); - } - } - - g_list_free(gdk_input_devices); - - for (tmp_list = gdk_input_windows; tmp_list; tmp_list = tmp_list->next) - { - g_free(tmp_list->data); - } - g_list_free(gdk_input_windows); -} - -static GdkDevicePrivate * -gdk_input_find_device(guint32 id) -{ - GList *tmp_list = gdk_input_devices; - GdkDevicePrivate *gdkdev; - while (tmp_list) - { - gdkdev = (GdkDevicePrivate *)(tmp_list->data); - if (gdkdev->info.deviceid == id) - return gdkdev; - tmp_list = tmp_list->next; - } - return NULL; -} - -void -gdk_input_window_get_pointer (GdkWindow *window, - guint32 deviceid, - gdouble *x, - gdouble *y, - gdouble *pressure, - gdouble *xtilt, - gdouble *ytilt, - GdkModifierType *mask) -{ - if (gdk_input_vtable.get_pointer) - gdk_input_vtable.get_pointer (window, deviceid, x, y, pressure, - xtilt, ytilt, mask); -} diff --git a/gdk/x11/gdkmain-x11.c b/gdk/x11/gdkmain-x11.c deleted file mode 100644 index 5256a2f629..0000000000 --- a/gdk/x11/gdkmain-x11.c +++ /dev/null @@ -1,4219 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#include "../config.h" - -/* If you don't want to use gdk's signal handlers define this */ -/* #define I_NEED_TO_ACTUALLY_DEBUG_MY_PROGRAMS 1 */ - -#include <X11/Xlocale.h> -#include <ctype.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <limits.h> -#ifdef USE_XIM -#include <stdarg.h> -#endif - -#ifdef HAVE_SYS_SELECT_H -#include <sys/select.h> -#endif /* HAVE_SYS_SELECT_H_ */ - -#define XLIB_ILLEGAL_ACCESS -#include <X11/Xatom.h> -#include <X11/Xlib.h> -#include <X11/Xos.h> -#include <X11/Xutil.h> -#include <X11/Xmu/WinUtil.h> -#ifdef USE_XIM -#include <X11/Xresource.h> -#endif -#include <X11/cursorfont.h> -#include "gdk.h" -#include "gdkprivate.h" -#include "gdkinput.h" -#ifdef USE_XIM -#include "gdkx.h" -#endif -#include "gdkkeysyms.h" -#include "gdki18n.h" - -#ifndef X_GETTIMEOFDAY -#define X_GETTIMEOFDAY(tv) gettimeofday (tv, NULL) -#endif /* X_GETTIMEOFDAY */ - - -#define DOUBLE_CLICK_TIME 250 -#define TRIPLE_CLICK_TIME 500 -#define DOUBLE_CLICK_DIST 5 -#define TRIPLE_CLICK_DIST 5 - - -#ifndef NO_FD_SET -# define SELECT_MASK fd_set -#else -# ifndef _AIX - typedef long fd_mask; -# endif -# if defined(_IBMR2) -# define SELECT_MASK void -# else -# define SELECT_MASK int -# endif -#endif - - -typedef struct _GdkInput GdkInput; -typedef struct _GdkPredicate GdkPredicate; - -struct _GdkInput -{ - gint tag; - gint source; - GdkInputCondition condition; - GdkInputFunction function; - gpointer data; - GdkDestroyNotify destroy; -}; - -struct _GdkPredicate -{ - GdkEventFunc func; - gpointer data; -}; - -/* - * Private function declarations - */ - -static GdkEvent *gdk_event_new (void); -static gint gdk_event_wait (void); -static gint gdk_event_apply_filters (XEvent *xevent, - GdkEvent *event, - GList *filters); -static gint gdk_event_translate (GdkEvent *event, - XEvent *xevent); -#if 0 -static Bool gdk_event_get_type (Display *display, - XEvent *xevent, - XPointer arg); -#endif -static void gdk_synthesize_click (GdkEvent *event, - gint nclicks); - -static void gdk_dnd_drag_begin (GdkWindow *initial_window); -static void gdk_dnd_drag_enter (Window dest); -static void gdk_dnd_drag_leave (Window dest); -static void gdk_dnd_drag_end (Window dest, - GdkPoint coords); -static GdkAtom gdk_dnd_check_types (GdkWindow *window, - XEvent *xevent); -#ifdef DEBUG_DND -static void gdk_print_atom (GdkAtom anatom); -#endif - -/* - * old junk from offix, we might use it though so leave it - */ -Window gdk_get_client_window (Display *dpy, - Window win); -#ifdef WE_HAVE_MOTIF_DROPS_DONE -static GdkWindow * gdk_drop_get_real_window (GdkWindow *w, - guint16 *x, - guint16 *y); -#endif -static void gdk_exit_func (void); -static int gdk_x_error (Display *display, - XErrorEvent *error); -static int gdk_x_io_error (Display *display); -static RETSIGTYPE gdk_signal (int signum); - - -#ifdef USE_XIM -static guint gdk_im_va_count (va_list list); -static XVaNestedList gdk_im_va_to_nested (va_list list, - guint count); - -static GdkIM gdk_im_get (void); -static gint gdk_im_open (XrmDatabase db, - gchar* res_name, - gchar* rec_class); -static void gdk_im_close (void); -static void gdk_ic_cleanup (void); - -#endif /* USE_XIM */ - -/* Private variable declarations - */ -static int initialized = 0; /* 1 if the library is initialized, - * 0 otherwise. - */ -static int connection_number = 0; /* The file descriptor number of our - * connection to the X server. This - * is used so that we may determine - * when events are pending by using - * the "select" system call. - */ - - -static struct timeval start; /* The time at which the library was - * last initialized. - */ -static struct timeval timer; /* Timeout interval to use in the call - * to "select". This is used in - * conjunction with "timerp" to create - * a maximum time to wait for an event - * to arrive. - */ -static struct timeval *timerp; /* The actual timer passed to "select" - * This may be NULL, in which case - * "select" will block until an event - * arrives. - */ -static guint32 timer_val; /* The timeout length as specified by - * the user in milliseconds. - */ -static GList *inputs; /* A list of the input file descriptors - * that we care about. Each list node - * contains a GdkInput struct that describes - * when we are interested in the specified - * file descriptor. That is, when it is - * available for read, write or has an - * exception pending. - */ -static guint32 button_click_time[2]; /* The last 2 button click times. Used - * to determine if the latest button click - * is part of a double or triple click. - */ -static GdkWindow *button_window[2]; /* The last 2 windows to receive button presses. - * Also used to determine if the latest button - * click is part of a double or triple click. - */ -static guint button_number[2]; /* The last 2 buttons to be pressed. - */ -static GdkWindowPrivate *xgrab_window = NULL; /* Window that currently holds the - * x pointer grab - */ - -#ifdef USE_XIM -static gint xim_using; /* using XIM Protocol if TRUE */ -static GdkIM xim_im; /* global IM */ -static XIMStyles* xim_styles; /* im supports these styles */ -static XIMStyle xim_best_allowed_style; -static GdkICPrivate *xim_ic; /* currently using IC */ -static GdkWindow* xim_window; /* currently using Widow */ -static GList* xim_ic_list; - -#endif - -static GList *putback_events = NULL; - -static gulong base_id; -static gint autorepeat; - -#ifdef G_ENABLE_DEBUG -static GDebugKey gdk_debug_keys[] = { - {"events", GDK_DEBUG_EVENTS}, - {"misc", GDK_DEBUG_MISC}, - {"dnd", GDK_DEBUG_DND}, - {"color-context", GDK_DEBUG_COLOR_CONTEXT}, - {"xim", GDK_DEBUG_XIM} -}; - -static const int gdk_ndebug_keys = sizeof(gdk_debug_keys)/sizeof(GDebugKey); - -#endif /* G_ENABLE_DEBUG */ - -/* - *-------------------------------------------------------------- - * gdk_init - * - * Initialize the library for use. - * - * Arguments: - * "argc" is the number of arguments. - * "argv" is an array of strings. - * - * Results: - * "argc" and "argv" are modified to reflect any arguments - * which were not handled. (Such arguments should either - * be handled by the application or dismissed). - * - * Side effects: - * The library is initialized. - * - *-------------------------------------------------------------- - */ - -void -gdk_init (int *argc, - char ***argv) -{ - XKeyboardState keyboard_state; - gint synchronize; - gint i, j, k; - XClassHint *class_hint; - gint argc_orig = *argc; - gchar **argv_orig; - - argv_orig = g_malloc ((argc_orig + 1) * sizeof (char*)); - for (i = 0; i < argc_orig; i++) - argv_orig[i] = g_strdup ((*argv)[i]); - argv_orig[argc_orig] = NULL; - - X_GETTIMEOFDAY (&start); - -#ifndef I_NEED_TO_ACTUALLY_DEBUG_MY_PROGRAMS - signal (SIGHUP, gdk_signal); - signal (SIGINT, gdk_signal); - signal (SIGQUIT, gdk_signal); - signal (SIGBUS, gdk_signal); - signal (SIGSEGV, gdk_signal); - signal (SIGPIPE, gdk_signal); - signal (SIGTERM, gdk_signal); -#endif - - gdk_display_name = NULL; - - XSetErrorHandler (gdk_x_error); - XSetIOErrorHandler (gdk_x_io_error); - - synchronize = FALSE; - -#ifdef G_ENABLE_DEBUG - { - gchar *debug_string = getenv("GDK_DEBUG"); - if (debug_string != NULL) - gdk_debug_flags = g_parse_debug_string (debug_string, - gdk_debug_keys, - gdk_ndebug_keys); - } -#endif /* G_ENABLE_DEBUG */ - - if (argc && argv) - { - if (*argc > 0) - { - gchar *d; - - d = strrchr((*argv)[0],'/'); - if (d != NULL) - gdk_progname = g_strdup (d + 1); - else - gdk_progname = g_strdup ((*argv)[0]); - GDK_NOTE (MISC, - g_print ("Gdk: progname: \"%s\"\n", gdk_progname)); - } - - for (i = 1; i < *argc;) - { -#ifdef G_ENABLE_DEBUG - if ((strcmp ("--gdk-debug", (*argv)[i]) == 0) || - (strncmp ("--gdk-debug=", (*argv)[i], 12) == 0)) - { - gchar *equal_pos = strchr ((*argv)[i], '='); - - if (equal_pos != NULL) - { - gdk_debug_flags |= g_parse_debug_string (equal_pos+1, - gdk_debug_keys, - gdk_ndebug_keys); - } - else if ((i + 1) < *argc && (*argv)[i + 1]) - { - gdk_debug_flags |= g_parse_debug_string ((*argv)[i+1], - gdk_debug_keys, - gdk_ndebug_keys); - (*argv)[i] = NULL; - i += 1; - } - (*argv)[i] = NULL; - } - else if ((strcmp ("--gdk-no-debug", (*argv)[i]) == 0) || - (strncmp ("--gdk-no-debug=", (*argv)[i], 15) == 0)) - { - gchar *equal_pos = strchr ((*argv)[i], '='); - - if (equal_pos != NULL) - { - gdk_debug_flags &= ~g_parse_debug_string (equal_pos+1, - gdk_debug_keys, - gdk_ndebug_keys); - } - else if ((i + 1) < *argc && (*argv)[i + 1]) - { - gdk_debug_flags &= ~g_parse_debug_string ((*argv)[i+1], - gdk_debug_keys, - gdk_ndebug_keys); - (*argv)[i] = NULL; - i += 1; - } - (*argv)[i] = NULL; - } - else -#endif /* G_ENABLE_DEBUG */ - if (strcmp ("--display", (*argv)[i]) == 0) - { - (*argv)[i] = NULL; - - if ((i + 1) < *argc && (*argv)[i + 1]) - { - gdk_display_name = g_strdup ((*argv)[i + 1]); - (*argv)[i + 1] = NULL; - i += 1; - } - } - else if (strcmp ("--sync", (*argv)[i]) == 0) - { - (*argv)[i] = NULL; - synchronize = TRUE; - } - else if (strcmp ("--no-xshm", (*argv)[i]) == 0) - { - (*argv)[i] = NULL; - gdk_use_xshm = FALSE; - } - else if (strcmp ("--name", (*argv)[i]) == 0) - { - if ((i + 1) < *argc && (*argv)[i + 1]) - { - (*argv)[i++] = NULL; - gdk_progname = (*argv)[i]; - (*argv)[i] = NULL; - } - } - else if (strcmp ("--class", (*argv)[i]) == 0) - { - if ((i + 1) < *argc && (*argv)[i + 1]) - { - (*argv)[i++] = NULL; - gdk_progclass = (*argv)[i]; - (*argv)[i] = NULL; - } - } -#ifdef XINPUT_GXI - else if (strcmp ("--gxid_host", (*argv)[i]) == 0) - { - if ((i + 1) < *argc && (*argv)[i + 1]) - { - (*argv)[i++] = NULL; - gdk_input_gxid_host = ((*argv)[i]); - (*argv)[i] = NULL; - } - } - else if (strcmp ("--gxid_port", (*argv)[i]) == 0) - { - if ((i + 1) < *argc && (*argv)[i + 1]) - { - (*argv)[i++] = NULL; - gdk_input_gxid_port = atoi ((*argv)[i]); - (*argv)[i] = NULL; - } - } -#endif -#ifdef USE_XIM - else if (strcmp ("--xim-preedit", (*argv)[i]) == 0) - { - if ((i + 1) < *argc && (*argv)[i + 1]) - { - (*argv)[i++] = NULL; - if (strcmp ("none", (*argv)[i]) == 0) - gdk_im_set_best_style (GdkIMPreeditNone); - else if (strcmp ("nothing", (*argv)[i]) == 0) - gdk_im_set_best_style (GdkIMPreeditNothing); - else if (strcmp ("area", (*argv)[i]) == 0) - gdk_im_set_best_style (GdkIMPreeditArea); - else if (strcmp ("position", (*argv)[i]) == 0) - gdk_im_set_best_style (GdkIMPreeditPosition); - else if (strcmp ("callbacks", (*argv)[i]) == 0) - gdk_im_set_best_style (GdkIMPreeditCallbacks); - } - } - else if (strcmp ("--xim-status", (*argv)[i]) == 0) - { - if ((i + 1) < *argc && (*argv)[i + 1]) - { - (*argv)[i++] = NULL; - if (strcmp ("none", (*argv)[i]) == 0) - gdk_im_set_best_style (GdkIMStatusNone); - else if (strcmp ("nothing", (*argv)[i]) == 0) - gdk_im_set_best_style (GdkIMStatusNothing); - else if (strcmp ("area", (*argv)[i]) == 0) - gdk_im_set_best_style (GdkIMStatusArea); - else if (strcmp ("callbacks", (*argv)[i]) == 0) - gdk_im_set_best_style (GdkIMStatusCallbacks); - } - } -#endif - - i += 1; - } - - for (i = 1; i < *argc; i++) - { - for (k = i; k < *argc; k++) - if ((*argv)[k] != NULL) - break; - - if (k > i) - { - k -= i; - for (j = i + k; j < *argc; j++) - (*argv)[j-k] = (*argv)[j]; - *argc -= k; - } - } - } - else - { - gdk_progname = "<unknown>"; - } - - gdk_display = XOpenDisplay (gdk_display_name); - if (!gdk_display) - { - g_warning ("cannot open display: %s", XDisplayName (gdk_display_name)); - exit(1); - } - - /* This is really crappy. We have to look into the display structure - * to find the base resource id. This is only needed for recording - * and playback of events. - */ - /* base_id = RESOURCE_BASE; */ - base_id = 0; - GDK_NOTE (EVENTS, g_print ("base id: %lu\n", base_id)); - - connection_number = ConnectionNumber (gdk_display); - GDK_NOTE (MISC, - g_print ("Gdk: connection number: %d\n", connection_number)); - - if (synchronize) - XSynchronize (gdk_display, True); - - gdk_screen = DefaultScreen (gdk_display); - gdk_root_window = RootWindow (gdk_display, gdk_screen); - - gdk_leader_window = XCreateSimpleWindow(gdk_display, gdk_root_window, - 10, 10, 10, 10, 0, 0 , 0); - class_hint = XAllocClassHint(); - class_hint->res_name = gdk_progname; - if (gdk_progclass == NULL) - { - gdk_progclass = g_strdup (gdk_progname); - gdk_progclass[0] = toupper (gdk_progclass[0]); - } - class_hint->res_class = gdk_progclass; - XSetClassHint(gdk_display, gdk_leader_window, class_hint); - XSetCommand(gdk_display, gdk_leader_window, argv_orig, argc_orig); - XFree (class_hint); - - for (i = 0; i < argc_orig; i++) - g_free(argv_orig[i]); - g_free(argv_orig); - - gdk_wm_delete_window = XInternAtom (gdk_display, "WM_DELETE_WINDOW", True); - gdk_wm_take_focus = XInternAtom (gdk_display, "WM_TAKE_FOCUS", True); - gdk_wm_protocols = XInternAtom (gdk_display, "WM_PROTOCOLS", True); - gdk_wm_window_protocols[0] = gdk_wm_delete_window; - gdk_wm_window_protocols[1] = gdk_wm_take_focus; - gdk_selection_property = XInternAtom (gdk_display, "GDK_SELECTION", False); - - gdk_dnd.gdk_XdeEnter = gdk_atom_intern("_XDE_ENTER", FALSE); - gdk_dnd.gdk_XdeLeave = gdk_atom_intern("_XDE_LEAVE", FALSE); - gdk_dnd.gdk_XdeRequest = gdk_atom_intern("_XDE_REQUEST", FALSE); - gdk_dnd.gdk_XdeDataAvailable = gdk_atom_intern("_XDE_DATA_AVAILABLE", FALSE); - gdk_dnd.gdk_XdeTypelist = gdk_atom_intern("_XDE_TYPELIST", FALSE); - gdk_dnd.c->gdk_cursor_dragdefault = XCreateFontCursor(gdk_display, XC_bogosity); - gdk_dnd.c->gdk_cursor_dragok = XCreateFontCursor(gdk_display, XC_heart); - - XGetKeyboardControl (gdk_display, &keyboard_state); - autorepeat = keyboard_state.global_auto_repeat; - - timer.tv_sec = 0; - timer.tv_usec = 0; - timerp = NULL; - - button_click_time[0] = 0; - button_click_time[1] = 0; - button_window[0] = NULL; - button_window[1] = NULL; - button_number[0] = -1; - button_number[1] = -1; - - if (ATEXIT (gdk_exit_func)) - g_warning ("unable to register exit function"); - - gdk_visual_init (); - gdk_window_init (); - gdk_image_init (); - gdk_input_init (); - -#ifdef USE_XIM - /* initialize XIM Protocol variables */ - xim_using = FALSE; - xim_im = NULL; - xim_styles = NULL; - if (!(xim_best_allowed_style & GdkIMPreeditMask)) - gdk_im_set_best_style (GdkIMPreeditCallbacks); - if (!(xim_best_allowed_style & GdkIMStatusMask)) - gdk_im_set_best_style (GdkIMStatusCallbacks); - xim_ic = NULL; - xim_window = (GdkWindow*)NULL; - - gdk_im_open (NULL, NULL, NULL); -#endif - - initialized = 1; -} - -/* - *-------------------------------------------------------------- - * gdk_exit - * - * Restores the library to an un-itialized state and exits - * the program using the "exit" system call. - * - * Arguments: - * "errorcode" is the error value to pass to "exit". - * - * Results: - * Allocated structures are freed and the program exits - * cleanly. - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -void -gdk_exit (int errorcode) -{ - /* de-initialisation is done by the gdk_exit_funct(), - no need to do this here (Alex J.) */ - exit (errorcode); -} - -/* - *-------------------------------------------------------------- - * gdk_set_locale - * - * Arguments: - * - * Results: - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -gchar* -gdk_set_locale (void) -{ - if (!setlocale (LC_ALL,"")) - g_print ("locale not supported by C library\n"); - - if (!XSupportsLocale ()) - { - g_print ("locale not supported by Xlib, locale set to C\n"); - setlocale (LC_ALL, "C"); - } - - if (!XSetLocaleModifiers ("")) - { - g_print ("can not set locale modifiers\n"); - } - - return setlocale (LC_ALL,NULL); -} - -/* - *-------------------------------------------------------------- - * gdk_events_pending - * - * Returns the number of events pending on the queue. - * These events have already been read from the server - * connection. - * - * Arguments: - * - * Results: - * Returns the number of events on XLib's event queue. - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -gint -gdk_events_pending (void) -{ - gint result; - GList *tmp_list; - - result = XPending (gdk_display); - - tmp_list = putback_events; - while (tmp_list) - { - result++; - tmp_list = tmp_list->next; - } - - return result; -} - -/* - *-------------------------------------------------------------- - * gdk_event_get_graphics_expose - * - * Waits for a GraphicsExpose or NoExpose event - * - * Arguments: - * - * Results: - * For GraphicsExpose events, returns a pointer to the event - * converted into a GdkEvent Otherwise, returns NULL. - * - * Side effects: - * - *-------------------------------------------------------------- */ - -static Bool -graphics_expose_predicate (Display *display, - XEvent *xevent, - XPointer arg) -{ - GdkWindowPrivate *private = (GdkWindowPrivate *)arg; - - g_return_val_if_fail (private != NULL, False); - - if ((xevent->xany.window == private->xwindow) && - ((xevent->xany.type == GraphicsExpose) || - (xevent->xany.type == NoExpose))) - return True; - else - return False; -} - -GdkEvent * -gdk_event_get_graphics_expose (GdkWindow *window) -{ - XEvent xevent; - GdkEvent *event; - - g_return_val_if_fail (window != NULL, NULL); - - XIfEvent (gdk_display, &xevent, graphics_expose_predicate, (XPointer)window); - - if (xevent.xany.type == GraphicsExpose) - { - event = gdk_event_new (); - - if (gdk_event_translate (event, &xevent)) - return event; - else - gdk_event_free (event); - } - - return NULL; -} - -/* - *-------------------------------------------------------------- - * gdk_event_get - * - * Gets the next event. - * - * Arguments: - * - * Results: - * If an event was received that we care about, returns - * a pointer to that event, to be freed with gdk_event_free. - * Otherwise, returns NULL. This function will also return - * before an event is received if the timeout interval - * runs out. - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -GdkEvent * -gdk_event_get (void) -{ - GdkEvent *event; - GList *temp_list; - XEvent xevent; - -#if 0 - if (pred) - { - temp_list = putback_events; - while (temp_list) - { - temp_event = temp_list->data; - - if ((* pred) (temp_event, data)) - { - if (event) - *event = *temp_event; - putback_events = g_list_remove_link (putback_events, temp_list); - g_list_free (temp_list); - return TRUE; - } - - temp_list = temp_list->next; - } - - event_pred.func = pred; - event_pred.data = data; - - if (XCheckIfEvent (gdk_display, &xevent, gdk_event_get_type, (XPointer) & event_pred)) - if (event) - return gdk_event_translate (event, &xevent); - } - else -#endif - if (putback_events) - { - event = putback_events->data; - - temp_list = putback_events; - putback_events = g_list_remove_link (putback_events, temp_list); - g_list_free_1 (temp_list); - - return event; - } - - /* Wait for an event to occur or the timeout to elapse. - * If an event occurs "gdk_event_wait" will return TRUE. - * If the timeout elapses "gdk_event_wait" will return - * FALSE. - */ - if (gdk_event_wait ()) - { - /* If we get here we can rest assurred that an event - * has occurred. Read it. - */ -#ifdef USE_XIM - gint filter_status; - if (xim_using && xim_window) - do - { /* don't dispatch events used by IM */ - XNextEvent (gdk_display, &xevent); - filter_status = XFilterEvent (&xevent, - GDK_WINDOW_XWINDOW (xim_window)); - } while (filter_status == True); - else - XNextEvent (gdk_display, &xevent); -#else - XNextEvent (gdk_display, &xevent); -#endif - - event = gdk_event_new (); - - event->any.type = GDK_NOTHING; - event->any.window = NULL; - event->any.send_event = FALSE; - event->any.send_event = xevent.xany.send_event; - - if (gdk_event_translate (event, &xevent)) - return event; - else - gdk_event_free (event); - } - - return NULL; -} - -void -gdk_event_put (GdkEvent *event) -{ - GdkEvent *new_event; - - g_return_if_fail (event != NULL); - - new_event = gdk_event_copy (event); - - putback_events = g_list_prepend (putback_events, new_event); -} - -/* - *-------------------------------------------------------------- - * gdk_event_copy - * - * Copy a event structure into new storage. - * - * Arguments: - * "event" is the event struct to copy. - * - * Results: - * A new event structure. Free it with gdk_event_free. - * - * Side effects: - * The reference count of the window in the event is increased. - * - *-------------------------------------------------------------- - */ - -static GMemChunk *event_chunk; - -static GdkEvent* -gdk_event_new (void) -{ - GdkEvent *new_event; - - if (event_chunk == NULL) - event_chunk = g_mem_chunk_new ("events", - sizeof (GdkEvent), - 4096, - G_ALLOC_AND_FREE); - - new_event = g_chunk_new (GdkEvent, event_chunk); - - return new_event; -} - -GdkEvent* -gdk_event_copy (GdkEvent *event) -{ - GdkEvent *new_event; - - g_return_val_if_fail (event != NULL, NULL); - - new_event = gdk_event_new (); - - *new_event = *event; - gdk_window_ref (new_event->any.window); - - switch (event->any.type) - { - case GDK_KEY_PRESS: - case GDK_KEY_RELEASE: - new_event->key.string = g_strdup (event->key.string); - break; - - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: - if (event->crossing.subwindow != NULL) - gdk_window_ref (event->crossing.subwindow); - break; - - case GDK_DROP_DATA_AVAIL: - new_event->dropdataavailable.data_type = g_strdup (event->dropdataavailable.data_type); - new_event->dropdataavailable.data = g_malloc (event->dropdataavailable.data_numbytes); - memcpy (new_event->dropdataavailable.data, - event->dropdataavailable.data, - event->dropdataavailable.data_numbytes); - break; - - default: - break; - } - - return new_event; -} - -/* - *-------------------------------------------------------------- - * gdk_event_free - * - * Free a event structure obtained from gdk_event_copy. Do not use - * with other event structures. - * - * Arguments: - * "event" is the event struct to free. - * - * Results: - * - * Side effects: - * The reference count of the window in the event is decreased and - * might be freed, too. - * - *-------------------------------------------------------------- */ - -void -gdk_event_free (GdkEvent *event) -{ - g_assert (event_chunk != NULL); - g_return_if_fail (event != NULL); - - if (event->any.window) - gdk_window_unref (event->any.window); - - switch (event->any.type) - { - case GDK_KEY_PRESS: - case GDK_KEY_RELEASE: - g_free (event->key.string); - break; - - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: - if (event->crossing.subwindow != NULL) - gdk_window_unref (event->crossing.subwindow); - break; - - case GDK_DROP_DATA_AVAIL: - g_free (event->dropdataavailable.data_type); - g_free (event->dropdataavailable.data); - break; - - case GDK_DRAG_REQUEST: - g_free (event->dragrequest.data_type); - break; - - default: - break; - } - - g_mem_chunk_free (event_chunk, event); -} - -/* - *-------------------------------------------------------------- - * gdk_set_show_events - * - * Turns on/off the showing of events. - * - * Arguments: - * "show_events" is a boolean describing whether or - * not to show the events gdk receives. - * - * Results: - * - * Side effects: - * When "show_events" is TRUE, calls to "gdk_event_get" - * will output debugging informatin regarding the event - * received to stdout. - * - *-------------------------------------------------------------- - */ - -void -gdk_set_show_events (int show_events) -{ - if (show_events) - gdk_debug_flags |= GDK_DEBUG_EVENTS; - else - gdk_debug_flags &= ~GDK_DEBUG_EVENTS; -} - -void -gdk_set_use_xshm (gint use_xshm) -{ - gdk_use_xshm = use_xshm; -} - -gint -gdk_get_show_events (void) -{ - return gdk_debug_flags & GDK_DEBUG_EVENTS; -} - -gint -gdk_get_use_xshm (void) -{ - return gdk_use_xshm; -} - -/* - *-------------------------------------------------------------- - * gdk_time_get - * - * Get the number of milliseconds since the library was - * initialized. - * - * Arguments: - * - * Results: - * The time since the library was initialized is returned. - * This time value is accurate to milliseconds even though - * a more accurate time down to the microsecond could be - * returned. - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -guint32 -gdk_time_get (void) -{ - struct timeval end; - struct timeval elapsed; - guint32 milliseconds; - - X_GETTIMEOFDAY (&end); - - if (start.tv_usec > end.tv_usec) - { - end.tv_usec += 1000000; - end.tv_sec--; - } - elapsed.tv_sec = end.tv_sec - start.tv_sec; - elapsed.tv_usec = end.tv_usec - start.tv_usec; - - milliseconds = (elapsed.tv_sec * 1000) + (elapsed.tv_usec / 1000); - - return milliseconds; -} - -/* - *-------------------------------------------------------------- - * gdk_timer_get - * - * Returns the current timer. - * - * Arguments: - * - * Results: - * Returns the current timer interval. This interval is - * in units of milliseconds. - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -guint32 -gdk_timer_get (void) -{ - return timer_val; -} - -/* - *-------------------------------------------------------------- - * gdk_timer_set - * - * Sets the timer interval. - * - * Arguments: - * "milliseconds" is the new value for the timer. - * - * Results: - * - * Side effects: - * Calls to "gdk_event_get" will last for a maximum - * of time of "milliseconds". However, a value of 0 - * milliseconds will cause "gdk_event_get" to block - * indefinately until an event is received. - * - *-------------------------------------------------------------- - */ - -void -gdk_timer_set (guint32 milliseconds) -{ - timer_val = milliseconds; - timer.tv_sec = milliseconds / 1000; - timer.tv_usec = (milliseconds % 1000) * 1000; - -} - -void -gdk_timer_enable (void) -{ - timerp = &timer; -} - -void -gdk_timer_disable (void) -{ - timerp = NULL; -} - -gint -gdk_input_add_full (gint source, - GdkInputCondition condition, - GdkInputFunction function, - gpointer data, - GdkDestroyNotify destroy) -{ - static gint next_tag = 1; - GList *list; - GdkInput *input; - gint tag; - - tag = 0; - list = inputs; - - while (list) - { - input = list->data; - list = list->next; - - if ((input->source == source) && (input->condition == condition)) - { - if (input->destroy) - (input->destroy) (input->data); - input->function = function; - input->data = data; - input->destroy = destroy; - tag = input->tag; - } - } - - if (!tag) - { - input = g_new (GdkInput, 1); - input->tag = next_tag++; - input->source = source; - input->condition = condition; - input->function = function; - input->data = data; - input->destroy = destroy; - tag = input->tag; - - inputs = g_list_prepend (inputs, input); - } - - return tag; -} - -gint -gdk_input_add (gint source, - GdkInputCondition condition, - GdkInputFunction function, - gpointer data) -{ - return gdk_input_add_interp (source, condition, function, data, NULL); -} - -void -gdk_input_remove (gint tag) -{ - GList *list; - GList *temp_list; - GdkInput *input; - - list = inputs; - while (list) - { - input = list->data; - - if (input->tag == tag) - { - if (input->destroy) - (input->destroy) (input->data); - - temp_list = list; - - if (list->next) - list->next->prev = list->prev; - if (list->prev) - list->prev->next = list->next; - if (inputs == list) - inputs = list->next; - - temp_list->next = NULL; - temp_list->prev = NULL; - - g_free (temp_list->data); - g_list_free (temp_list); - break; - } - - list = list->next; - } -} - -/* - *-------------------------------------------------------------- - * gdk_pointer_grab - * - * Grabs the pointer to a specific window - * - * Arguments: - * "window" is the window which will receive the grab - * "owner_events" specifies whether events will be reported as is, - * or relative to "window" - * "event_mask" masks only interesting events - * "confine_to" limits the cursor movement to the specified window - * "cursor" changes the cursor for the duration of the grab - * "time" specifies the time - * - * Results: - * - * Side effects: - * requires a corresponding call to gdk_pointer_ungrab - * - *-------------------------------------------------------------- - */ - -gint -gdk_pointer_grab (GdkWindow * window, - gint owner_events, - GdkEventMask event_mask, - GdkWindow * confine_to, - GdkCursor * cursor, - guint32 time) -{ - /* From gdkwindow.c */ - extern int nevent_masks; - extern int event_mask_table[]; - - gint return_val; - GdkWindowPrivate *window_private; - GdkWindowPrivate *confine_to_private; - GdkCursorPrivate *cursor_private; - guint xevent_mask; - Window xwindow; - Window xconfine_to; - Cursor xcursor; - int i; - - g_return_val_if_fail (window != NULL, 0); - - window_private = (GdkWindowPrivate*) window; - confine_to_private = (GdkWindowPrivate*) confine_to; - cursor_private = (GdkCursorPrivate*) cursor; - - xwindow = window_private->xwindow; - - if (!confine_to || confine_to_private->destroyed) - xconfine_to = None; - else - xconfine_to = confine_to_private->xwindow; - - if (!cursor) - xcursor = None; - else - xcursor = cursor_private->xcursor; - - - xevent_mask = 0; - for (i = 0; i < nevent_masks; i++) - { - if (event_mask & (1 << (i + 1))) - xevent_mask |= event_mask_table[i]; - } - - if (gdk_input_vtable.grab_pointer) - return_val = gdk_input_vtable.grab_pointer (window, - owner_events, - event_mask, - confine_to, - time); - else - return_val = Success; - - if (return_val == Success) - { - if (!window_private->destroyed) - return_val = XGrabPointer (window_private->xdisplay, - xwindow, - owner_events, - xevent_mask, - GrabModeAsync, GrabModeAsync, - xconfine_to, - xcursor, - time); - else - return_val = AlreadyGrabbed; - } - - if (return_val == GrabSuccess) - xgrab_window = window_private; - - return return_val; -} - -/* - *-------------------------------------------------------------- - * gdk_pointer_ungrab - * - * Releases any pointer grab - * - * Arguments: - * - * Results: - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -void -gdk_pointer_ungrab (guint32 time) -{ - if (gdk_input_vtable.ungrab_pointer) - gdk_input_vtable.ungrab_pointer (time); - - XUngrabPointer (gdk_display, time); - xgrab_window = NULL; -} - -/* - *-------------------------------------------------------------- - * gdk_pointer_is_grabbed - * - * Tell wether there is an active x pointer grab in effect - * - * Arguments: - * - * Results: - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -gint -gdk_pointer_is_grabbed (void) -{ - return xgrab_window != NULL; -} - -/* - *-------------------------------------------------------------- - * gdk_keyboard_grab - * - * Grabs the keyboard to a specific window - * - * Arguments: - * "window" is the window which will receive the grab - * "owner_events" specifies whether events will be reported as is, - * or relative to "window" - * "time" specifies the time - * - * Results: - * - * Side effects: - * requires a corresponding call to gdk_keyboard_ungrab - * - *-------------------------------------------------------------- - */ - -gint -gdk_keyboard_grab (GdkWindow * window, - gint owner_events, - guint32 time) -{ - GdkWindowPrivate *window_private; - Window xwindow; - - g_return_val_if_fail (window != NULL, 0); - - window_private = (GdkWindowPrivate*) window; - xwindow = window_private->xwindow; - - if (!window_private->destroyed) - return XGrabKeyboard (window_private->xdisplay, - xwindow, - owner_events, - GrabModeAsync, GrabModeAsync, - time); - else - return AlreadyGrabbed; -} - -/* - *-------------------------------------------------------------- - * gdk_keyboard_ungrab - * - * Releases any keyboard grab - * - * Arguments: - * - * Results: - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -void -gdk_keyboard_ungrab (guint32 time) -{ - XUngrabKeyboard (gdk_display, time); -} - -/* - *-------------------------------------------------------------- - * gdk_screen_width - * - * Return the width of the screen. - * - * Arguments: - * - * Results: - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -gint -gdk_screen_width (void) -{ - gint return_val; - - return_val = DisplayWidth (gdk_display, gdk_screen); - - return return_val; -} - -/* - *-------------------------------------------------------------- - * gdk_screen_height - * - * Return the height of the screen. - * - * Arguments: - * - * Results: - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -gint -gdk_screen_height (void) -{ - gint return_val; - - return_val = DisplayHeight (gdk_display, gdk_screen); - - return return_val; -} - -void -gdk_key_repeat_disable (void) -{ - XAutoRepeatOff (gdk_display); -} - -void -gdk_key_repeat_restore (void) -{ - if (autorepeat) - XAutoRepeatOn (gdk_display); - else - XAutoRepeatOff (gdk_display); -} - - -/* - *-------------------------------------------------------------- - * gdk_flush - * - * Flushes the Xlib output buffer and then waits - * until all requests have been received and processed - * by the X server. The only real use for this function - * is in dealing with XShm. - * - * Arguments: - * - * Results: - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -void gdk_flush (void) -{ - XSync (gdk_display, False); -} - - -void -gdk_beep (void) -{ - XBell(gdk_display, 100); -} - - -/* - *-------------------------------------------------------------- - * gdk_event_wait - * - * Waits until an event occurs or the timer runs out. - * - * Arguments: - * - * Results: - * Returns TRUE if an event is ready to be read and FALSE - * if the timer ran out. - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -static gint -gdk_event_wait (void) -{ - GList *list; - GdkInput *input; - GdkInputCondition condition; - SELECT_MASK readfds; - SELECT_MASK writefds; - SELECT_MASK exceptfds; - int max_input; - int nfd; - - /* If there are no events pending we will wait for an event. - * The time we wait is dependant on the "timer". If no timer - * has been specified then we'll block until an event arrives. - * If a timer has been specified we'll block until an event - * arrives or the timer expires. (This is all done using the - * "select" system call). - */ - - if (XPending (gdk_display) == 0) - { - FD_ZERO (&readfds); - FD_ZERO (&writefds); - FD_ZERO (&exceptfds); - - FD_SET (connection_number, &readfds); - max_input = connection_number; - - list = inputs; - while (list) - { - input = list->data; - list = list->next; - - if (input->condition & GDK_INPUT_READ) - FD_SET (input->source, &readfds); - if (input->condition & GDK_INPUT_WRITE) - FD_SET (input->source, &writefds); - if (input->condition & GDK_INPUT_EXCEPTION) - FD_SET (input->source, &exceptfds); - - max_input = MAX (max_input, input->source); - } - - nfd = select (max_input+1, &readfds, &writefds, &exceptfds, timerp); - - timerp = NULL; - timer_val = 0; - - if (nfd > 0) - { - if (FD_ISSET (connection_number, &readfds)) - { - if (XPending (gdk_display) == 0) - { - if (nfd == 1) - { - XNoOp (gdk_display); - XFlush (gdk_display); - } - return FALSE; - } - else - return TRUE; - } - - list = inputs; - while (list) - { - input = list->data; - list = list->next; - - condition = 0; - if (FD_ISSET (input->source, &readfds)) - condition |= GDK_INPUT_READ; - if (FD_ISSET (input->source, &writefds)) - condition |= GDK_INPUT_WRITE; - if (FD_ISSET (input->source, &exceptfds)) - condition |= GDK_INPUT_EXCEPTION; - - if (condition && input->function) - (* input->function) (input->data, input->source, condition); - } - } - } - else - return TRUE; - - return FALSE; -} - -static gint -gdk_event_apply_filters (XEvent *xevent, - GdkEvent *event, - GList *filters) -{ - GdkEventFilter *filter; - GList *tmp_list; - GdkFilterReturn result; - - tmp_list = filters; - - while (tmp_list) - { - filter = (GdkEventFilter *)tmp_list->data; - - result = (*filter->function)(xevent, event, filter->data); - if (result != GDK_FILTER_CONTINUE) - return result; - - tmp_list = tmp_list->next; - } - - return GDK_FILTER_CONTINUE; -} - -static gint -gdk_event_translate (GdkEvent *event, - XEvent *xevent) -{ - - GdkWindow *window; - GdkWindowPrivate *window_private; - static XComposeStatus compose; - KeySym keysym; - int charcount; -#ifdef USE_XIM - static gchar* buf = NULL; - static gint buf_len= 0; -#else - char buf[16]; -#endif - gint return_val; - - return_val = FALSE; - - /* We need to play catch-up with the dnd motion events */ - if(gdk_dnd.drag_really && xevent->type == MotionNotify) - while (XCheckTypedEvent(xevent->xany.display,MotionNotify,xevent)); - - /* Find the GdkWindow that this event occurred in. - * All events occur in some GdkWindow (otherwise, why - * would we be receiving them). It really is an error - * to receive an event for which we cannot find the - * corresponding GdkWindow. We handle events with window=None - * specially - they are generated by XFree86's XInput under - * some circumstances. - */ - - if ((xevent->xany.window == None) && - gdk_input_vtable.window_none_event) - { - return_val = gdk_input_vtable.window_none_event (event,xevent); - - if (return_val >= 0) /* was handled */ - return return_val; - else - return_val = FALSE; - } - - window = gdk_window_lookup (xevent->xany.window); - window_private = (GdkWindowPrivate *) window; - - if (window != NULL) - gdk_window_ref (window); -#ifdef USE_XIM - else if (XFilterEvent(xevent, None)) /* for xlib XIM handling */ - return FALSE; -#endif - else if(gdk_null_window_warnings) /* Special purpose programs that - get events for other windows may - want to disable this */ - g_warning ("%#lx -> NULL\n", xevent->xany.window); - - /* Check for filters for this window */ - - { - GdkFilterReturn result; - result = gdk_event_apply_filters (xevent, event, - window_private - ?window_private->filters - :gdk_default_filters); - - if (result != GDK_FILTER_CONTINUE) - { - return (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE; - } - } - - /* We do a "manual" conversion of the XEvent to a - * GdkEvent. The structures are mostly the same so - * the conversion is fairly straightforward. We also - * optionally print debugging info regarding events - * received. - */ - /* Addendum: - * During drag & drop you get events where the pointer is - * in other windows. Need to just do finer-grained checking - */ - switch (xevent->type) - { - case KeyPress: - /* Lookup the string corresponding to the given keysym. - */ -#ifdef USE_XIM - if (buf_len == 0) - { - buf_len = 128; - buf = g_new (gchar, buf_len); - } - keysym = GDK_VoidSymbol; - - if (xim_using == TRUE && xim_ic) - { - Status status; - - /* Clear keyval. Depending on status, may not be set */ - charcount = XmbLookupString(xim_ic->xic, - &xevent->xkey, buf, buf_len-1, - &keysym, &status); - if (status == XBufferOverflow) - { /* retry */ - /* alloc adequate size of buffer */ - GDK_NOTE (XIM, - g_print("XIM: overflow (required %i)\n", charcount)); - - while (buf_len <= charcount) - buf_len *= 2; - buf = (gchar *) g_realloc (buf, buf_len); - - charcount = XmbLookupString (xim_ic->xic, - &xevent->xkey, buf, buf_len-1, - &keysym, &status); - } - if (status == XLookupNone) - { - return_val = FALSE; - break; - } - } - else - charcount = XLookupString (&xevent->xkey, buf, buf_len, - &keysym, &compose); -#else - charcount = XLookupString (&xevent->xkey, buf, 16, - &keysym, &compose); -#endif - event->key.keyval = keysym; - - if (charcount > 0 && buf[charcount-1] == '\0') - charcount --; - else - buf[charcount] = '\0'; - - /* Print debugging info. - */ -#ifdef G_ENABLE_DEBUG - if (gdk_debug_flags & GDK_DEBUG_EVENTS) - { - g_print ("key press:\twindow: %ld key: %12s %d\n", - xevent->xkey.window - base_id, - event->key.keyval ? XKeysymToString (event->key.keyval) : "(none)", - event->key.keyval); - if (charcount > 0) - g_print ("\t\tlength: %4d string: \"%s\"\n", - charcount, buf); - } -#endif /* G_ENABLE_DEBUG */ - - event->key.type = GDK_KEY_PRESS; - event->key.window = window; - event->key.time = xevent->xkey.time; - event->key.state = (GdkModifierType) xevent->xkey.state; - event->key.string = g_strdup (buf); - event->key.length = charcount; - - return_val = window_private && !window_private->destroyed; - - if (!return_val) - g_free (event->key.string); - - break; - - case KeyRelease: - /* Lookup the string corresponding to the given keysym. - */ - keysym = GDK_VoidSymbol; - charcount = XLookupString (&xevent->xkey, buf, 16, - &keysym, &compose); - event->key.keyval = keysym; - - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("key release:\t\twindow: %ld key: %12s %d\n", - xevent->xkey.window - base_id, - XKeysymToString (event->key.keyval), - event->key.keyval)); - - event->key.type = GDK_KEY_RELEASE; - event->key.window = window; - event->key.time = xevent->xkey.time; - event->key.state = (GdkModifierType) xevent->xkey.state; - event->key.length = 0; - event->key.string = NULL; - - return_val = window_private && !window_private->destroyed; - break; - - case ButtonPress: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("button press[%d]:\t\twindow: %ld x,y: %d %d button: %d\n", - window_private?window_private->dnd_drag_enabled:0, - xevent->xbutton.window - base_id, - xevent->xbutton.x, xevent->xbutton.y, - xevent->xbutton.button)); - - if (window_private && - (window_private->extension_events != 0) && - gdk_input_ignore_core) - break; - - event->button.type = GDK_BUTTON_PRESS; - event->button.window = window; - event->button.time = xevent->xbutton.time; - event->button.x = xevent->xbutton.x; - event->button.y = xevent->xbutton.y; - event->button.x_root = (gfloat)xevent->xbutton.x_root; - event->button.y_root = (gfloat)xevent->xbutton.y_root; - event->button.pressure = 0.5; - event->button.xtilt = 0; - event->button.ytilt = 0; - event->button.state = (GdkModifierType) xevent->xbutton.state; - event->button.button = xevent->xbutton.button; - event->button.source = GDK_SOURCE_MOUSE; - event->button.deviceid = GDK_CORE_POINTER; - - if ((event->button.time < (button_click_time[1] + TRIPLE_CLICK_TIME)) && - (event->button.window == button_window[1]) && - (event->button.button == button_number[1])) - { - gdk_synthesize_click (event, 3); - - button_click_time[1] = 0; - button_click_time[0] = 0; - button_window[1] = NULL; - button_window[0] = 0; - button_number[1] = -1; - button_number[0] = -1; - } - else if ((event->button.time < (button_click_time[0] + DOUBLE_CLICK_TIME)) && - (event->button.window == button_window[0]) && - (event->button.button == button_number[0])) - { - gdk_synthesize_click (event, 2); - - button_click_time[1] = button_click_time[0]; - button_click_time[0] = event->button.time; - button_window[1] = button_window[0]; - button_window[0] = event->button.window; - button_number[1] = button_number[0]; - button_number[0] = event->button.button; - } - else - { - button_click_time[1] = 0; - button_click_time[0] = event->button.time; - button_window[1] = NULL; - button_window[0] = event->button.window; - button_number[1] = -1; - button_number[0] = event->button.button; - } - if(window_private - && window_private->dnd_drag_enabled - && !gdk_dnd.drag_perhaps - && event->button.button == 1 - && !gdk_dnd.drag_really) - { - gdk_dnd.drag_perhaps = 1; - gdk_dnd.dnd_drag_start.x = xevent->xbutton.x_root; - gdk_dnd.dnd_drag_start.y = xevent->xbutton.y_root; - gdk_dnd.real_sw = window_private; - - if(gdk_dnd.drag_startwindows) - { - g_free(gdk_dnd.drag_startwindows); - gdk_dnd.drag_startwindows = NULL; - } - gdk_dnd.drag_numwindows = gdk_dnd.drag_really = 0; - gdk_dnd.dnd_grabbed = FALSE; - - { - /* Set motion mask for first DnD'd window, since it - will be the one that is actually dragged */ - XWindowAttributes dnd_winattr; - XSetWindowAttributes dnd_setwinattr; - - /* We need to get motion events while the button is down, so - we can know whether to really start dragging or not... */ - XGetWindowAttributes(gdk_display, (Window)window_private->xwindow, - &dnd_winattr); - - window_private->dnd_drag_savedeventmask = dnd_winattr.your_event_mask; - dnd_setwinattr.event_mask = - window_private->dnd_drag_eventmask = ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | - EnterWindowMask | LeaveWindowMask | ExposureMask; - XChangeWindowAttributes(gdk_display, window_private->xwindow, - CWEventMask, &dnd_setwinattr); - } - } - return_val = window_private && !window_private->destroyed; - break; - - case ButtonRelease: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("button release[%d]:\twindow: %ld x,y: %d %d button: %d\n", - window_private?window_private->dnd_drag_enabled:0, - xevent->xbutton.window - base_id, - xevent->xbutton.x, xevent->xbutton.y, - xevent->xbutton.button)); - - if (window_private && - (window_private->extension_events != 0) && - gdk_input_ignore_core) - break; - - event->button.type = GDK_BUTTON_RELEASE; - event->button.window = window; - event->button.time = xevent->xbutton.time; - event->button.x = xevent->xbutton.x; - event->button.y = xevent->xbutton.y; - event->button.x_root = (gfloat)xevent->xbutton.x_root; - event->button.y_root = (gfloat)xevent->xbutton.y_root; - event->button.pressure = 0.5; - event->button.xtilt = 0; - event->button.ytilt = 0; - event->button.state = (GdkModifierType) xevent->xbutton.state; - event->button.button = xevent->xbutton.button; - event->button.source = GDK_SOURCE_MOUSE; - event->button.deviceid = GDK_CORE_POINTER; - - gdk_dnd.last_drop_time = xevent->xbutton.time; - if(gdk_dnd.drag_perhaps) - { - { - XSetWindowAttributes attrs; - /* Reset event mask to pre-drag value, assuming event_mask - doesn't change during drag */ - attrs.event_mask = gdk_dnd.real_sw->dnd_drag_savedeventmask; - XChangeWindowAttributes(gdk_display, gdk_dnd.real_sw->xwindow, - CWEventMask, &attrs); - } - - if (gdk_dnd.dnd_grabbed) - { - gdk_dnd_display_drag_cursor(-2, - -2, - FALSE, TRUE); - XUngrabPointer(gdk_display, CurrentTime); - gdk_dnd.dnd_grabbed = FALSE; - } - - if(gdk_dnd.drag_really) - { - GdkPoint foo; - foo.x = xevent->xbutton.x_root; - foo.y = xevent->xbutton.y_root; - - if(gdk_dnd.dnd_drag_target != None) - gdk_dnd_drag_end(gdk_dnd.dnd_drag_target, foo); - gdk_dnd.drag_really = 0; - - gdk_dnd.drag_numwindows = 0; - if(gdk_dnd.drag_startwindows) - { - g_free(gdk_dnd.drag_startwindows); - gdk_dnd.drag_startwindows = NULL; - } - - gdk_dnd.real_sw = NULL; - } - - gdk_dnd.drag_perhaps = 0; - gdk_dnd.dnd_drag_start.x = gdk_dnd.dnd_drag_start.y = 0; - gdk_dnd.dnd_drag_dropzone.x = gdk_dnd.dnd_drag_dropzone.y = 0; - gdk_dnd.dnd_drag_dropzone.width = gdk_dnd.dnd_drag_dropzone.height = 0; - gdk_dnd.dnd_drag_curwin = None; - return_val = window_private?TRUE:FALSE; - } else - return_val = window_private && !window_private->destroyed; - break; - - case MotionNotify: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s d:%d r%d\n", - xevent->xmotion.window - base_id, - xevent->xmotion.x, xevent->xmotion.y, - (xevent->xmotion.is_hint) ? "true" : "false", - gdk_dnd.drag_perhaps, gdk_dnd.drag_really)); - - if (window_private && - (window_private->extension_events != 0) && - gdk_input_ignore_core) - break; - - event->motion.type = GDK_MOTION_NOTIFY; - event->motion.window = window; - event->motion.time = xevent->xmotion.time; - event->motion.x = xevent->xmotion.x; - event->motion.y = xevent->xmotion.y; - event->motion.x_root = (gfloat)xevent->xmotion.x_root; - event->motion.y_root = (gfloat)xevent->xmotion.y_root; - event->motion.pressure = 0.5; - event->motion.xtilt = 0; - event->motion.ytilt = 0; - event->motion.state = (GdkModifierType) xevent->xmotion.state; - event->motion.is_hint = xevent->xmotion.is_hint; - event->motion.source = GDK_SOURCE_MOUSE; - event->motion.deviceid = GDK_CORE_POINTER; - -#define IS_IN_ZONE(cx, cy) (cx >= gdk_dnd.dnd_drag_dropzone.x \ - && cy >= gdk_dnd.dnd_drag_dropzone.y \ - && cx < (gdk_dnd.dnd_drag_dropzone.x + gdk_dnd.dnd_drag_dropzone.width) \ - && cy < (gdk_dnd.dnd_drag_dropzone.y + gdk_dnd.dnd_drag_dropzone.height)) - - if(gdk_dnd.drag_perhaps && gdk_dnd.drag_really - /* && event->motion.is_hint */ /* HINTME */) - { - /* First, we have to find what window the motion was in... */ - /* XXX there has to be a better way to do this, perhaps with - XTranslateCoordinates or XQueryTree - I don't know how, - and this sort of works */ - static Window lastwin = None, curwin = None; -#if 0 - Window twin; -#endif - Window childwin = gdk_root_window; - int x, y, ox, oy; - - /* Interlude - display cursor for the drag ASAP */ - gdk_dnd_display_drag_cursor(xevent->xmotion.x_root, - xevent->xmotion.y_root, - gdk_dnd.dnd_drag_target?TRUE:FALSE, - FALSE); - - lastwin = curwin; - curwin = gdk_root_window; - ox = x = xevent->xmotion.x_root; - oy = y = xevent->xmotion.y_root; -#if 1 - curwin = gdk_window_xid_at_coords(xevent->xmotion.x_root, - xevent->xmotion.y_root, - gdk_dnd.c->xids,TRUE); - XTranslateCoordinates(gdk_display, gdk_root_window, curwin, - x, y, &x, &y, &childwin); -#else - while(childwin != None) - { - ox = x; oy = y; - curwin = childwin; - XTranslateCoordinates(gdk_display, curwin, curwin, - x, y, &x, &y, &childwin); - if(childwin != None) - { - XTranslateCoordinates(gdk_display, curwin, childwin, - x, y, &x, &y, &twin); - } - } -#endif - GDK_NOTE (DND, - g_print("Drag is now in window %#lx, lastwin was %#lx, ddc = %#lx\n", - curwin, lastwin, gdk_dnd.dnd_drag_curwin)); - if(curwin != gdk_dnd.dnd_drag_curwin && curwin != lastwin) - { - /* We have left one window and entered another - (do leave & enter bits) */ - if(gdk_dnd.dnd_drag_curwin != None) - gdk_dnd_drag_leave(gdk_dnd.dnd_drag_curwin); - gdk_dnd.dnd_drag_curwin = curwin; - gdk_dnd_drag_enter(gdk_dnd.dnd_drag_curwin); - gdk_dnd.dnd_drag_dropzone.x = gdk_dnd.dnd_drag_dropzone.y = 0; - gdk_dnd.dnd_drag_dropzone.width = gdk_dnd.dnd_drag_dropzone.height = 0; - gdk_dnd.dnd_drag_target = None; - GDK_NOTE (DND, - g_print("curwin = %#lx, lastwin = %#lx, dnd_drag_curwin = %#lx\n", - curwin, lastwin, gdk_dnd.dnd_drag_curwin)); - - gdk_dnd_display_drag_cursor(xevent->xmotion.x_root, - xevent->xmotion.y_root, - FALSE, TRUE); - } - else if(gdk_dnd.dnd_drag_dropzone.width > 0 - && gdk_dnd.dnd_drag_dropzone.height > 0 - && curwin == gdk_dnd.dnd_drag_curwin) - { - /* Handle all that dropzone stuff - thanks John ;-) */ - if (gdk_dnd.dnd_drag_target != None) - { - gboolean in_zone = IS_IN_ZONE(xevent->xmotion.x_root, - xevent->xmotion.y_root); - gboolean old_in_zone = IS_IN_ZONE(gdk_dnd.dnd_drag_oldpos.x, - gdk_dnd.dnd_drag_oldpos.y); - - if (!in_zone && old_in_zone) - { - /* We were in the drop zone and moved out */ - gdk_dnd.dnd_drag_target = None; - gdk_dnd_drag_leave(curwin); - gdk_dnd_display_drag_cursor(xevent->xmotion.x_root, - xevent->xmotion.y_root, - FALSE, TRUE); - } - else if (!in_zone && !old_in_zone) - { - /* We were outside drop zone but in the window - - have to send enter events */ - gdk_dnd_drag_enter(curwin); - gdk_dnd.dnd_drag_curwin = curwin; - gdk_dnd.dnd_drag_dropzone.x = gdk_dnd.dnd_drag_dropzone.y = 0; - gdk_dnd.dnd_drag_target = None; - } - } - } /* else - dnd_drag_curwin = None; */ - return_val = FALSE; - } - else - return_val = window_private && !window_private->destroyed; - break; - - case EnterNotify: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("enter notify:\t\twindow: %ld detail: %d subwin: %ld\n", - xevent->xcrossing.window - base_id, - xevent->xcrossing.detail, - xevent->xcrossing.subwindow - base_id)); - - /* Tell XInput stuff about it if appropriate */ - if (window_private && - !window_private->destroyed && - (window_private->extension_events != 0) && - gdk_input_vtable.enter_event) - gdk_input_vtable.enter_event (&xevent->xcrossing, window); - - event->crossing.type = GDK_ENTER_NOTIFY; - event->crossing.window = window; - - /* If the subwindow field of the XEvent is non-NULL, then - * lookup the corresponding GdkWindow. - */ - if (xevent->xcrossing.subwindow != None) - event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow); - else - event->crossing.subwindow = NULL; - - /* Translate the crossing detail into Gdk terms. - */ - switch (xevent->xcrossing.detail) - { - case NotifyInferior: - event->crossing.detail = GDK_NOTIFY_INFERIOR; - break; - case NotifyAncestor: - event->crossing.detail = GDK_NOTIFY_ANCESTOR; - break; - case NotifyVirtual: - event->crossing.detail = GDK_NOTIFY_VIRTUAL; - break; - case NotifyNonlinear: - event->crossing.detail = GDK_NOTIFY_NONLINEAR; - break; - case NotifyNonlinearVirtual: - event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL; - break; - default: - event->crossing.detail = GDK_NOTIFY_UNKNOWN; - break; - } - -#ifdef G_ENABLE_DEBUG - if ((gdk_debug_flags & GDK_DEBUG_DND) & gdk_dnd.drag_perhaps) - { - g_print("We may[%d] have a drag into %#lx = %#lx\n", - gdk_dnd.drag_really, - xevent->xcrossing.window, gdk_dnd.real_sw->xwindow); - } -#endif /* G_ENABLE_DEBUG */ - - if (gdk_dnd.drag_perhaps && gdk_dnd.drag_really && - (xevent->xcrossing.window == gdk_dnd.real_sw->xwindow)) - { - gdk_dnd.drag_really = 0; - - GDK_NOTE (DND, g_print("Ungrabbed\n")); - - gdk_dnd.drag_numwindows = 0; - g_free(gdk_dnd.drag_startwindows); - gdk_dnd.drag_startwindows = NULL; - /* We don't want to ungrab the pointer here, or we'll - * start getting spurious enter/leave events */ -#if 0 - XChangeActivePointerGrab (gdk_display, 0, None, CurrentTime); -#endif - } - - return_val = window_private && !window_private->destroyed; - break; - - case LeaveNotify: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("leave notify:\t\twindow: %ld detail: %d subwin: %ld\n", - xevent->xcrossing.window - base_id, - xevent->xcrossing.detail, xevent->xcrossing.subwindow - base_id)); - - event->crossing.type = GDK_LEAVE_NOTIFY; - event->crossing.window = window; - - /* If the subwindow field of the XEvent is non-NULL, then - * lookup the corresponding GdkWindow. - */ - if (xevent->xcrossing.subwindow != None) - event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow); - else - event->crossing.subwindow = NULL; - - /* Translate the crossing detail into Gdk terms. - */ - switch (xevent->xcrossing.detail) - { - case NotifyInferior: - event->crossing.detail = GDK_NOTIFY_INFERIOR; - break; - case NotifyAncestor: - event->crossing.detail = GDK_NOTIFY_ANCESTOR; - break; - case NotifyVirtual: - event->crossing.detail = GDK_NOTIFY_VIRTUAL; - break; - case NotifyNonlinear: - event->crossing.detail = GDK_NOTIFY_NONLINEAR; - break; - case NotifyNonlinearVirtual: - event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL; - break; - default: - event->crossing.detail = GDK_NOTIFY_UNKNOWN; - break; - } -#ifdef G_ENABLE_DEBUG - if ((gdk_debug_flags & GDK_DEBUG_DND) & gdk_dnd.drag_perhaps) - { - g_print("We may[%d] have a drag out of %#lx = %#lx\n", - gdk_dnd.drag_really, - xevent->xcrossing.window, gdk_dnd.real_sw->xwindow); - } -#endif /* G_ENABLE_DEBUG */ - if (gdk_dnd.drag_perhaps && !gdk_dnd.drag_really && - (xevent->xcrossing.window == gdk_dnd.real_sw->xwindow)) - { - gboolean xgpret; - gdk_dnd_drag_addwindow((GdkWindow *) gdk_dnd.real_sw); - gdk_dnd_drag_begin((GdkWindow *) gdk_dnd.real_sw); - xgpret = - XGrabPointer(gdk_display, gdk_dnd.real_sw->xwindow, False, - ButtonMotionMask | PointerMotionMask | - /* PointerMotionHintMask | */ /* HINTME */ - ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - None, CurrentTime); -#ifdef G_ENABLE_DEBUG - GDK_NOTE(DND, g_print("xgpret = %d\n", xgpret)); -#endif - gdk_dnd.dnd_grabbed = TRUE; - gdk_dnd.drag_really = 1; - gdk_dnd_display_drag_cursor(xevent->xmotion.x_root, - xevent->xmotion.y_root, - FALSE, TRUE); - } - - return_val = window_private && !window_private->destroyed; - break; - - case FocusIn: - case FocusOut: - /* We only care about focus events that indicate that _this_ - * window (not a ancestor or child) got or lost the focus - */ - switch (xevent->xfocus.detail) - { - case NotifyAncestor: - case NotifyInferior: - case NotifyNonlinear: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("focus %s:\t\twindow: %ld\n", - (xevent->xany.type == FocusIn) ? "in" : "out", - xevent->xfocus.window - base_id)); - - event->focus_change.type = GDK_FOCUS_CHANGE; - event->focus_change.window = window; - event->focus_change.in = (xevent->xany.type == FocusIn); - - return_val = window_private && !window_private->destroyed; - break; - default: - ; - } - break; - - case KeymapNotify: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("keymap notify\n")); - - /* Not currently handled */ - break; - - case Expose: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d\n", - xevent->xexpose.window - base_id, xevent->xexpose.count, - xevent->xexpose.x, xevent->xexpose.y, - xevent->xexpose.width, xevent->xexpose.height)); - - event->expose.type = GDK_EXPOSE; - event->expose.window = window; - event->expose.area.x = xevent->xexpose.x; - event->expose.area.y = xevent->xexpose.y; - event->expose.area.width = xevent->xexpose.width; - event->expose.area.height = xevent->xexpose.height; - event->expose.count = xevent->xexpose.count; - - return_val = window_private && !window_private->destroyed; - break; - - case GraphicsExpose: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("graphics expose:\tdrawable: %ld\n", - xevent->xgraphicsexpose.drawable - base_id)); - - event->expose.type = GDK_EXPOSE; - event->expose.window = window; - event->expose.area.x = xevent->xgraphicsexpose.x; - event->expose.area.y = xevent->xgraphicsexpose.y; - event->expose.area.width = xevent->xgraphicsexpose.width; - event->expose.area.height = xevent->xgraphicsexpose.height; - event->expose.count = xevent->xexpose.count; - - return_val = window_private && !window_private->destroyed; - break; - - case NoExpose: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("no expose:\t\tdrawable: %ld\n", - xevent->xnoexpose.drawable - base_id)); - - event->no_expose.type = GDK_NO_EXPOSE; - event->no_expose.window = window; - - return_val = window_private && !window_private->destroyed; - break; - - case VisibilityNotify: - /* Print debugging info. - */ -#ifdef G_ENABLE_DEBUG - if (gdk_debug_flags & GDK_DEBUG_EVENTS) - switch (xevent->xvisibility.state) - { - case VisibilityFullyObscured: - g_print ("visibility notify:\twindow: %ld none\n", - xevent->xvisibility.window - base_id); - break; - case VisibilityPartiallyObscured: - g_print ("visibility notify:\twindow: %ld partial\n", - xevent->xvisibility.window - base_id); - break; - case VisibilityUnobscured: - g_print ("visibility notify:\twindow: %ld full\n", - xevent->xvisibility.window - base_id); - break; - } -#endif /* G_ENABLE_DEBUG */ - - event->visibility.type = GDK_VISIBILITY_NOTIFY; - event->visibility.window = window; - - switch (xevent->xvisibility.state) - { - case VisibilityFullyObscured: - event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED; - break; - - case VisibilityPartiallyObscured: - event->visibility.state = GDK_VISIBILITY_PARTIAL; - break; - - case VisibilityUnobscured: - event->visibility.state = GDK_VISIBILITY_UNOBSCURED; - break; - } - - return_val = window_private && !window_private->destroyed; - break; - - case CreateNotify: - /* Not currently handled */ - break; - - case DestroyNotify: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("destroy notify:\twindow: %ld\n", - xevent->xdestroywindow.window - base_id)); - - event->any.type = GDK_DESTROY; - event->any.window = window; - - return_val = window_private && !window_private->destroyed; - - gdk_window_destroy_notify (window); - break; - - case UnmapNotify: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("unmap notify:\t\twindow: %ld\n", - xevent->xmap.window - base_id)); - - event->any.type = GDK_UNMAP; - event->any.window = window; - - if (xgrab_window == window_private) - xgrab_window = NULL; - - return_val = window_private && !window_private->destroyed; - break; - - case MapNotify: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("map notify:\t\twindow: %ld\n", - xevent->xmap.window - base_id)); - - event->any.type = GDK_MAP; - event->any.window = window; - - return_val = window_private && !window_private->destroyed; - break; - - case ReparentNotify: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("reparent notify:\twindow: %ld\n", - xevent->xreparent.window - base_id)); - - /* Not currently handled */ - break; - - case ConfigureNotify: - /* Print debugging info. - */ - while ((XPending (gdk_display) > 0) && - XCheckTypedWindowEvent(gdk_display, xevent->xany.window, - ConfigureNotify, xevent)) - { - GdkFilterReturn result; - - GDK_NOTE (EVENTS, - g_print ("configure notify discarded:\twindow: %ld\n", - xevent->xconfigure.window - base_id)); - - result = gdk_event_apply_filters (xevent, event, - window_private - ?window_private->filters - :gdk_default_filters); - - /* If the result is GDK_FILTER_REMOVE, there will be - * trouble, but anybody who filtering the Configure events - * better know what they are doing - */ - if (result != GDK_FILTER_CONTINUE) - { - return (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE; - } - - /*XSync (gdk_display, 0);*/ - } - - - GDK_NOTE (EVENTS, - g_print ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d\n", - xevent->xconfigure.window - base_id, - xevent->xconfigure.x, - xevent->xconfigure.y, - xevent->xconfigure.width, - xevent->xconfigure.height, - xevent->xconfigure.border_width, - xevent->xconfigure.above - base_id, - xevent->xconfigure.override_redirect)); - - if (window_private) - { - if (!window_private->destroyed && - (window_private->extension_events != 0) && - gdk_input_vtable.configure_event) - gdk_input_vtable.configure_event (&xevent->xconfigure, window); - - if (window_private->window_type != GDK_WINDOW_CHILD) - { - event->configure.type = GDK_CONFIGURE; - event->configure.window = window; - event->configure.width = xevent->xconfigure.width; - event->configure.height = xevent->xconfigure.height; - - if (!xevent->xconfigure.x && - !xevent->xconfigure.y && - !window_private->destroyed) - { - gint tx = 0; - gint ty = 0; - Window child_window = 0; - - if (!XTranslateCoordinates (window_private->xdisplay, - window_private->xwindow, - gdk_root_window, - 0, 0, - &tx, &ty, - &child_window)) - g_warning ("GdkWindow %ld doesn't share root windows display?", - window_private->xwindow - base_id); - event->configure.x = tx; - event->configure.y = ty; - } - else - { - event->configure.x = xevent->xconfigure.x; - event->configure.y = xevent->xconfigure.y; - } - window_private->x = event->configure.x; - window_private->y = event->configure.y; - window_private->width = xevent->xconfigure.width; - window_private->height = xevent->xconfigure.height; - if (window_private->resize_count > 1) - window_private->resize_count -= 1; - - return_val = !window_private->destroyed; - } - } - break; - - case PropertyNotify: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("property notify:\twindow: %ld\n", - xevent->xproperty.window - base_id)); - - event->property.type = GDK_PROPERTY_NOTIFY; - event->property.window = window; - event->property.atom = xevent->xproperty.atom; - event->property.time = xevent->xproperty.time; - event->property.state = xevent->xproperty.state; - - return_val = window_private && !window_private->destroyed; - break; - - case SelectionClear: - GDK_NOTE (EVENTS, - g_print ("selection clear:\twindow: %ld\n", - xevent->xproperty.window - base_id)); - - event->selection.type = GDK_SELECTION_CLEAR; - event->selection.window = window; - event->selection.selection = xevent->xselectionclear.selection; - event->selection.time = xevent->xselectionclear.time; - - return_val = window_private && !window_private->destroyed; - break; - - case SelectionRequest: - GDK_NOTE (EVENTS, - g_print ("selection request:\twindow: %ld\n", - xevent->xproperty.window - base_id)); - - event->selection.type = GDK_SELECTION_REQUEST; - event->selection.window = window; - event->selection.selection = xevent->xselectionrequest.selection; - event->selection.target = xevent->xselectionrequest.target; - event->selection.property = xevent->xselectionrequest.property; - event->selection.requestor = xevent->xselectionrequest.requestor; - event->selection.time = xevent->xselectionrequest.time; - - return_val = window_private && !window_private->destroyed; - break; - - case SelectionNotify: - GDK_NOTE (EVENTS, - g_print ("selection notify:\twindow: %ld\n", - xevent->xproperty.window - base_id)); - - - event->selection.type = GDK_SELECTION_NOTIFY; - event->selection.window = window; - event->selection.selection = xevent->xselection.selection; - event->selection.target = xevent->xselection.target; - event->selection.property = xevent->xselection.property; - event->selection.time = xevent->xselection.time; - - return_val = window_private && !window_private->destroyed; - break; - - case ColormapNotify: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("colormap notify:\twindow: %ld\n", - xevent->xcolormap.window - base_id)); - - /* Not currently handled */ - break; - - case ClientMessage: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("client message:\twindow: %ld\n", - xevent->xclient.window - base_id)); - - /* Client messages are the means of the window manager - * communicating with a program. We'll first check to - * see if this is really the window manager talking - * to us. - */ - if (xevent->xclient.message_type == gdk_wm_protocols) - { - if ((Atom) xevent->xclient.data.l[0] == gdk_wm_delete_window) - { - /* The delete window request specifies a window - * to delete. We don't actually destroy the - * window because "it is only a request". (The - * window might contain vital data that the - * program does not want destroyed). Instead - * the event is passed along to the program, - * which should then destroy the window. - */ - - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("delete window:\t\twindow: %ld\n", - xevent->xclient.window - base_id)); - - event->any.type = GDK_DELETE; - event->any.window = window; - - return_val = window_private && !window_private->destroyed; - } - else if ((Atom) xevent->xclient.data.l[0] == gdk_wm_take_focus) - { - } - } - else if (xevent->xclient.message_type == gdk_dnd.gdk_XdeEnter) - { - Atom reptype = 0; - - event->dropenter.u.allflags = xevent->xclient.data.l[1]; - - GDK_NOTE (DND, g_print ("GDK_DROP_ENTER [%d][%d]\n", - window_private->dnd_drop_enabled, event->dropenter.u.flags.sendreply)); - return_val = FALSE; - - /* Now figure out if we really want this drop... - * If someone is trying funky clipboard stuff, ignore - */ - if (window_private - && window_private->dnd_drop_enabled - && event->dropenter.u.flags.sendreply - && (reptype = gdk_dnd_check_types (window, xevent))) - { - XEvent replyev; - - replyev.xclient.type = ClientMessage; - replyev.xclient.window = xevent->xclient.data.l[0]; - replyev.xclient.format = 32; - replyev.xclient.message_type = gdk_dnd.gdk_XdeRequest; - replyev.xclient.data.l[0] = window_private->xwindow; - - event->dragrequest.u.allflags = 0; - event->dragrequest.u.flags.protocol_version = - DND_PROTOCOL_VERSION; - event->dragrequest.u.flags.willaccept = 1; - event->dragrequest.u.flags.delete_data = - (window_private->dnd_drop_destructive_op) ? 1 : 0; - - replyev.xclient.data.l[1] = event->dragrequest.u.allflags; - replyev.xclient.data.l[2] = replyev.xclient.data.l[3] = 0; - replyev.xclient.data.l[4] = reptype; - - if (!gdk_send_xevent (replyev.xclient.window, False, - NoEventMask, &replyev)) - GDK_NOTE (DND, g_print("Sending XdeRequest to %#lx failed\n", - replyev.xclient.window)); - - event->any.type = GDK_DROP_ENTER; - event->any.window = window; - event->dropenter.requestor = replyev.xclient.window; - event->dropenter.u.allflags = xevent->xclient.data.l[1]; - - GDK_NOTE (DND, g_print("We sent a GDK_DROP_ENTER on to Gtk\n")); - return_val = TRUE; - } - } - else if (xevent->xclient.message_type == gdk_dnd.gdk_XdeLeave) - { -#ifdef G_ENABLE_DEBUG - if (gdk_debug_flags & (GDK_DEBUG_EVENTS | GDK_DEBUG_DND)) - g_print ("GDK_DROP_LEAVE\n"); -#endif - - if (window_private && window_private->dnd_drop_enabled) - { - event->dropleave.type = GDK_DROP_LEAVE; - event->dropleave.window = window; - event->dropleave.requestor = xevent->xclient.data.l[0]; - event->dropleave.u.allflags = xevent->xclient.data.l[1]; - return_val = TRUE; - } - else - return_val = FALSE; - } - else if (xevent->xclient.message_type == gdk_dnd.gdk_XdeRequest) - { - /* - * make sure to only handle requests from the window the cursor is - * over - */ -#ifdef G_ENABLE_DEBUG - if (gdk_debug_flags & (GDK_DEBUG_EVENTS | GDK_DEBUG_DND)) - g_print ("GDK_DRAG_REQUEST\n"); -#endif - event->dragrequest.u.allflags = xevent->xclient.data.l[1]; - return_val = FALSE; - - if (window && gdk_dnd.drag_really && - xevent->xclient.data.l[0] == gdk_dnd.dnd_drag_curwin && - event->dragrequest.u.flags.sendreply == 0) - { - /* Got request - do we need to ask user? */ - if (!event->dragrequest.u.flags.willaccept - && event->dragrequest.u.flags.senddata) - { - /* Yes we do :) */ - event->dragrequest.type = GDK_DRAG_REQUEST; - event->dragrequest.window = window; - event->dragrequest.requestor = xevent->xclient.data.l[0]; - event->dragrequest.isdrop = 0; - event->dragrequest.drop_coords.x = - event->dragrequest.drop_coords.y = 0; - return_val = TRUE; - } - else if (event->dragrequest.u.flags.willaccept) - { - window_private->dnd_drag_destructive_op = - event->dragrequest.u.flags.delete_data; - window_private->dnd_drag_accepted = 1; - window_private->dnd_drag_data_type = - xevent->xclient.data.l[4]; - - gdk_dnd.dnd_drag_target = gdk_dnd.dnd_drag_curwin; - gdk_dnd_display_drag_cursor(-1, -1, TRUE, TRUE); - } - gdk_dnd.dnd_drag_dropzone.x = xevent->xclient.data.l[2] & 65535; - gdk_dnd.dnd_drag_dropzone.y = - (xevent->xclient.data.l[2] >> 16) & 65535; - gdk_dnd.dnd_drag_dropzone.width = xevent->xclient.data.l[3] & 65535; - gdk_dnd.dnd_drag_dropzone.height = - (xevent->xclient.data.l[3] >> 16) & 65535; - } - } - else if(xevent->xclient.message_type == gdk_dnd.gdk_XdeDataAvailable) - { - gint tmp_int; Atom tmp_atom; - gulong tmp_long; - guchar *tmp_charptr; - -#ifdef G_ENABLE_DEBUG - if (gdk_debug_flags & (GDK_DEBUG_EVENTS | GDK_DEBUG_DND)) - g_print("GDK_DROP_DATA_AVAIL\n"); -#endif - event->dropdataavailable.u.allflags = xevent->xclient.data.l[1]; - event->dropdataavailable.timestamp = xevent->xclient.data.l[4]; - event->dropdataavailable.coords.x = - xevent->xclient.data.l[3] & 0xffff; - event->dropdataavailable.coords.y = - (xevent->xclient.data.l[3] >> 16) & 0xffff; - if(window - /* No preview of data ATM */ - && event->dropdataavailable.u.flags.isdrop) - { - event->dropdataavailable.type = GDK_DROP_DATA_AVAIL; - event->dropdataavailable.window = window; - event->dropdataavailable.requestor = xevent->xclient.data.l[0]; - event->dropdataavailable.data_type = - gdk_atom_name(xevent->xclient.data.l[2]); - if(XGetWindowProperty (gdk_display, - event->dropdataavailable.requestor, - xevent->xclient.data.l[2], - 0, LONG_MAX - 1, - False, XA_PRIMARY, &tmp_atom, - &tmp_int, - &event->dropdataavailable.data_numbytes, - &tmp_long, - &tmp_charptr) - != Success) - { - g_warning("XGetWindowProperty on %#x may have failed\n", - event->dropdataavailable.requestor); - event->dropdataavailable.data = NULL; - } - else - { - GDK_NOTE (DND, g_print("XGetWindowProperty got us %ld bytes\n", - event->dropdataavailable.data_numbytes)); - event->dropdataavailable.data = - g_malloc (event->dropdataavailable.data_numbytes); - memcpy (event->dropdataavailable.data, - tmp_charptr, event->dropdataavailable.data_numbytes); - XFree(tmp_charptr); - return_val = TRUE; - } - return_val = TRUE; - } - } - else - { - /* Send unknown ClientMessage's on to Gtk for it to use */ - event->client.type = GDK_CLIENT_EVENT; - event->client.window = window; - event->client.message_type = xevent->xclient.message_type; - event->client.data_format = xevent->xclient.format; - memcpy(&event->client.data, &xevent->xclient.data, - sizeof(event->client.data)); - if(window) - return_val = TRUE; - else - return_val = FALSE; - } - if(window_private) - return_val = return_val && !window_private->destroyed; - break; - - case MappingNotify: - /* Print debugging info. - */ - GDK_NOTE (EVENTS, - g_print ("mapping notify\n")); - - /* Let XLib know that there is a new keyboard mapping. - */ - XRefreshKeyboardMapping (&xevent->xmapping); - break; - - default: - /* something else - (e.g., a Xinput event) */ - - if (window_private && - !window_private->destroyed && - (window_private->extension_events != 0) && - gdk_input_vtable.other_event) - return_val = gdk_input_vtable.other_event(event, xevent, window); - else - return_val = FALSE; - - return_val = return_val && !window_private->destroyed; - - break; - } - - if (return_val) - { - if (event->any.window) - gdk_window_ref (event->any.window); - if (((event->any.type == GDK_ENTER_NOTIFY) || - (event->any.type == GDK_LEAVE_NOTIFY)) && - (event->crossing.subwindow != NULL)) - gdk_window_ref (event->crossing.subwindow); - } - else - { - /* Mark this event as having no resources to be freed */ - event->any.window = NULL; - event->any.type = GDK_NOTHING; - } - - if (window) - gdk_window_unref (window); - - return return_val; -} - -#if 0 -static Bool -gdk_event_get_type (Display *display, - XEvent *xevent, - XPointer arg) -{ - GdkEvent event; - GdkPredicate *pred; - - if (gdk_event_translate (&event, xevent)) - { - pred = (GdkPredicate*) arg; - return (* pred->func) (&event, pred->data); - } - - return FALSE; -} -#endif - -static void -gdk_synthesize_click (GdkEvent *event, - gint nclicks) -{ - GdkEvent temp_event; - - g_return_if_fail (event != NULL); - - temp_event = *event; - temp_event.type = (nclicks == 2) ? GDK_2BUTTON_PRESS : GDK_3BUTTON_PRESS; - - gdk_event_put (&temp_event); -} - -/* - *-------------------------------------------------------------- - * gdk_exit_func - * - * This is the "atexit" function that makes sure the - * library gets a chance to cleanup. - * - * Arguments: - * - * Results: - * - * Side effects: - * The library is un-initialized and the program exits. - * - *-------------------------------------------------------------- - */ - -static void -gdk_exit_func (void) -{ - static gboolean in_gdk_exit_func = FALSE; - - /* This is to avoid an infinite loop if a program segfaults in - an atexit() handler (and yes, it does happen, especially if a program - has trounced over memory too badly for even g_print to work) */ - if(in_gdk_exit_func == TRUE) return; - in_gdk_exit_func = TRUE; - - if (initialized) - { -#ifdef USE_XIM - /* cleanup IC */ - gdk_ic_cleanup (); - /* close IM */ - gdk_im_close (); -#endif - gdk_image_exit (); - gdk_input_exit (); - gdk_key_repeat_restore (); - - XCloseDisplay (gdk_display); - initialized = 0; - } -} - -/* - *-------------------------------------------------------------- - * gdk_x_error - * - * The X error handling routine. - * - * Arguments: - * "display" is the X display the error orignated from. - * "error" is the XErrorEvent that we are handling. - * - * Results: - * Either we were expecting some sort of error to occur, - * in which case we set the "gdk_error_code" flag, or this - * error was unexpected, in which case we will print an - * error message and exit. (Since trying to continue will - * most likely simply lead to more errors). - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -static int -gdk_x_error (Display *display, - XErrorEvent *error) -{ - char buf[64]; - - if (gdk_error_warnings) - { - XGetErrorText (display, error->error_code, buf, 63); - g_error ("%s\n serial %ld error_code %d request_code %d minor_code %d\n", - buf, - error->serial, - error->error_code, - error->request_code, - error->minor_code); - } - - gdk_error_code = -1; - return 0; -} - -/* - *-------------------------------------------------------------- - * gdk_x_io_error - * - * The X I/O error handling routine. - * - * Arguments: - * "display" is the X display the error orignated from. - * - * Results: - * An X I/O error basically means we lost our connection - * to the X server. There is not much we can do to - * continue, so simply print an error message and exit. - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -static int -gdk_x_io_error (Display *display) -{ - g_error ("an x io error occurred"); - return 0; -} - -/* - *-------------------------------------------------------------- - * gdk_signal - * - * The signal handler. - * - * Arguments: - * "sig_num" is the number of the signal we received. - * - * Results: - * The signals we catch are all fatal. So we simply build - * up a nice little error message and print it and exit. - * If in the process of doing so another signal is received - * we notice that we are already exiting and simply kill - * our process. - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -static RETSIGTYPE -gdk_signal (int sig_num) -{ - static int caught_fatal_sig = 0; - char *sig; - - if (caught_fatal_sig) - kill (getpid (), sig_num); - caught_fatal_sig = 1; - - switch (sig_num) - { - case SIGHUP: - sig = "sighup"; - break; - case SIGINT: - sig = "sigint"; - break; - case SIGQUIT: - sig = "sigquit"; - break; - case SIGBUS: - sig = "sigbus"; - break; - case SIGSEGV: - sig = "sigsegv"; - break; - case SIGPIPE: - sig = "sigpipe"; - break; - case SIGTERM: - sig = "sigterm"; - break; - default: - sig = "unknown signal"; - break; - } - - g_print ("\n** ERROR **: %s caught\n", sig); -#ifdef G_ENABLE_DEBUG - abort (); -#else /* !G_ENABLE_DEBUG */ - gdk_exit (1); -#endif /* !G_ENABLE_DEBUG */ -} - -static void -gdk_dnd_drag_begin (GdkWindow *initial_window) -{ - GdkEvent tev; - - GDK_NOTE(DND, g_print("------- STARTING DRAG from %p\n", initial_window)); - - tev.type = GDK_DRAG_BEGIN; - tev.dragbegin.window = initial_window; - tev.dragbegin.u.allflags = 0; - tev.dragbegin.u.flags.protocol_version = DND_PROTOCOL_VERSION; - - gdk_event_put (&tev); -} - -static void -gdk_dnd_drag_enter (Window dest) -{ - XEvent sev; - GdkEventDropEnter tev; - int i; - GdkWindowPrivate *wp; - - sev.xclient.type = ClientMessage; - sev.xclient.format = 32; - sev.xclient.message_type = gdk_dnd.gdk_XdeEnter; - sev.xclient.window = dest; - - tev.u.allflags = 0; - tev.u.flags.protocol_version = DND_PROTOCOL_VERSION; - tev.u.flags.sendreply = 1; - for (i = 0; i < gdk_dnd.drag_numwindows; i++) - { - wp = (GdkWindowPrivate *) gdk_dnd.drag_startwindows[i]; - if (wp->dnd_drag_data_numtypesavail) - { - sev.xclient.data.l[0] = wp->xwindow; - tev.u.flags.extended_typelist = (wp->dnd_drag_data_numtypesavail > 3)?1:0; - sev.xclient.data.l[1] = tev.u.allflags; - sev.xclient.data.l[2] = wp->dnd_drag_data_typesavail[0]; - if (wp->dnd_drag_data_numtypesavail > 1) - { - sev.xclient.data.l[3] = wp->dnd_drag_data_typesavail[1]; - if (wp->dnd_drag_data_numtypesavail > 2) - { - sev.xclient.data.l[4] = wp->dnd_drag_data_typesavail[2]; - } - else - sev.xclient.data.l[4] = None; - } - else - sev.xclient.data.l[3] = sev.xclient.data.l[4] = None; - if (!gdk_send_xevent (dest, False, StructureNotifyMask, &sev)) - GDK_NOTE (DND, g_print("Sending XdeEnter to %#lx failed\n", - dest)); - } - - } -} - - -#ifdef USE_XIM - -/* The following routines duplicate functionality in Xlib to - * translate from varargs to X's internal opaque XVaNestedList. - * - * If all vendors have stuck close to the reference implementation, - * then we should hopefully be OK. - */ - -/* This needs to match XIMArg as defined in Xlcint.h exactly */ - -typedef struct { - gchar *name; - gpointer value; -} GdkImArg; - -/************************************************************* - * gdk_im_va_count: - * Counts the number of name/value pairs in the vararg list - * - * arguments: - * - * results: - *************************************************************/ - -static guint -gdk_im_va_count (va_list list) -{ - gint count = 0; - gchar *name; - - name = va_arg (list, gchar *); - while (name) - { - count++; - (void)va_arg (list, gpointer); - name = va_arg (list, gchar *); - } - - return count; -} - -/************************************************************* - * gdk_im_va_to_nested: - * Given a varargs list and the result of gdk_im_va_count, - * create a XVaNestedList. - * - * arguments: - * - * results: - *************************************************************/ - -static XVaNestedList -gdk_im_va_to_nested (va_list list, guint count) -{ - GdkImArg *result; - GdkImArg *arg; - - gchar *name; - - if (count == 0) - return NULL; - - result = g_new (GdkImArg, count+1); - arg = result; - - name = va_arg (list, gchar *); - while (name) - { - arg->name = name; - arg->value = va_arg (list, gpointer); - arg++; - name = va_arg (list, gchar *); - } - - arg->name = NULL; - - return (XVaNestedList)result; -} - -/* - *-------------------------------------------------------------- - * gdk_im_begin - * - * Begin using input method with XIM Protocol(X11R6 standard) - * - * Arguments: - * "ic" is the "Input Context" which is created by gtk_ic_new. - * The input area is specified with "window". - * - * Results: - * The gdk's event handling routine is switched to XIM based routine. - * XIM based routine uses XFilterEvent to get rid of events used by IM, - * and uses XmbLookupString instead of XLookupString. - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -void -gdk_im_begin (GdkIC ic, GdkWindow* window) -{ - GdkICPrivate *private; - Window xwin; - - g_return_if_fail (ic != NULL); - g_return_if_fail (window); - - private = (GdkICPrivate *) ic; - - xim_using = TRUE; - xim_ic = private; - xim_window = window; - if (gdk_im_ready()) - { - XGetICValues (private->xic, XNFocusWindow, &xwin, NULL); - if (xwin != GDK_WINDOW_XWINDOW(window)) - XSetICValues (private->xic, XNFocusWindow, - GDK_WINDOW_XWINDOW(window), NULL); - if (private != xim_ic) - XSetICFocus (private->xic); - } -} - -/* - *-------------------------------------------------------------- - * gdk_im_end - * - * End using input method with XIM Protocol(X11R6 standard) - * - * Arguments: - * - * Results: - * The gdk's event handling routine is switched to normal routine. - * User should call this function before ic and window will be destroyed. - * - * Side effects: - * - *-------------------------------------------------------------- - */ - -void -gdk_im_end (void) -{ - xim_using = FALSE; - xim_ic = NULL; - xim_window = NULL; -} - -static GdkIM -gdk_im_get (void) -{ - return xim_im; -} - -static GdkIMStyle -gdk_im_choose_better_style (GdkIMStyle style1, GdkIMStyle style2) -{ - GdkIMStyle s1, s2, u; - - if (style1 == 0) return style2; - if (style2 == 0) return style1; - if ((style1 & (GdkIMPreeditMask | GdkIMStatusMask)) - == (style2 & (GdkIMPreeditMask | GdkIMStatusMask))) - return style1; - - s1 = style1 & GdkIMPreeditMask; - s2 = style2 & GdkIMPreeditMask; - u = s1 | s2; - if (s1 != s2) { - if (u & GdkIMPreeditCallbacks) - return (s1 == GdkIMPreeditCallbacks)? style1:style2; - else if (u & GdkIMPreeditPosition) - return (s1 == GdkIMPreeditPosition)? style1:style2; - else if (u & GdkIMPreeditArea) - return (s1 == GdkIMPreeditArea)? style1:style2; - else if (u & GdkIMPreeditNothing) - return (s1 == GdkIMPreeditNothing)? style1:style2; - } else { - s1 = style1 & GdkIMStatusMask; - s2 = style2 & GdkIMStatusMask; - u = s1 | s2; - if ( u & GdkIMStatusCallbacks) - return (s1 == GdkIMStatusCallbacks)? style1:style2; - else if ( u & GdkIMStatusArea) - return (s1 == GdkIMStatusArea)? style1:style2; - else if ( u & GdkIMStatusNothing) - return (s1 == GdkIMStatusNothing)? style1:style2; - else if ( u & GdkIMStatusNone) - return (s1 == GdkIMStatusNone)? style1:style2; - } - return 0; /* Get rid of stupid warning */ -} - -GdkIMStyle -gdk_im_decide_style (GdkIMStyle supported_style) -{ - gint i; - GdkIMStyle style, tmp; - - g_return_val_if_fail (xim_styles != NULL, 0); - - style = 0; - for (i=0; i<xim_styles->count_styles; i++) - { - tmp = xim_styles->supported_styles[i]; - if (tmp == (tmp & supported_style & xim_best_allowed_style)) - style = gdk_im_choose_better_style (style, tmp); - } - return style; -} - -GdkIMStyle -gdk_im_set_best_style (GdkIMStyle style) -{ - if (style & GdkIMPreeditMask) - { - xim_best_allowed_style &= ~GdkIMPreeditMask; - - xim_best_allowed_style |= GdkIMPreeditNone; - if (!(style & GdkIMPreeditNone)) - { - xim_best_allowed_style |= GdkIMPreeditNothing; - if (!(style & GdkIMPreeditNothing)) - { - xim_best_allowed_style |= GdkIMPreeditArea; - if (!(style & GdkIMPreeditArea)) - { - xim_best_allowed_style |= GdkIMPreeditPosition; - if (!(style & GdkIMPreeditPosition)) - xim_best_allowed_style |= GdkIMPreeditCallbacks; - } - } - } - } - if (style & GdkIMStatusMask) - { - xim_best_allowed_style &= ~GdkIMStatusMask; - - xim_best_allowed_style |= GdkIMStatusNone; - if (!(style & GdkIMStatusNone)) - { - xim_best_allowed_style |= GdkIMStatusNothing; - if (!(style & GdkIMStatusNothing)) - { - xim_best_allowed_style |= GdkIMStatusArea; - if (!(style & GdkIMStatusArea)) - xim_best_allowed_style |= GdkIMStatusCallbacks; - } - } - } - - return xim_best_allowed_style; -} - -static gint -gdk_im_open (XrmDatabase db, gchar* res_name, gchar* res_class) -{ - xim_im = XOpenIM (GDK_DISPLAY(), db, res_name, res_class); - if (xim_im == NULL) - { - GDK_NOTE (XIM, g_warning ("Unable to open open IM.")); - return FALSE; - } - XGetIMValues (xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL); - - return TRUE; -} - -static void -gdk_im_close (void) -{ - if (xim_im) - { - XCloseIM (xim_im); - xim_im = NULL; - } - if (xim_styles) - { - XFree (xim_styles); - xim_styles = NULL; - } -} - -gint -gdk_im_ready (void) -{ - return (xim_im != NULL); -} - -GdkIC -gdk_ic_new (GdkWindow* client_window, - GdkWindow* focus_window, - GdkIMStyle style, ...) -{ - va_list list; - GdkICPrivate *private; - XVaNestedList preedit_attr = NULL; - guint count; - - g_return_val_if_fail (client_window != NULL, NULL); - g_return_val_if_fail (focus_window != NULL, NULL); - g_return_val_if_fail (gdk_im_ready(), NULL); - - private = g_new (GdkICPrivate, 1); - - va_start (list, style); - count = gdk_im_va_count (list); - va_end (list); - - va_start (list, style); - preedit_attr = gdk_im_va_to_nested (list, count); - va_end (list); - - private->style = gdk_im_decide_style (style); - if (private->style != style) - { - g_warning ("can not create input context with specified input style."); - g_free (private); - return NULL; - } - - private->xic = XCreateIC(gdk_im_get (), - XNInputStyle, style, - XNClientWindow, GDK_WINDOW_XWINDOW (client_window), - XNFocusWindow, GDK_WINDOW_XWINDOW (focus_window), - preedit_attr? XNPreeditAttributes : NULL, preedit_attr, - NULL); - - g_free (preedit_attr); - - if (!private->xic) - { - g_free (private); - return NULL; - } - - xim_ic_list = g_list_append (xim_ic_list, private); - return private; -} - -void -gdk_ic_destroy (GdkIC ic) -{ - GdkICPrivate *private; - - g_return_if_fail (ic != NULL); - - private = (GdkICPrivate *) ic; - - if (xim_ic == private) - gdk_im_end (); - - XDestroyIC (private->xic); - xim_ic_list = g_list_remove (xim_ic_list, private); - g_free (private); -} - -GdkIMStyle -gdk_ic_get_style (GdkIC ic) -{ - GdkICPrivate *private; - - g_return_val_if_fail (ic != NULL, 0); - - private = (GdkICPrivate *) ic; - - return private->style; -} - -void -gdk_ic_set_values (GdkIC ic, ...) -{ - va_list list; - XVaNestedList args; - GdkICPrivate *private; - guint count; - - g_return_if_fail (ic != NULL); - - private = (GdkICPrivate *) ic; - - va_start (list, ic); - count = gdk_im_va_count (list); - va_end (list); - - va_start (list, ic); - args = gdk_im_va_to_nested (list, count); - va_end (list); - - XSetICValues (private->xic, XNVaNestedList, args, NULL); - - g_free (args); -} - -void -gdk_ic_get_values (GdkIC ic, ...) -{ - va_list list; - XVaNestedList args; - GdkICPrivate *private; - guint count; - - g_return_if_fail (ic != NULL); - - private = (GdkICPrivate *) ic; - - va_start (list, ic); - count = gdk_im_va_count (list); - va_end (list); - - va_start (list, ic); - args = gdk_im_va_to_nested (list, count); - va_end (list); - - XGetICValues (private->xic, XNVaNestedList, args, NULL); - - g_free (args); -} - -void -gdk_ic_set_attr (GdkIC ic, const char *target, ...) -{ - va_list list; - XVaNestedList attr; - GdkICPrivate *private; - guint count; - - g_return_if_fail (ic != NULL); - g_return_if_fail (target != NULL); - - private = (GdkICPrivate *) ic; - - va_start (list, target); - count = gdk_im_va_count (list); - va_end (list); - - va_start (list, target); - attr = gdk_im_va_to_nested (list, count); - va_end (list); - - XSetICValues (private->xic, target, attr, NULL); - - g_free (attr); -} - -void -gdk_ic_get_attr (GdkIC ic, const char *target, ...) -{ - va_list list; - XVaNestedList attr; - GdkICPrivate *private; - guint count; - - g_return_if_fail (ic != NULL); - g_return_if_fail (target != NULL); - - private = (GdkICPrivate *) ic; - - va_start (list, target); - count = gdk_im_va_count (list); - va_end (list); - - va_start (list, target); - attr = gdk_im_va_to_nested (list, count); - va_end (list); - - XGetICValues (private->xic, target, attr, NULL); - - g_free (attr); -} - -GdkEventMask -gdk_ic_get_events (GdkIC ic) -{ - GdkEventMask mask; - glong xmask; - glong bit; - GdkICPrivate *private; - gint i; - - /* From gdkwindow.c */ - extern int nevent_masks; - extern int event_mask_table[]; - - g_return_val_if_fail (ic != NULL, 0); - - private = (GdkICPrivate *) ic; - - if (XGetICValues (private->xic, XNFilterEvents, &xmask, NULL) != NULL) - { - GDK_NOTE (XIM, g_warning ("Call to XGetICValues: %s failed", XNFilterEvents)); - return 0; - } - - mask = 0; - for (i=0, bit=2; i < nevent_masks; i++, bit <<= 1) - if (xmask & event_mask_table [i]) - { - mask |= bit; - xmask &= ~ event_mask_table [i]; - } - - if (xmask) - g_warning ("ic requires events not supported by the application (%#04lx)", xmask); - - return mask; -} - -static void -gdk_ic_cleanup (void) -{ - GList* node; - gint destroyed; - GdkICPrivate *private; - - destroyed = 0; - for (node = xim_ic_list; node != NULL; node = node->next) - { - if (node->data) - { - private = (GdkICPrivate *) (node->data); - XDestroyIC (private->xic); - g_free (private); - destroyed++; - } - } -#ifdef G_ENABLE_DEBUG - if ((gdk_debug_flags & GDK_DEBUG_XIM) && destroyed > 0) - { - g_warning ("Cleaned up %i IC(s)\n", destroyed); - } -#endif /* G_ENABLE_DEBUG */ - g_list_free(xim_ic_list); - xim_ic_list = NULL; -} - -#else /* !USE_XIM */ - -void -gdk_im_begin (GdkIC ic, GdkWindow* window) -{ -} - -void -gdk_im_end (void) -{ -} - -GdkIMStyle -gdk_im_decide_style (GdkIMStyle supported_style) -{ - return GdkIMPreeditNone | GdkIMStatusNone; -} - -GdkIMStyle -gdk_im_set_best_style (GdkIMStyle style) -{ - return GdkIMPreeditNone | GdkIMStatusNone; -} - -gint -gdk_im_ready (void) -{ - return FALSE; -} - -GdkIC -gdk_ic_new (GdkWindow* client_window, - GdkWindow* focus_window, - GdkIMStyle style, ...) -{ - return NULL; -} - -void -gdk_ic_destroy (GdkIC ic) -{ -} - -GdkIMStyle -gdk_ic_get_style (GdkIC ic) -{ - return GdkIMPreeditNone | GdkIMStatusNone; -} - -void -gdk_ic_set_values (GdkIC ic, ...) -{ -} - -void -gdk_ic_get_values (GdkIC ic, ...) -{ -} - -void -gdk_ic_set_attr (GdkIC ic, const char *target, ...) -{ -} - -void -gdk_ic_get_attr (GdkIC ic, const char *target, ...) -{ -} - -GdkEventMask -gdk_ic_get_events (GdkIC ic) -{ - return 0; -} - -#endif /* USE_XIM */ - -#ifdef X_LOCALE - -gint -_g_mbtowc (wchar_t *wstr, const char *str, size_t len) -{ - static wchar_t wcs[MB_CUR_MAX + 1]; - static gchar mbs[MB_CUR_MAX + 1]; - - wcs[0] = (wchar_t) NULL; - mbs[0] = '\0'; - - /* The last argument isn't a mistake. The X locale code trims - * the input string to the length of the output string! - */ - len = _Xmbstowcs (wcs, str, (len<MB_CUR_MAX)? len:MB_CUR_MAX); - if (len < 1) - return len; - else if (wcs[0] == (wchar_t) NULL) - return -1; - - len = _Xwctomb (mbs, wcs[0]); - if (mbs[0] == '\0') - return -1; - if (wstr) - *wstr = wcs[0]; - - return len; -} - -#endif /* X_LOCALE */ - -static void -gdk_dnd_drag_leave (Window dest) -{ - XEvent sev; - GdkEventDropLeave tev; - int i; - GdkWindowPrivate *wp; - - tev.u.allflags = 0; - - tev.u.flags.protocol_version = DND_PROTOCOL_VERSION; - sev.xclient.type = ClientMessage; - sev.xclient.window = dest; - sev.xclient.format = 32; - sev.xclient.message_type = gdk_dnd.gdk_XdeLeave; - sev.xclient.data.l[1] = tev.u.allflags; - for (i = 0; i < gdk_dnd.drag_numwindows; i++) - { - wp = (GdkWindowPrivate *) gdk_dnd.drag_startwindows[i]; - sev.xclient.data.l[0] = wp->xwindow; - if (!gdk_send_xevent (dest, False, StructureNotifyMask, &sev)) - GDK_NOTE (DND, g_print("Sending XdeLeave to %#lx failed\n", - dest)); - wp->dnd_drag_accepted = 0; - } -} - -/* - * when a drop occurs, we go through the list of windows being dragged and - * tell them that it has occurred, so that they can set things up and reply - * to 'dest' window - */ -static void -gdk_dnd_drag_end (Window dest, - GdkPoint coords) -{ - GdkWindowPrivate *wp; - GdkEvent tev; - int i; - - tev.dragrequest.type = GDK_DRAG_REQUEST; - tev.dragrequest.drop_coords = coords; - tev.dragrequest.requestor = dest; - tev.dragrequest.u.allflags = 0; - tev.dragrequest.u.flags.protocol_version = DND_PROTOCOL_VERSION; - tev.dragrequest.isdrop = 1; - - for (i = 0; i < gdk_dnd.drag_numwindows; i++) - { - wp = (GdkWindowPrivate *) gdk_dnd.drag_startwindows[i]; - if (wp->dnd_drag_accepted) - { - tev.dragrequest.window = (GdkWindow *) wp; - tev.dragrequest.u.flags.delete_data = wp->dnd_drag_destructive_op; - tev.dragrequest.timestamp = gdk_dnd.last_drop_time; - tev.dragrequest.data_type = - gdk_atom_name(wp->dnd_drag_data_type); - - gdk_event_put(&tev); - } - } -} - -static GdkAtom -gdk_dnd_check_types (GdkWindow *window, - XEvent *xevent) -{ - GdkWindowPrivate *wp = (GdkWindowPrivate *) window; - int i, j; - GdkEventDropEnter event; - - g_return_val_if_fail(window != NULL, 0); - g_return_val_if_fail(xevent != NULL, 0); - g_return_val_if_fail(xevent->type == ClientMessage, 0); - g_return_val_if_fail(xevent->xclient.message_type == gdk_dnd.gdk_XdeEnter, 0); - - if(wp->dnd_drop_data_numtypesavail <= 0 || - !wp->dnd_drop_data_typesavail) - return 0; - - for (i = 2; i <= 4; i++) - { - for (j = 0; j < wp->dnd_drop_data_numtypesavail; j++) - { - if (xevent->xclient.data.l[i] == wp->dnd_drop_data_typesavail[j]) - return xevent->xclient.data.l[i]; - } - } - - /* Now we get the extended type list if it's available */ - event.u.allflags = xevent->xclient.data.l[1]; - if (event.u.flags.extended_typelist) - { - Atom *exttypes, realtype; - gulong nitems, nbar; - gint realfmt; - - if (XGetWindowProperty(gdk_display, xevent->xclient.data.l[0], - gdk_dnd.gdk_XdeTypelist, 0L, LONG_MAX - 1, - False, AnyPropertyType, &realtype, &realfmt, - &nitems, &nbar, (unsigned char **) &exttypes) - != Success) - return 0; - - if (realfmt != (sizeof(Atom) * 8)) - { - g_warning("XdeTypelist property had format of %d instead of the expected %ld, on window %#lx\n", - realfmt, (glong)sizeof(Atom) * 8, xevent->xclient.data.l[0]); - return 0; - } - - for (i = 0; i <= nitems; i++) - { - for (j = 0; j < wp->dnd_drop_data_numtypesavail; j++) - { - if (exttypes[i] == wp->dnd_drop_data_typesavail[j]) - { - XFree (exttypes); - return exttypes[i]; - } - } - } - XFree (exttypes); - } - return 0; -} - -/* - * used for debugging only - */ -#ifdef DEBUG_DND -static void -gdk_print_atom (GdkAtom anatom) -{ - gchar *tmpstr = NULL; - tmpstr = (anatom!=None)?gdk_atom_name(anatom):"(none)"; - g_print("Atom %lu has name %s\n", anatom, tmpstr); - if(tmpstr) - g_free(tmpstr); -} -#endif - -/* - * used only by below routine and itself - */ -static Window -getchildren (Display *dpy, - Window win, - Atom WM_STATE) -{ - Window root, parent, *children, inf = 0; - Atom type = None; - unsigned int nchildren, i; - int format; - unsigned long nitems, after; - unsigned char *data; - - if (XQueryTree(dpy, win, &root, &parent, &children, &nchildren) == 0) - return 0; - - for (i = 0; !inf && (i < nchildren); i++) - { - XGetWindowProperty (dpy, children[i], WM_STATE, 0, 0, False, - AnyPropertyType, &type, &format, &nitems, - &after, &data); - if (type != 0) - inf = children[i]; - XFree(data); - } - - for (i = 0; !inf && (i < nchildren); i++) - inf = getchildren (dpy, children[i], WM_STATE); - - if (children != None) - XFree ((char *) children); - - return inf; -} - -/* - * find a window with WM_STATE, else return win itself, as per ICCCM - * - * modification of the XmuClientWindow() routine from X11R6.3 - */ -Window -gdk_get_client_window (Display *dpy, - Window win) -{ - Atom WM_STATE; - Atom type = None; - int format; - unsigned long nitems, after; - unsigned char *data; - Window inf; - - if (win == 0) - return DefaultRootWindow(dpy); - - if ((WM_STATE = XInternAtom (dpy, "WM_STATE", True)) == 0) - return win; - - XGetWindowProperty (dpy, win, WM_STATE, 0, 0, False, AnyPropertyType, - &type, &format, &nitems, &after, &data); - if (type) - return win; - - inf = getchildren (dpy, win, WM_STATE); - - if (inf == 0) - return win; - else - return inf; -} - -#ifdef WE_HAVE_MOTIF_DROPS_DONE -static GdkWindow * -gdk_drop_get_real_window (GdkWindow *w, - guint16 *x, - guint16 *y) -{ - GdkWindow *retval = w; - GdkWindowPrivate *awin; - GList *children; - gint16 myx = *x, myy = *y; - - g_return_val_if_fail(w != NULL && x != NULL && y != NULL, NULL); - - myx = *x; - myy = *y; - -descend: - for (children = gdk_window_get_children(retval); - children && children->next; - children = children->next) - { - awin = (GdkWindowPrivate *) children->data; - if ((myx >= awin->x) && (myy >= awin->y) - && (myx < (awin->x + awin->width)) - && (myy < (awin->y + awin->height))) - { - retval = (GdkWindow *) awin; - myx -= awin->x; - myy -= awin->y; - goto descend; - } - } - - *x = myx; - *y = myy; - - return retval; -} -#endif - -/* Sends a ClientMessage to all toplevel client windows */ -void -gdk_event_send_clientmessage_toall(GdkEvent *event) -{ - XEvent sev; - Window *ret_children, ret_root, ret_parent, curwin; - unsigned int ret_nchildren; - int i; - - g_return_if_fail(event != NULL); - - /* Set up our event to send, with the exception of its target window */ - sev.xclient.type = ClientMessage; - sev.xclient.display = gdk_display; - sev.xclient.format = event->client.data_format; - sev.xclient.serial = CurrentTime; - memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data)); - sev.xclient.message_type = event->client.message_type; - - /* OK, we're all set, now let's find some windows to send this to */ - if(XQueryTree(gdk_display, gdk_root_window, &ret_root, &ret_parent, - &ret_children, &ret_nchildren) != True) - return; - - /* foreach true child window of the root window, send an event to it */ - for(i = 0; i < ret_nchildren; i++) { - curwin = gdk_get_client_window(gdk_display, ret_children[i]); - sev.xclient.window = curwin; - if (!gdk_send_xevent (curwin, False, NoEventMask, &sev)) - GDK_NOTE (MISC, g_print("Gdk: Sending client message %ld to %#lx failed\n", - event->client.message_type, curwin)); - } - - XFree(ret_children); -} - -gchar * -gdk_get_display(void) -{ - return (gchar *)XDisplayName (gdk_display_name); -} - -gint -gdk_send_xevent (Window window, gboolean propagate, glong event_mask, - XEvent *event_send) -{ - Status result; - - gdk_error_code = 0; - - gdk_error_warnings = 0; - result = XSendEvent (gdk_display, window, propagate, event_mask, event_send); - XSync (gdk_display, False); - gdk_error_warnings = 1; - - return result && (gdk_error_code != -1); -} diff --git a/gdk/x11/gdkpixmap-x11.c b/gdk/x11/gdkpixmap-x11.c deleted file mode 100644 index 27c19b004a..0000000000 --- a/gdk/x11/gdkpixmap-x11.c +++ /dev/null @@ -1,782 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#include "../config.h" -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -/* Needed for SEEK_END in SunOS */ -#include <unistd.h> -#include <X11/Xlib.h> - -#include "gdk.h" -#include "gdkprivate.h" - -typedef struct -{ - gchar *color_string; - GdkColor color; - gint transparent; -} _GdkPixmapColor; - -GdkPixmap* -gdk_pixmap_new (GdkWindow *window, - gint width, - gint height, - gint depth) -{ - GdkPixmap *pixmap; - GdkWindowPrivate *private; - GdkWindowPrivate *window_private; - - g_return_val_if_fail ((window != NULL) || (depth != -1), NULL); - g_return_val_if_fail ((width != 0) && (height != 0), NULL); - - if (!window) - window = (GdkWindow*) &gdk_root_parent; - - window_private = (GdkWindowPrivate*) window; - if (window_private->destroyed) - return NULL; - - if (depth == -1) - depth = gdk_window_get_visual (window)->depth; - - private = g_new (GdkWindowPrivate, 1); - pixmap = (GdkPixmap*) private; - - private->xdisplay = window_private->xdisplay; - private->window_type = GDK_WINDOW_PIXMAP; - private->xwindow = XCreatePixmap (private->xdisplay, window_private->xwindow, - width, height, depth); - private->colormap = NULL; - private->parent = NULL; - private->x = 0; - private->y = 0; - private->width = width; - private->height = height; - private->resize_count = 0; - private->ref_count = 1; - private->destroyed = 0; - - gdk_xid_table_insert (&private->xwindow, pixmap); - - return pixmap; -} - -GdkPixmap * -gdk_bitmap_create_from_data (GdkWindow *window, - gchar *data, - gint width, - gint height) -{ - GdkPixmap *pixmap; - GdkWindowPrivate *private; - GdkWindowPrivate *window_private; - - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail ((width != 0) && (height != 0), NULL); - - if (!window) - window = (GdkWindow*) &gdk_root_parent; - - window_private = (GdkWindowPrivate*) window; - if (window_private->destroyed) - return NULL; - - private = g_new (GdkWindowPrivate, 1); - pixmap = (GdkPixmap*) private; - - private->parent = NULL; - private->xdisplay = window_private->xdisplay; - private->window_type = GDK_WINDOW_PIXMAP; - private->x = 0; - private->y = 0; - private->width = width; - private->height = height; - private->resize_count = 0; - private->ref_count = 1; - private->destroyed = FALSE; - - private->xwindow = XCreateBitmapFromData (private->xdisplay, - window_private->xwindow, - data, width, height); - - gdk_xid_table_insert (&private->xwindow, pixmap); - - return pixmap; -} - -GdkPixmap* -gdk_pixmap_create_from_data (GdkWindow *window, - gchar *data, - gint width, - gint height, - gint depth, - GdkColor *fg, - GdkColor *bg) -{ - GdkPixmap *pixmap; - GdkWindowPrivate *private; - GdkWindowPrivate *window_private; - - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (fg != NULL, NULL); - g_return_val_if_fail (bg != NULL, NULL); - g_return_val_if_fail ((window != NULL) || (depth != -1), NULL); - g_return_val_if_fail ((width != 0) && (height != 0), NULL); - - if (!window) - window = (GdkWindow*) &gdk_root_parent; - - window_private = (GdkWindowPrivate*) window; - if (window_private->destroyed) - return NULL; - - if (depth == -1) - depth = gdk_window_get_visual (window)->depth; - - private = g_new (GdkWindowPrivate, 1); - pixmap = (GdkPixmap*) private; - - private->parent = NULL; - private->xdisplay = window_private->xdisplay; - private->window_type = GDK_WINDOW_PIXMAP; - private->x = 0; - private->y = 0; - private->width = width; - private->height = height; - private->resize_count = 0; - private->ref_count = 1; - private->destroyed = FALSE; - - private->xwindow = XCreatePixmapFromBitmapData (private->xdisplay, - window_private->xwindow, - data, width, height, - fg->pixel, bg->pixel, depth); - - gdk_xid_table_insert (&private->xwindow, pixmap); - - return pixmap; -} - -gint -gdk_pixmap_seek_string (FILE *infile, - const gchar *str, - gint skip_comments) -{ - char instr[1024]; - - while (!feof (infile)) - { - fscanf (infile, "%1023s", instr); - if (skip_comments == TRUE && strcmp (instr, "/*") == 0) - { - fscanf (infile, "%1023s", instr); - while (!feof (infile) && strcmp (instr, "*/") != 0) - fscanf (infile, "%1023s", instr); - fscanf(infile, "%1023s", instr); - } - if (strcmp (instr, str)==0) - return TRUE; - } - - return FALSE; -} - -gint -gdk_pixmap_seek_char (FILE *infile, - gchar c) -{ - gint b, oldb; - - while ((b = getc(infile)) != EOF) - { - if (c != b && b == '/') - { - b = getc (infile); - if (b == EOF) - return FALSE; - else if (b == '*') /* we have a comment */ - { - b = -1; - do - { - oldb = b; - b = getc (infile); - if (b == EOF) - return FALSE; - } - while (!(oldb == '*' && b == '/')); - } - } - else if (c == b) - return TRUE; - } - return FALSE; -} - -gint -gdk_pixmap_read_string (FILE *infile, - gchar **buffer, - guint *buffer_size) -{ - gint c; - guint cnt = 0; - - if ((*buffer) == NULL) - { - (*buffer_size) = 10 * sizeof (gchar); - (*buffer) = g_new(gchar, *buffer_size); - } - - do - c = getc (infile); - while (c != EOF && c != '"'); - - if (c != '"') - return FALSE; - - while ((c = getc(infile)) != EOF) - { - if (cnt == (*buffer_size)) - { - guint new_size = (*buffer_size) * 2; - if (new_size > (*buffer_size)) - *buffer_size = new_size; - else - return FALSE; - - (*buffer) = (gchar *) g_realloc ((*buffer), *buffer_size); - } - - if (c != '"') - (*buffer)[cnt++] = c; - else - { - (*buffer)[cnt++] = 0; - return TRUE; - } - } - - return FALSE; -} - -gchar* -gdk_pixmap_skip_whitespaces (gchar *buffer) -{ - gint32 index = 0; - - while (buffer[index] != 0 && (buffer[index] == 0x20 || buffer[index] == 0x09)) - index++; - - return &buffer[index]; -} - -gchar* -gdk_pixmap_skip_string (gchar *buffer) -{ - gint32 index = 0; - - while (buffer[index] != 0 && buffer[index] != 0x20 && buffer[index] != 0x09) - index++; - - return &buffer[index]; -} - -/* Xlib crashed ince at a color name lengths around 125 */ -#define MAX_COLOR_LEN 120 - -gchar* -gdk_pixmap_extract_color (gchar *buffer) -{ - gint counter, numnames; - gchar *ptr = NULL, ch, temp[128]; - gchar color[MAX_COLOR_LEN], *retcol; - gint space; - - counter = 0; - while (ptr == NULL) - { - if (buffer[counter] == 'c') - { - ch = buffer[counter + 1]; - if (ch == 0x20 || ch == 0x09) - ptr = &buffer[counter + 1]; - } - else if (buffer[counter] == 0) - return NULL; - - counter++; - } - - ptr = gdk_pixmap_skip_whitespaces (ptr); - - if (ptr[0] == 0) - return NULL; - else if (ptr[0] == '#') - { - counter = 1; - while (ptr[counter] != 0 && - ((ptr[counter] >= '0' && ptr[counter] <= '9') || - (ptr[counter] >= 'a' && ptr[counter] <= 'f') || - (ptr[counter] >= 'A' && ptr[counter] <= 'F'))) - counter++; - - retcol = g_new (gchar, counter+1); - strncpy (retcol, ptr, counter); - - retcol[counter] = 0; - - return retcol; - } - - color[0] = 0; - numnames = 0; - - space = MAX_COLOR_LEN - 1; - while (space > 0) - { - sscanf (ptr, "%127s", temp); - - if (((gint)ptr[0] == 0) || - (strcmp ("s", temp) == 0) || (strcmp ("m", temp) == 0) || - (strcmp ("g", temp) == 0) || (strcmp ("g4", temp) == 0)) - { - break; - } - else - { - if (numnames > 0) - { - space -= 1; - strcat (color, " "); - } - if (space > 0) - { - strncat (color, temp, space); - space -= MIN (space, strlen (temp)); - } - ptr = gdk_pixmap_skip_string (ptr); - ptr = gdk_pixmap_skip_whitespaces (ptr); - numnames++; - } - } - - retcol = g_strdup (color); - return retcol; -} - -GdkPixmap* -gdk_pixmap_colormap_create_from_xpm (GdkWindow *window, - GdkColormap *colormap, - GdkBitmap **mask, - GdkColor *transparent_color, - const gchar *filename) -{ - FILE *infile = NULL; - GdkPixmap *pixmap = NULL; - GdkImage *image = NULL; - GdkVisual *visual; - GdkGC *gc; - GdkColor tmp_color; - gint width, height, num_cols, cpp, cnt, n, ns, xcnt, ycnt; - gchar *buffer = NULL, pixel_str[32]; - guint buffer_size = 0; - _GdkPixmapColor *colors = NULL, *color = NULL; - gulong index; - - if ((window == NULL) && (colormap == NULL)) - g_warning ("Creating pixmap from xpm with NULL window and colormap"); - - if (window == NULL) - window = (GdkWindow *)&gdk_root_parent; - - if (colormap == NULL) - { - colormap = gdk_window_get_colormap (window); - visual = gdk_window_get_visual (window); - } - else - visual = ((GdkColormapPrivate *)colormap)->visual; - - infile = fopen (filename, "rb"); - if (infile != NULL) - { - if (gdk_pixmap_seek_string (infile, "XPM", FALSE) == TRUE) - { - if (gdk_pixmap_seek_char (infile,'{') == TRUE) - { - gdk_pixmap_seek_char (infile, '"'); - fseek (infile, -1, SEEK_CUR); - gdk_pixmap_read_string (infile, &buffer, &buffer_size); - - sscanf (buffer,"%d %d %d %d", &width, &height, &num_cols, &cpp); - if (cpp >= 32) - { - g_warning ("Pixmap has more than 31 characters per color\n"); - return NULL; - } - - colors = g_new(_GdkPixmapColor, num_cols); - - if (transparent_color == NULL) - { - gdk_color_white (colormap, &tmp_color); - transparent_color = &tmp_color; - } - - for (cnt = 0; cnt < num_cols; cnt++) - { - gchar *color_name; - - gdk_pixmap_seek_char (infile, '"'); - fseek (infile, -1, SEEK_CUR); - gdk_pixmap_read_string (infile, &buffer, &buffer_size); - - colors[cnt].color_string = g_new(gchar, cpp + 1); - for (n = 0; n < cpp; n++) - colors[cnt].color_string[n] = buffer[n]; - colors[cnt].color_string[n] = 0; - colors[cnt].transparent = FALSE; - - color_name = gdk_pixmap_extract_color (&buffer[cpp]); - - if (color_name != NULL) - { - if (gdk_color_parse (color_name, &colors[cnt].color) == FALSE) - { - colors[cnt].color = *transparent_color; - colors[cnt].transparent = TRUE; - } - } - else - { - colors[cnt].color = *transparent_color; - colors[cnt].transparent = TRUE; - } - - g_free (color_name); - - gdk_color_alloc (colormap, &colors[cnt].color); - } - - index = 0; - image = gdk_image_new (GDK_IMAGE_FASTEST, visual, width, height); - - gc = NULL; - if (mask) - { - /* The pixmap mask is just a bits pattern. - * Color 0 is used for background and 1 for foreground. - * We don't care about the colormap, we just need 0 and 1. - */ - GdkColor mask_pattern; - - *mask = gdk_pixmap_new (window, width, height, 1); - gc = gdk_gc_new (*mask); - - mask_pattern.pixel = 0; - gdk_gc_set_foreground (gc, &mask_pattern); - gdk_draw_rectangle (*mask, gc, TRUE, 0, 0, -1, -1); - - mask_pattern.pixel = 1; - gdk_gc_set_foreground (gc, &mask_pattern); - } - - for (ycnt = 0; ycnt < height; ycnt++) - { - gdk_pixmap_read_string (infile, &buffer, &buffer_size); - - for (n = 0, cnt = 0, xcnt = 0; n < (width * cpp); n += cpp, xcnt++) - { - strncpy (pixel_str, &buffer[n], cpp); - pixel_str[cpp] = 0; - color = NULL; - ns = 0; - - while ((color == NULL) && (ns < num_cols)) - { - if (strcmp (pixel_str, colors[ns].color_string) == 0) - color = &colors[ns]; - else - ns++; - } - - if (!color) /* screwed up XPM file */ - color = &colors[0]; - - gdk_image_put_pixel (image, xcnt, ycnt, color->color.pixel); - - if (mask && color->transparent) - { - if (cnt < xcnt) - gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt); - cnt = xcnt + 1; - } - } - - if (mask && (cnt < xcnt)) - gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt); - } - - if (mask) - gdk_gc_destroy (gc); - - pixmap = gdk_pixmap_new (window, width, height, visual->depth); - - gc = gdk_gc_new (pixmap); - gdk_gc_set_foreground (gc, transparent_color); - gdk_draw_image (pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); - gdk_gc_destroy (gc); - gdk_image_destroy (image); - } - } - - fclose (infile); - free (buffer); - - if (colors != NULL) - { - for (cnt = 0; cnt < num_cols; cnt++) - g_free (colors[cnt].color_string); - g_free (colors); - } - } - - return pixmap; -} - -GdkPixmap* -gdk_pixmap_create_from_xpm (GdkWindow *window, - GdkBitmap **mask, - GdkColor *transparent_color, - const gchar *filename) -{ - return gdk_pixmap_colormap_create_from_xpm (window, NULL, mask, - transparent_color, filename); -} - - -GdkPixmap* -gdk_pixmap_colormap_create_from_xpm_d (GdkWindow *window, - GdkColormap *colormap, - GdkBitmap **mask, - GdkColor *transparent_color, - gchar **data) -{ - GdkPixmap *pixmap = NULL; - GdkImage *image = NULL; - GdkVisual *visual; - GdkGC *gc; - GdkColor tmp_color; - gint width, height, num_cols, cpp, cnt, n, ns, xcnt, ycnt, i; - gchar *buffer, pixel_str[32]; - _GdkPixmapColor *colors = NULL, *color = NULL; - gulong index; - - if ((window == NULL) && (colormap == NULL)) - g_warning ("Creating pixmap from xpm with NULL window and colormap"); - - if (window == NULL) - window = (GdkWindow *)&gdk_root_parent; - - if (colormap == NULL) - { - colormap = gdk_window_get_colormap (window); - visual = gdk_window_get_visual (window); - } - else - visual = ((GdkColormapPrivate *)colormap)->visual; - - i = 0; - buffer = data[i++]; - sscanf (buffer,"%d %d %d %d", &width, &height, &num_cols, &cpp); - if (cpp >= 32) - { - g_warning ("Pixmap has more than 31 characters per color\n"); - return NULL; - } - - colors = g_new(_GdkPixmapColor, num_cols); - - if (transparent_color == NULL) - { - gdk_color_white (colormap, &tmp_color); - transparent_color = &tmp_color; - } - - for (cnt = 0; cnt < num_cols; cnt++) - { - gchar *color_name; - - buffer = data[i++]; - - colors[cnt].color_string = g_new(gchar, cpp + 1); - for (n = 0; n < cpp; n++) - colors[cnt].color_string[n] = buffer[n]; - colors[cnt].color_string[n] = 0; - colors[cnt].transparent = FALSE; - - color_name = gdk_pixmap_extract_color (&buffer[cpp]); - - if (color_name != NULL) - { - if (gdk_color_parse (color_name, &colors[cnt].color) == FALSE) - { - colors[cnt].color = *transparent_color; - colors[cnt].transparent = TRUE; - } - } - else - { - colors[cnt].color = *transparent_color; - colors[cnt].transparent = TRUE; - } - - g_free (color_name); - - gdk_color_alloc (colormap, &colors[cnt].color); - } - - index = 0; - image = gdk_image_new (GDK_IMAGE_FASTEST, visual, width, height); - - gc = NULL; - if (mask) - { - /* The pixmap mask is just a bits pattern. - * Color 0 is used for background and 1 for foreground. - * We don't care about the colormap, we just need 0 and 1. - */ - GdkColor mask_pattern; - - *mask = gdk_pixmap_new (window, width, height, 1); - gc = gdk_gc_new (*mask); - - mask_pattern.pixel = 0; - gdk_gc_set_foreground (gc, &mask_pattern); - gdk_draw_rectangle (*mask, gc, TRUE, 0, 0, -1, -1); - - mask_pattern.pixel = 1; - gdk_gc_set_foreground (gc, &mask_pattern); - } - - for (ycnt = 0; ycnt < height; ycnt++) - { - buffer = data[i++]; - - for (n = 0, cnt = 0, xcnt = 0; n < (width * cpp); n += cpp, xcnt++) - { - strncpy (pixel_str, &buffer[n], cpp); - pixel_str[cpp] = 0; - color = NULL; - ns = 0; - - while ((color == NULL) && (ns < num_cols)) - { - if (strcmp (pixel_str, colors[ns].color_string) == 0) - color = &colors[ns]; - else - ns++; - } - - if (!color) /* screwed up XPM file */ - color = &colors[0]; - - gdk_image_put_pixel (image, xcnt, ycnt, color->color.pixel); - - if (mask && color->transparent) - { - if (cnt < xcnt) - gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt); - cnt = xcnt + 1; - } - } - - if (mask && (cnt < xcnt)) - gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt); - } - - if (mask) - gdk_gc_destroy (gc); - - pixmap = gdk_pixmap_new (window, width, height, visual->depth); - - gc = gdk_gc_new (pixmap); - gdk_gc_set_foreground (gc, transparent_color); - gdk_draw_image (pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); - gdk_gc_destroy (gc); - gdk_image_destroy (image); - - if (colors != NULL) - { - for (cnt = 0; cnt < num_cols; cnt++) - g_free (colors[cnt].color_string); - g_free (colors); - } - - return pixmap; -} - -GdkPixmap* -gdk_pixmap_create_from_xpm_d (GdkWindow *window, - GdkBitmap **mask, - GdkColor *transparent_color, - gchar **data) -{ - return gdk_pixmap_colormap_create_from_xpm_d (window, NULL, mask, - transparent_color, data); -} - -GdkPixmap* -gdk_pixmap_ref (GdkPixmap *pixmap) -{ - GdkWindowPrivate *private = (GdkWindowPrivate *)pixmap; - g_return_val_if_fail (pixmap != NULL, NULL); - - private->ref_count += 1; - return pixmap; -} - -void -gdk_pixmap_unref (GdkPixmap *pixmap) -{ - GdkWindowPrivate *private = (GdkWindowPrivate *)pixmap; - g_return_if_fail(pixmap != NULL); - - private->ref_count -= 1; - if (private->ref_count == 0) - { - XFreePixmap (private->xdisplay, private->xwindow); - gdk_xid_table_remove (private->xwindow); - g_free (private); - } -} - -GdkBitmap * -gdk_bitmap_ref (GdkBitmap *bitmap) -{ - return (GdkBitmap *)gdk_pixmap_ref ((GdkPixmap *)bitmap); -} - -void -gdk_bitmap_unref (GdkBitmap *bitmap) -{ - gdk_pixmap_unref ((GdkPixmap *)bitmap); -} diff --git a/gdk/x11/gdkproperty-x11.c b/gdk/x11/gdkproperty-x11.c deleted file mode 100644 index 36e3c22024..0000000000 --- a/gdk/x11/gdkproperty-x11.c +++ /dev/null @@ -1,214 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#include <X11/Xlib.h> -#include <X11/Xatom.h> -#include <string.h> -#include "gdk.h" -#include "gdkprivate.h" - - -GdkAtom -gdk_atom_intern (const gchar *atom_name, - gint only_if_exists) -{ - return XInternAtom (gdk_display, atom_name, only_if_exists); -} - -gchar * -gdk_atom_name (GdkAtom atom) -{ - gchar *t; - gchar *name; - - /* If this atom doesn't exist, we'll die with an X error unless - we take precautions */ - - gdk_error_warnings = 0; - gdk_error_code = 0; - t = XGetAtomName (gdk_display, atom); - gdk_error_warnings = 1; - - if (gdk_error_code == -1) - { - return NULL; - } - else - { - name = g_strdup (t); - XFree (t); - - return name; - } -} - -gint -gdk_property_get (GdkWindow *window, - GdkAtom property, - GdkAtom type, - gulong offset, - gulong length, - gint pdelete, - GdkAtom *actual_property_type, - gint *actual_format_type, - gint *actual_length, - guchar **data) -{ - Display *xdisplay; - Window xwindow; - Atom ret_prop_type; - gint ret_format; - gulong ret_nitems; - gulong ret_bytes_after; - gulong ret_length; - guchar *ret_data; - - if (window) - { - GdkWindowPrivate *private; - - private = (GdkWindowPrivate*) window; - if (private->destroyed) - return FALSE; - - xdisplay = private->xdisplay; - xwindow = private->xwindow; - } - else - { - xdisplay = gdk_display; - xwindow = gdk_root_window; - } - - XGetWindowProperty (xdisplay, xwindow, property, - offset, (length + 3) / 4, pdelete, - type, &ret_prop_type, &ret_format, - &ret_nitems, &ret_bytes_after, - &ret_data); - - if ((ret_prop_type == None) && (ret_format == 0)) { - return FALSE; - } - - if (actual_property_type) - *actual_property_type = ret_prop_type; - if (actual_format_type) - *actual_format_type = ret_format; - - if (ret_prop_type != type) - { - gchar *rn, *pn; - XFree (ret_data); - rn = gdk_atom_name(ret_prop_type); - pn = gdk_atom_name(type); - g_warning("Couldn't match property type %s to %s\n", rn, pn); - g_free(rn); g_free(pn); - return FALSE; - } - - /* FIXME: ignoring bytes_after could have very bad effects */ - - if (data) - { - switch (ret_format) - { - case 8: - ret_length = ret_nitems; - break; - case 16: - ret_length = 2 * ret_nitems; - break; - case 32: - ret_length = 4 * ret_nitems; - break; - default: - g_warning ("unknown property return format: %d", ret_format); - XFree (ret_data); - return FALSE; - } - - *data = g_new (guchar, ret_length); - memcpy (*data, ret_data, ret_length); - if (actual_length) - *actual_length = ret_length; - } - - XFree (ret_data); - - return TRUE; -} - -void -gdk_property_change (GdkWindow *window, - GdkAtom property, - GdkAtom type, - gint format, - GdkPropMode mode, - guchar *data, - gint nelements) -{ - Display *xdisplay; - Window xwindow; - - if (window) - { - GdkWindowPrivate *private; - - private = (GdkWindowPrivate*) window; - if (private->destroyed) - return; - - xdisplay = private->xdisplay; - xwindow = private->xwindow; - } - else - { - xdisplay = gdk_display; - xwindow = gdk_root_window; - } - - XChangeProperty (xdisplay, xwindow, property, type, - format, mode, data, nelements); -} - -void -gdk_property_delete (GdkWindow *window, - GdkAtom property) -{ - Display *xdisplay; - Window xwindow; - - if (window) - { - GdkWindowPrivate *private; - - private = (GdkWindowPrivate*) window; - if (private->destroyed) - return; - - xdisplay = private->xdisplay; - xwindow = private->xwindow; - } - else - { - xdisplay = gdk_display; - xwindow = gdk_root_window; - } - - XDeleteProperty (xdisplay, xwindow, property); -} diff --git a/gdk/x11/gdkregion-x11.c b/gdk/x11/gdkregion-x11.c deleted file mode 100644 index 4b5c1c866c..0000000000 --- a/gdk/x11/gdkregion-x11.c +++ /dev/null @@ -1,302 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include "gdk.h" -#include "gdkprivate.h" - - - - -GdkRegion* -gdk_region_new (void) -{ - GdkRegionPrivate *private; - GdkRegion *region; - Region xregion; - - xregion = XCreateRegion(); - private = g_new (GdkRegionPrivate, 1); - private->xregion = xregion; - region = (GdkRegion*) private; - region->user_data = NULL; - - return region; -} - -void -gdk_region_destroy (GdkRegion *region) -{ - GdkRegionPrivate *private; - - g_return_if_fail (region != NULL); - - private = (GdkRegionPrivate *) region; - XDestroyRegion (private->xregion); - - g_free (private); -} - -gboolean -gdk_region_empty (GdkRegion *region) -{ - GdkRegionPrivate *private; - - g_return_val_if_fail (region != NULL, 0); - - private = (GdkRegionPrivate *) region; - - return XEmptyRegion (private->xregion); -} - -gboolean -gdk_region_equal (GdkRegion *region1, - GdkRegion *region2) -{ - GdkRegionPrivate *private1; - GdkRegionPrivate *private2; - - g_return_val_if_fail (region1 != NULL, 0); - g_return_val_if_fail (region2 != NULL, 0); - - private1 = (GdkRegionPrivate *) region1; - private2 = (GdkRegionPrivate *) region2; - - return XEqualRegion (private1->xregion, private2->xregion); -} - -gboolean -gdk_region_point_in (GdkRegion *region, - gint x, - gint y) -{ - GdkRegionPrivate *private; - - g_return_val_if_fail (region != NULL, 0); - - private = (GdkRegionPrivate *) region; - - return XPointInRegion (private->xregion, x, y); -} - -GdkOverlapType -gdk_region_rect_in (GdkRegion *region, - GdkRectangle *rect) -{ - GdkRegionPrivate *private; - int res; - - g_return_val_if_fail (region != NULL, 0); - - private = (GdkRegionPrivate *) region; - - res = XRectInRegion (private->xregion, rect->x, rect->y, rect->width, rect->height); - - switch (res) - { - case RectangleIn: return GDK_OVERLAP_RECTANGLE_IN; - case RectangleOut: return GDK_OVERLAP_RECTANGLE_OUT; - case RectanglePart: return GDK_OVERLAP_RECTANGLE_PART; - } - - return GDK_OVERLAP_RECTANGLE_OUT; /*what else ? */ -} - -GdkRegion * -gdk_region_polygon (GdkPoint *points, - gint npoints, - GdkFillRule fill_rule) -{ - GdkRegionPrivate *private; - GdkRegion *region; - Region xregion; - gint xfill_rule = EvenOddRule; - - g_return_val_if_fail (points != NULL, NULL); - g_return_val_if_fail (npoints != 0, NULL); /* maybe we should check for at least three points */ - - switch (fill_rule) - { - case GDK_EVEN_ODD_RULE: - xfill_rule = EvenOddRule; - break; - - case GDK_WINDING_RULE: - xfill_rule = WindingRule; - break; - } - - xregion = XPolygonRegion ((XPoint *) points, npoints, xfill_rule); - private = g_new (GdkRegionPrivate, 1); - private->xregion = xregion; - region = (GdkRegion *) private; - region->user_data = NULL; - - return region; -} - -void -gdk_region_offset (GdkRegion *region, - gint dx, - gint dy) -{ - GdkRegionPrivate *private; - - g_return_if_fail (region != NULL); - - private = (GdkRegionPrivate *) region; - - XOffsetRegion (private->xregion, dx, dy); -} - -void -gdk_region_shrink (GdkRegion *region, - gint dx, - gint dy) -{ - GdkRegionPrivate *private; - - g_return_if_fail (region != NULL); - - private = (GdkRegionPrivate *) region; - - XShrinkRegion (private->xregion, dx, dy); -} - -GdkRegion* -gdk_region_union_with_rect (GdkRegion *region, - GdkRectangle *rect) -{ - GdkRegionPrivate *private; - GdkRegion *res; - GdkRegionPrivate *res_private; - XRectangle xrect; - - g_return_val_if_fail (region != NULL, NULL); - - private = (GdkRegionPrivate *) region; - - xrect.x = rect->x; - xrect.y = rect->y; - xrect.width = rect->width; - xrect.height = rect->height; - - res = gdk_region_new (); - res_private = (GdkRegionPrivate *) res; - - XUnionRectWithRegion (&xrect, private->xregion, res_private->xregion); - - return res; -} - -GdkRegion* -gdk_regions_intersect (GdkRegion *source1, - GdkRegion *source2) -{ - GdkRegionPrivate *private1; - GdkRegionPrivate *private2; - GdkRegion *res; - GdkRegionPrivate *res_private; - - g_return_val_if_fail (source1 != NULL, NULL); - g_return_val_if_fail (source2 != NULL, NULL); - - private1 = (GdkRegionPrivate *) source1; - private2 = (GdkRegionPrivate *) source2; - - res = gdk_region_new (); - res_private = (GdkRegionPrivate *) res; - - XIntersectRegion (private1->xregion, private2->xregion, res_private->xregion); - - return res; -} - -GdkRegion* -gdk_regions_union (GdkRegion *source1, - GdkRegion *source2) -{ - GdkRegionPrivate *private1; - GdkRegionPrivate *private2; - GdkRegion *res; - GdkRegionPrivate *res_private; - - g_return_val_if_fail (source1 != NULL, NULL); - g_return_val_if_fail (source2 != NULL, NULL); - - private1 = (GdkRegionPrivate *) source1; - private2 = (GdkRegionPrivate *) source2; - - res = gdk_region_new (); - res_private = (GdkRegionPrivate *) res; - - XUnionRegion (private1->xregion, private2->xregion, res_private->xregion); - - return res; -} - -GdkRegion* -gdk_regions_subtract (GdkRegion *source1, - GdkRegion *source2) -{ - GdkRegionPrivate *private1; - GdkRegionPrivate *private2; - GdkRegion *res; - GdkRegionPrivate *res_private; - - g_return_val_if_fail (source1 != NULL, NULL); - g_return_val_if_fail (source2 != NULL, NULL); - - private1 = (GdkRegionPrivate *) source1; - private2 = (GdkRegionPrivate *) source2; - - res = gdk_region_new (); - res_private = (GdkRegionPrivate *) res; - - XSubtractRegion (private1->xregion, private2->xregion, res_private->xregion); - - return res; -} - -GdkRegion* -gdk_regions_xor (GdkRegion *source1, - GdkRegion *source2) -{ - GdkRegionPrivate *private1; - GdkRegionPrivate *private2; - GdkRegion *res; - GdkRegionPrivate *res_private; - - g_return_val_if_fail (source1 != NULL, NULL); - g_return_val_if_fail (source2 != NULL, NULL); - - private1 = (GdkRegionPrivate *) source1; - private2 = (GdkRegionPrivate *) source2; - - res = gdk_region_new (); - res_private = (GdkRegionPrivate *) res; - - XXorRegion (private1->xregion, private2->xregion, res_private->xregion); - - return res; -} - - - diff --git a/gdk/x11/gdkselection-x11.c b/gdk/x11/gdkselection-x11.c deleted file mode 100644 index f1abc01cfb..0000000000 --- a/gdk/x11/gdkselection-x11.c +++ /dev/null @@ -1,246 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#include <X11/Xlib.h> -#include <X11/Xatom.h> -#include <string.h> -#include "gdk.h" -#include "gdkprivate.h" -#include "gdkx.h" - - -gint -gdk_selection_owner_set (GdkWindow *owner, - GdkAtom selection, - guint32 time, - gint send_event) -{ - Display *xdisplay; - Window xwindow; - - if (owner) - { - GdkWindowPrivate *private; - - private = (GdkWindowPrivate*) owner; - if (private->destroyed) - return FALSE; - - xdisplay = private->xdisplay; - xwindow = private->xwindow; - } - else - { - xdisplay = gdk_display; - xwindow = None; - } - - XSetSelectionOwner (xdisplay, selection, xwindow, time); - - return (XGetSelectionOwner (xdisplay, selection) == xwindow); -} - -GdkWindow* -gdk_selection_owner_get (GdkAtom selection) -{ - Window xwindow; - - xwindow = XGetSelectionOwner (gdk_display, selection); - if (xwindow == None) - return NULL; - - return gdk_window_lookup (xwindow); -} - -void -gdk_selection_convert (GdkWindow *requestor, - GdkAtom selection, - GdkAtom target, - guint32 time) -{ - GdkWindowPrivate *private; - - g_return_if_fail (requestor != NULL); - - private = (GdkWindowPrivate*) requestor; - if (private->destroyed) - return; - - XConvertSelection (private->xdisplay, selection, target, - gdk_selection_property, private->xwindow, time); -} - -gint -gdk_selection_property_get (GdkWindow *requestor, - guchar **data, - GdkAtom *ret_type, - gint *ret_format) -{ - GdkWindowPrivate *private; - gulong nitems; - gulong nbytes; - gulong length; - GdkAtom prop_type; - gint prop_format; - guchar *t; - - g_return_val_if_fail (requestor != NULL, 0); - - /* If retrieved chunks are typically small, (and the ICCM says the - should be) it would be a win to try first with a buffer of - moderate length, to avoid two round trips to the server */ - - private = (GdkWindowPrivate*) requestor; - if (private->destroyed) - return 0; - - XGetWindowProperty (private->xdisplay, private->xwindow, - gdk_selection_property, 0, 0, False, - AnyPropertyType, &prop_type, &prop_format, - &nitems, &nbytes, &t); - - if (ret_type) - *ret_type = prop_type; - if (ret_format) - *ret_format = prop_format; - - if (prop_type == None) - { - *data = NULL; - return 0; - } - - XFree (t); - - /* Add on an extra byte to handle null termination. X guarantees - that t will be 1 longer than nbytes and null terminated */ - length = nbytes + 1; - - /* We can't delete the selection here, because it might be the INCR - protocol, in which case the client has to make sure they'll be - notified of PropertyChange events _before_ the property is deleted. - Otherwise there's no guarantee we'll win the race ... */ - XGetWindowProperty (private->xdisplay, private->xwindow, - gdk_selection_property, 0, (nbytes + 3) / 4, False, - AnyPropertyType, &prop_type, &prop_format, - &nitems, &nbytes, &t); - - if (prop_type != None) - { - *data = g_new (guchar, length); - memcpy (*data, t, length); - XFree (t); - return length-1; - } - else - { - *data = NULL; - return 0; - } -} - - -void -gdk_selection_send_notify (guint32 requestor, - GdkAtom selection, - GdkAtom target, - GdkAtom property, - guint32 time) -{ - XSelectionEvent xevent; - - xevent.type = SelectionNotify; - xevent.serial = 0; - xevent.send_event = True; - xevent.display = gdk_display; - xevent.requestor = requestor; - xevent.selection = selection; - xevent.target = target; - xevent.property = property; - xevent.time = time; - - XSendEvent (gdk_display, requestor, False, NoEventMask, (XEvent*) &xevent); -} - -gint -gdk_text_property_to_text_list (GdkAtom encoding, gint format, - guchar *text, gint length, - gchar ***list) -{ - XTextProperty property; - gint count = 0; - gint res; - - if (!list) - return 0; - - property.value = text; - property.encoding = encoding; - property.format = format; - property.nitems = length; - res = XmbTextPropertyToTextList (GDK_DISPLAY(), &property, list, &count); - - if (res == XNoMemory || res == XLocaleNotSupported || - res == XConverterNotFound) - return 0; - else - return count; -} - -void -gdk_free_text_list (gchar **list) -{ - XFreeStringList (list); -} - -gint -gdk_string_to_compound_text (gchar *str, - GdkAtom *encoding, gint *format, - guchar **ctext, gint *length) -{ - gint res; - XTextProperty property; - - res = XmbTextListToTextProperty (GDK_DISPLAY(), - &str, 1, XCompoundTextStyle, - &property); - if (res != Success) - { - property.encoding = None; - property.format = None; - property.value = NULL; - property.nitems = 0; - } - - if (encoding) - *encoding = property.encoding; - if (format) - *format = property.format; - if (ctext) - *ctext = property.value; - if (length) - *length = property.nitems; - - return res; -} - -void gdk_free_compound_text (guchar *ctext) -{ - if (ctext) - XFree (ctext); -} diff --git a/gdk/x11/gdkvisual-x11.c b/gdk/x11/gdkvisual-x11.c deleted file mode 100644 index a6a8b2b134..0000000000 --- a/gdk/x11/gdkvisual-x11.c +++ /dev/null @@ -1,443 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include "gdk.h" -#include "gdkprivate.h" - - -static void gdk_visual_add (GdkVisual *visual); -static void gdk_visual_decompose_mask (gulong mask, - gint *shift, - gint *prec); -static guint gdk_visual_hash (Visual *key); -static gint gdk_visual_compare (Visual *a, - Visual *b); - - -static GdkVisualPrivate *system_visual; -static GdkVisualPrivate *visuals; -static gint nvisuals; - -static gint available_depths[4]; -static gint navailable_depths; - -static GdkVisualType available_types[6]; -static gint navailable_types; - -#ifdef G_ENABLE_DEBUG - -static gchar* visual_names[] = -{ - "static gray", - "grayscale", - "static color", - "pseudo color", - "true color", - "direct color", -}; - -#endif /* G_ENABLE_DEBUG */ - -static GHashTable *visual_hash = NULL; - -void -gdk_visual_init (void) -{ - static gint possible_depths[6] = { 32, 24, 16, 15, 8, 1 }; - static GdkVisualType possible_types[6] = - { - GDK_VISUAL_DIRECT_COLOR, - GDK_VISUAL_TRUE_COLOR, - GDK_VISUAL_PSEUDO_COLOR, - GDK_VISUAL_STATIC_COLOR, - GDK_VISUAL_GRAYSCALE, - GDK_VISUAL_STATIC_GRAY - }; - - static gint npossible_depths = 6; - static gint npossible_types = 6; - - XVisualInfo *visual_list; - XVisualInfo visual_template; - GdkVisualPrivate temp_visual; - Visual *default_xvisual; - int nxvisuals; - int i, j; - - visual_template.screen = gdk_screen; - visual_list = XGetVisualInfo (gdk_display, VisualScreenMask, &visual_template, &nxvisuals); - visuals = g_new (GdkVisualPrivate, nxvisuals); - - default_xvisual = DefaultVisual (gdk_display, gdk_screen); - - nvisuals = 0; - for (i = 0; i < nxvisuals; i++) - { - if (visual_list[i].depth >= 1) - { -#ifdef __cplusplus - switch (visual_list[i].c_class) -#else /* __cplusplus */ - switch (visual_list[i].class) -#endif /* __cplusplus */ - { - case StaticGray: - visuals[nvisuals].visual.type = GDK_VISUAL_STATIC_GRAY; - break; - case GrayScale: - visuals[nvisuals].visual.type = GDK_VISUAL_GRAYSCALE; - break; - case StaticColor: - visuals[nvisuals].visual.type = GDK_VISUAL_STATIC_COLOR; - break; - case PseudoColor: - visuals[nvisuals].visual.type = GDK_VISUAL_PSEUDO_COLOR; - break; - case TrueColor: - visuals[nvisuals].visual.type = GDK_VISUAL_TRUE_COLOR; - break; - case DirectColor: - visuals[nvisuals].visual.type = GDK_VISUAL_DIRECT_COLOR; - break; - } - - visuals[nvisuals].visual.depth = visual_list[i].depth; - visuals[nvisuals].visual.byte_order = - (ImageByteOrder(gdk_display) == LSBFirst) ? - GDK_LSB_FIRST : GDK_MSB_FIRST; - visuals[nvisuals].visual.red_mask = visual_list[i].red_mask; - visuals[nvisuals].visual.green_mask = visual_list[i].green_mask; - visuals[nvisuals].visual.blue_mask = visual_list[i].blue_mask; - visuals[nvisuals].visual.colormap_size = visual_list[i].colormap_size; - visuals[nvisuals].visual.bits_per_rgb = visual_list[i].bits_per_rgb; - visuals[nvisuals].xvisual = visual_list[i].visual; - - if ((visuals[nvisuals].visual.type == GDK_VISUAL_TRUE_COLOR) || - (visuals[nvisuals].visual.type == GDK_VISUAL_DIRECT_COLOR)) - { - gdk_visual_decompose_mask (visuals[nvisuals].visual.red_mask, - &visuals[nvisuals].visual.red_shift, - &visuals[nvisuals].visual.red_prec); - - gdk_visual_decompose_mask (visuals[nvisuals].visual.green_mask, - &visuals[nvisuals].visual.green_shift, - &visuals[nvisuals].visual.green_prec); - - gdk_visual_decompose_mask (visuals[nvisuals].visual.blue_mask, - &visuals[nvisuals].visual.blue_shift, - &visuals[nvisuals].visual.blue_prec); - } - else - { - visuals[nvisuals].visual.red_mask = 0; - visuals[nvisuals].visual.red_shift = 0; - visuals[nvisuals].visual.red_prec = 0; - - visuals[nvisuals].visual.green_mask = 0; - visuals[nvisuals].visual.green_shift = 0; - visuals[nvisuals].visual.green_prec = 0; - - visuals[nvisuals].visual.blue_mask = 0; - visuals[nvisuals].visual.blue_shift = 0; - visuals[nvisuals].visual.blue_prec = 0; - } - - nvisuals += 1; - } - } - - XFree (visual_list); - - for (i = 0; i < nvisuals; i++) - { - for (j = i+1; j < nvisuals; j++) - { - if (visuals[j].visual.depth >= visuals[i].visual.depth) - { - if ((visuals[j].visual.depth == 8) && (visuals[i].visual.depth == 8)) - { - if (visuals[j].visual.type == GDK_VISUAL_PSEUDO_COLOR) - { - temp_visual = visuals[j]; - visuals[j] = visuals[i]; - visuals[i] = temp_visual; - } - else if ((visuals[i].visual.type != GDK_VISUAL_PSEUDO_COLOR) && - visuals[j].visual.type > visuals[i].visual.type) - { - temp_visual = visuals[j]; - visuals[j] = visuals[i]; - visuals[i] = temp_visual; - } - } - else if ((visuals[j].visual.depth > visuals[i].visual.depth) || - ((visuals[j].visual.depth == visuals[i].visual.depth) && - (visuals[j].visual.type > visuals[i].visual.type))) - { - temp_visual = visuals[j]; - visuals[j] = visuals[i]; - visuals[i] = temp_visual; - } - } - } - } - - for (i = 0; i < nvisuals; i++) - if (default_xvisual->visualid == visuals[i].xvisual->visualid) - { - system_visual = &visuals[i]; - break; - } - -#ifdef G_ENABLE_DEBUG - if (gdk_debug_flags & GDK_DEBUG_MISC) - for (i = 0; i < nvisuals; i++) - g_print ("Gdk: visual: %s: %d\n", - visual_names[visuals[i].visual.type], - visuals[i].visual.depth); -#endif /* G_ENABLE_DEBUG */ - - navailable_depths = 0; - for (i = 0; i < npossible_depths; i++) - { - for (j = 0; j < nvisuals; j++) - { - if (visuals[j].visual.depth == possible_depths[i]) - { - available_depths[navailable_depths++] = visuals[j].visual.depth; - break; - } - } - } - - if (navailable_depths == 0) - g_error ("unable to find a usable depth"); - - navailable_types = 0; - for (i = 0; i < npossible_types; i++) - { - for (j = 0; j < nvisuals; j++) - { - if (visuals[j].visual.type == possible_types[i]) - { - available_types[navailable_types++] = visuals[j].visual.type; - break; - } - } - } - - for (i = 0; i < nvisuals; i++) - gdk_visual_add ((GdkVisual*) &visuals[i]); - - if (npossible_types == 0) - g_error ("unable to find a usable visual type"); -} - -GdkVisual* -gdk_visual_ref (GdkVisual *visual) -{ - return visual; -} - -void -gdk_visual_unref (GdkVisual *visual) -{ - return; -} - -gint -gdk_visual_get_best_depth (void) -{ - return available_depths[0]; -} - -GdkVisualType -gdk_visual_get_best_type (void) -{ - return available_types[0]; -} - -GdkVisual* -gdk_visual_get_system (void) -{ - return ((GdkVisual*) system_visual); -} - -GdkVisual* -gdk_visual_get_best (void) -{ - return ((GdkVisual*) &(visuals[0])); -} - -GdkVisual* -gdk_visual_get_best_with_depth (gint depth) -{ - GdkVisual *return_val; - int i; - - return_val = NULL; - for (i = 0; i < nvisuals; i++) - if (depth == visuals[i].visual.depth) - { - return_val = (GdkVisual*) &(visuals[i]); - break; - } - - return return_val; -} - -GdkVisual* -gdk_visual_get_best_with_type (GdkVisualType visual_type) -{ - GdkVisual *return_val; - int i; - - return_val = NULL; - for (i = 0; i < nvisuals; i++) - if (visual_type == visuals[i].visual.type) - { - return_val = (GdkVisual*) &(visuals[i]); - break; - } - - return return_val; -} - -GdkVisual* -gdk_visual_get_best_with_both (gint depth, - GdkVisualType visual_type) -{ - GdkVisual *return_val; - int i; - - return_val = NULL; - for (i = 0; i < nvisuals; i++) - if ((depth == visuals[i].visual.depth) && - (visual_type == visuals[i].visual.type)) - { - return_val = (GdkVisual*) &(visuals[i]); - break; - } - - return return_val; -} - -void -gdk_query_depths (gint **depths, - gint *count) -{ - *count = navailable_depths; - *depths = available_depths; -} - -void -gdk_query_visual_types (GdkVisualType **visual_types, - gint *count) -{ - *count = navailable_types; - *visual_types = available_types; -} - -GList* -gdk_list_visuals (void) -{ - GList *list; - guint i; - - list = NULL; - for (i = 0; i < nvisuals; ++i) - list = g_list_append (list, (gpointer) &visuals[i]); - - return list; -} - - -GdkVisual* -gdk_visual_lookup (Visual *xvisual) -{ - GdkVisual *visual; - - if (!visual_hash) - return NULL; - - visual = g_hash_table_lookup (visual_hash, xvisual); - return visual; -} - -GdkVisual* -gdkx_visual_get (VisualID xvisualid) -{ - int i; - - for (i = 0; i < nvisuals; i++) - if (xvisualid == visuals[i].xvisual->visualid) - return (GdkVisual*) &visuals[i]; - - return NULL; -} - - -static void -gdk_visual_add (GdkVisual *visual) -{ - GdkVisualPrivate *private; - - if (!visual_hash) - visual_hash = g_hash_table_new ((GHashFunc) gdk_visual_hash, - (GCompareFunc) gdk_visual_compare); - - private = (GdkVisualPrivate*) visual; - - g_hash_table_insert (visual_hash, private->xvisual, visual); -} - -static void -gdk_visual_decompose_mask (gulong mask, - gint *shift, - gint *prec) -{ - *shift = 0; - *prec = 0; - - while (!(mask & 0x1)) - { - (*shift)++; - mask >>= 1; - } - - while (mask & 0x1) - { - (*prec)++; - mask >>= 1; - } -} - -static guint -gdk_visual_hash (Visual *key) -{ - return key->visualid; -} - -static gint -gdk_visual_compare (Visual *a, - Visual *b) -{ - return (a->visualid == b->visualid); -} diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c deleted file mode 100644 index e80717071a..0000000000 --- a/gdk/x11/gdkwindow-x11.c +++ /dev/null @@ -1,1983 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/Xatom.h> -#include <netinet/in.h> -#include "gdk.h" -#include "../config.h" -#include "gdkinput.h" -#include "gdkprivate.h" -#include "MwmUtil.h" -#include <stdlib.h> -#include <stdio.h> - -#ifdef HAVE_SHAPE_EXT -#include <X11/extensions/shape.h> -#endif - -int nevent_masks = 17; -int event_mask_table[19] = -{ - ExposureMask, - PointerMotionMask, - PointerMotionHintMask, - ButtonMotionMask, - Button1MotionMask, - Button2MotionMask, - Button3MotionMask, - ButtonPressMask | OwnerGrabButtonMask, - ButtonReleaseMask | OwnerGrabButtonMask, - KeyPressMask, - KeyReleaseMask, - EnterWindowMask, - LeaveWindowMask, - FocusChangeMask, - StructureNotifyMask, - PropertyChangeMask, - VisibilityChangeMask, - 0, /* PROXIMITY_IN */ - 0 /* PROXIMTY_OUT */ -}; - - -/* internal function created for and used by gdk_window_xid_at_coords */ -Window -gdk_window_xid_at(Window base, gint bx, gint by, gint x, gint y, - GList *excludes, gboolean excl_child) -{ - GdkWindow *window; - GdkWindowPrivate *private; - Display *disp; - Window *list=NULL; - Window child=0,parent_win=0,root_win=0; - - int i; - unsigned int ww, wh, wb, wd, num; - int wx,wy; - - window=(GdkWindow*)&gdk_root_parent; - private=(GdkWindowPrivate*)window; - disp=private->xdisplay; - if (!XGetGeometry(disp,base,&root_win,&wx,&wy,&ww,&wh,&wb,&wd)) - return 0; - wx+=bx;wy+=by; - if (!((x>=wx)&&(y>=wy)&&(x<(int)(wx+ww))&&(y<(int)(wy+wh)))) - return 0; - if (!XQueryTree(disp,base,&root_win,&parent_win,&list,&num)) - return base; - if (list) - { - for (i=num-1;;i--) - { - if ((!excl_child)||(!g_list_find(excludes,(gpointer *)list[i]))) - { - if ((child=gdk_window_xid_at(list[i],wx,wy,x,y,excludes,excl_child))!=0) - { - XFree(list); - return child; - } - } - if (!i) break; - } - XFree(list); - } - return base; -} - -/* - * The following fucntion by The Rasterman <raster@redhat.com> - * This function returns the X Window ID in which the x y location is in - * (x and y being relative to the root window), excluding any windows listed - * in the GList excludes (this is a list of X Window ID's - gpointer being - * the Window ID). - * - * This is primarily designed for internal gdk use - for DND for example - * when using a shaped icon window as the drag object - you exclude the - * X Window ID of the "icon" (perhaps more if excludes may be needed) and - * You can get back an X Window ID as to what X Window ID is infact under - * those X,Y co-ordinates. - */ -Window -gdk_window_xid_at_coords(gint x, gint y, GList *excludes, gboolean excl_child) -{ - GdkWindow *window; - GdkWindowPrivate *private; - Display *disp; - Window *list=NULL; - Window root,child=0,parent_win=0,root_win=0; - unsigned int num; - int i; - - window=(GdkWindow*)&gdk_root_parent; - private=(GdkWindowPrivate*)window; - disp=private->xdisplay; - root=private->xwindow; - XGrabServer(disp); - num=g_list_length(excludes); - if (!XQueryTree(disp,root,&root_win,&parent_win,&list,&num)) - return root; - if (list) - { - i = num - 1; - do - { - XWindowAttributes xwa; - - XGetWindowAttributes (disp, list [i], &xwa); - - if (xwa.map_state != IsViewable) - continue; - - if (excl_child && g_list_find(excludes,(gpointer *)list[i])) - continue; - - if ((child = gdk_window_xid_at (list[i], 0, 0, x, y, excludes, excl_child)) == 0) - continue; - - if (excludes) - { - if (!g_list_find(excludes,(gpointer *)child)) - { - XFree(list); - XUngrabServer(disp); - return child; - } - } - else - { - XFree(list); - XUngrabServer(disp); - return child; - } - } while (--i > 0); - XFree(list); - } - XUngrabServer(disp); - return root; -} - -void -gdk_window_init (void) -{ - XWindowAttributes xattributes; - unsigned int width; - unsigned int height; - unsigned int border_width; - unsigned int depth; - int x, y; - - XGetGeometry (gdk_display, gdk_root_window, &gdk_root_window, - &x, &y, &width, &height, &border_width, &depth); - XGetWindowAttributes (gdk_display, gdk_root_window, &xattributes); - - gdk_root_parent.xdisplay = gdk_display; - gdk_root_parent.xwindow = gdk_root_window; - gdk_root_parent.window_type = GDK_WINDOW_ROOT; - gdk_root_parent.window.user_data = NULL; - gdk_root_parent.width = width; - gdk_root_parent.height = height; - gdk_root_parent.children = NULL; - gdk_root_parent.colormap = NULL; -} - -GdkWindow* -gdk_window_new (GdkWindow *parent, - GdkWindowAttr *attributes, - gint attributes_mask) -{ - GdkWindow *window; - GdkWindowPrivate *private; - GdkWindowPrivate *parent_private; - GdkVisual *visual; - Display *parent_display; - Window xparent; - Visual *xvisual; - XSetWindowAttributes xattributes; - long xattributes_mask; - XSizeHints size_hints; - XWMHints wm_hints; - XClassHint *class_hint; - int x, y, depth; - unsigned int class; - char *title; - int i; - - g_return_val_if_fail (attributes != NULL, NULL); - - if (!parent) - parent = (GdkWindow*) &gdk_root_parent; - - parent_private = (GdkWindowPrivate*) parent; - if (parent_private->destroyed) - return NULL; - - xparent = parent_private->xwindow; - parent_display = parent_private->xdisplay; - - private = g_new (GdkWindowPrivate, 1); - window = (GdkWindow*) private; - - private->parent = parent; - - if (parent_private != &gdk_root_parent) - parent_private->children = g_list_prepend (parent_private->children, window); - - private->xdisplay = parent_display; - private->destroyed = FALSE; - private->resize_count = 0; - private->ref_count = 1; - xattributes_mask = 0; - - if (attributes_mask & GDK_WA_X) - x = attributes->x; - else - x = 0; - - if (attributes_mask & GDK_WA_Y) - y = attributes->y; - else - y = 0; - - private->x = x; - private->y = y; - private->width = (attributes->width > 1) ? (attributes->width) : (1); - private->height = (attributes->height > 1) ? (attributes->height) : (1); - private->window_type = attributes->window_type; - private->extension_events = FALSE; - private->dnd_drag_data_type = None; - private->dnd_drag_data_typesavail = - private->dnd_drop_data_typesavail = NULL; - private->dnd_drop_enabled = private->dnd_drag_enabled = - private->dnd_drag_accepted = private->dnd_drag_datashow = - private->dnd_drop_data_numtypesavail = - private->dnd_drag_data_numtypesavail = 0; - private->dnd_drag_eventmask = private->dnd_drag_savedeventmask = 0; - - private->filters = NULL; - private->children = NULL; - - window->user_data = NULL; - - if (attributes_mask & GDK_WA_VISUAL) - visual = attributes->visual; - else - visual = gdk_visual_get_system (); - xvisual = ((GdkVisualPrivate*) visual)->xvisual; - - xattributes.event_mask = StructureNotifyMask; - for (i = 0; i < nevent_masks; i++) - { - if (attributes->event_mask & (1 << (i + 1))) - xattributes.event_mask |= event_mask_table[i]; - } - - if (xattributes.event_mask) - xattributes_mask |= CWEventMask; - - if(attributes_mask & GDK_WA_NOREDIR) { - xattributes.override_redirect = - (attributes->override_redirect == FALSE)?False:True; - xattributes_mask |= CWOverrideRedirect; - } else - xattributes.override_redirect = False; - - if (attributes->wclass == GDK_INPUT_OUTPUT) - { - class = InputOutput; - depth = visual->depth; - - if (attributes_mask & GDK_WA_COLORMAP) - private->colormap = attributes->colormap; - else - private->colormap = gdk_colormap_get_system (); - - xattributes.background_pixel = BlackPixel (gdk_display, gdk_screen); - xattributes.border_pixel = BlackPixel (gdk_display, gdk_screen); - xattributes_mask |= CWBorderPixel | CWBackPixel; - - switch (private->window_type) - { - case GDK_WINDOW_TOPLEVEL: - xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap; - xattributes_mask |= CWColormap; - - xparent = gdk_root_window; - break; - - case GDK_WINDOW_CHILD: - xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap; - xattributes_mask |= CWColormap; - break; - - case GDK_WINDOW_DIALOG: - xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap; - xattributes_mask |= CWColormap; - - xparent = gdk_root_window; - break; - - case GDK_WINDOW_TEMP: - xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap; - xattributes_mask |= CWColormap; - - xparent = gdk_root_window; - - xattributes.save_under = True; - xattributes.override_redirect = True; - xattributes.cursor = None; - xattributes_mask |= CWSaveUnder | CWOverrideRedirect; - break; - case GDK_WINDOW_ROOT: - g_error ("cannot make windows of type GDK_WINDOW_ROOT"); - break; - case GDK_WINDOW_PIXMAP: - g_error ("cannot make windows of type GDK_WINDOW_PIXMAP (use gdk_pixmap_new)"); - break; - } - } - else - { - depth = 0; - class = InputOnly; - private->colormap = NULL; - } - - private->xwindow = XCreateWindow (private->xdisplay, xparent, - x, y, private->width, private->height, - 0, depth, class, xvisual, - xattributes_mask, &xattributes); - gdk_window_ref (window); - gdk_xid_table_insert (&private->xwindow, window); - - if (private->colormap) - gdk_colormap_ref (private->colormap); - - gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ? - (attributes->cursor) : - NULL)); - - switch (private->window_type) - { - case GDK_WINDOW_DIALOG: - XSetTransientForHint (private->xdisplay, private->xwindow, xparent); - case GDK_WINDOW_TOPLEVEL: - case GDK_WINDOW_TEMP: - XSetWMProtocols (private->xdisplay, private->xwindow, gdk_wm_window_protocols, 2); - break; - case GDK_WINDOW_CHILD: - if ((attributes->wclass == GDK_INPUT_OUTPUT) && - (private->colormap != gdk_colormap_get_system ()) && - (private->colormap != gdk_window_get_colormap (gdk_window_get_toplevel (window)))) - { - GDK_NOTE (MISC, g_print ("adding colormap window\n")); - gdk_window_add_colormap_windows (window); - } - - return window; - default: - - return window; - } - - size_hints.flags = PSize; - size_hints.width = private->width; - size_hints.height = private->height; - - wm_hints.flags = InputHint | StateHint | WindowGroupHint; - wm_hints.window_group = gdk_leader_window; - wm_hints.input = True; - wm_hints.initial_state = NormalState; - - /* FIXME: Is there any point in doing this? Do any WM's pay - * attention to PSize, and even if they do, is this the - * correct value??? - */ - XSetWMNormalHints (private->xdisplay, private->xwindow, &size_hints); - - XSetWMHints (private->xdisplay, private->xwindow, &wm_hints); - - if (attributes_mask & GDK_WA_TITLE) - title = attributes->title; - else - title = gdk_progname; - - XmbSetWMProperties (private->xdisplay, private->xwindow, - title, title, - NULL, 0, - NULL, NULL, NULL); - - if (attributes_mask & GDK_WA_WMCLASS) - { - class_hint = XAllocClassHint (); - class_hint->res_name = attributes->wmclass_name; - class_hint->res_class = attributes->wmclass_class; - XSetClassHint (private->xdisplay, private->xwindow, class_hint); - XFree (class_hint); - } - - - return window; -} - -GdkWindow * -gdk_window_foreign_new (guint32 anid) -{ - GdkWindow *window; - GdkWindowPrivate *private; - GdkWindowPrivate *parent_private; - XWindowAttributes attrs; - Window root, parent; - Window *children; - guint nchildren; - - private = g_new (GdkWindowPrivate, 1); - window = (GdkWindow*) private; - - XGetWindowAttributes (gdk_display, anid, &attrs); - - /* FIXME: This is pretty expensive. Maybe the caller should supply - * the parent */ - XQueryTree (gdk_display, anid, &root, &parent, &children, &nchildren); - XFree (children); - private->parent = gdk_xid_table_lookup (parent); - - parent_private = (GdkWindowPrivate *)private->parent; - - if (parent_private) - parent_private->children = g_list_prepend (parent_private->children, window); - - private->xwindow = anid; - private->xdisplay = gdk_display; - private->x = attrs.x; - private->y = attrs.y; - private->width = attrs.width; - private->height = attrs.height; - private->resize_count = 0; - private->ref_count = 1; - private->window_type = GDK_WINDOW_FOREIGN; - private->destroyed = FALSE; - private->extension_events = 0; - - private->colormap = NULL; - - private->dnd_drag_data_type = None; - private->dnd_drag_data_typesavail = - private->dnd_drop_data_typesavail = NULL; - private->dnd_drop_enabled = private->dnd_drag_enabled = - private->dnd_drag_accepted = private->dnd_drag_datashow = - private->dnd_drop_data_numtypesavail = - private->dnd_drag_data_numtypesavail = 0; - private->dnd_drag_eventmask = private->dnd_drag_savedeventmask = 0; - - private->filters = NULL; - private->children = NULL; - - window->user_data = NULL; - - gdk_window_ref (window); - gdk_xid_table_insert (&private->xwindow, window); - - return window; -} - -/* Call this function when you want a window and all its children to - disappear. When xdestroy is true, a request to destroy the XWindow - is sent out. When it is false, it is assumed that the XWindow has - been or will be destroyed by destroying some ancestor of this - window. */ - -static void -gdk_window_internal_destroy (GdkWindow *window, gboolean xdestroy, - gboolean our_destroy) -{ - GdkWindowPrivate *private; - GdkWindowPrivate *temp_private; - GdkWindow *temp_window; - GList *children; - GList *tmp; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - - switch (private->window_type) - { - case GDK_WINDOW_TOPLEVEL: - case GDK_WINDOW_CHILD: - case GDK_WINDOW_DIALOG: - case GDK_WINDOW_TEMP: - case GDK_WINDOW_FOREIGN: - if (!private->destroyed) - { - if (private->parent) - { - GdkWindowPrivate *parent_private = (GdkWindowPrivate *)private->parent; - if (parent_private->children) - parent_private->children = g_list_remove (parent_private->children, window); - } - - if (private->window_type != GDK_WINDOW_FOREIGN) - { - children = tmp = private->children; - private->children = NULL; - - while (tmp) - { - temp_window = tmp->data; - tmp = tmp->next; - - temp_private = (GdkWindowPrivate*) temp_window; - if (temp_private) - gdk_window_internal_destroy (temp_window, FALSE, - our_destroy); - } - - g_list_free (children); - } - - if (private->extension_events != 0) - gdk_input_window_destroy (window); - - if(private->dnd_drag_data_numtypesavail > 0) - { - g_free (private->dnd_drag_data_typesavail); - private->dnd_drag_data_typesavail = NULL; - } - if(private->dnd_drop_data_numtypesavail > 0) - { - g_free (private->dnd_drop_data_typesavail); - private->dnd_drop_data_typesavail = NULL; - } - - if (private->filters) - { - tmp = private->filters; - - while (tmp) - { - g_free (tmp->data); - tmp = tmp->next; - } - - g_list_free (private->filters); - private->filters = NULL; - } - - if (private->window_type == GDK_WINDOW_FOREIGN) - { - if (our_destroy && (private->parent != NULL)) - { - /* It's somebody elses window, but in our heirarchy, - * so reparent it to the root window, and then send - * it a delete event, as if we were a WM - */ - XClientMessageEvent xevent; - - gdk_window_hide (window); - gdk_window_reparent (window, NULL, 0, 0); - - xevent.type = ClientMessage; - xevent.window = private->xwindow; - xevent.message_type = gdk_wm_protocols; - xevent.format = 32; - xevent.data.l[0] = gdk_wm_delete_window; - xevent.data.l[1] = CurrentTime; - - XSendEvent (private->xdisplay, private->xwindow, - False, 0, (XEvent *)&xevent); - } - } - else if (xdestroy) - XDestroyWindow (private->xdisplay, private->xwindow); - - if (private->colormap) - gdk_colormap_unref (private->colormap); - - private->destroyed = TRUE; - } - break; - - case GDK_WINDOW_ROOT: - g_error ("attempted to destroy root window"); - break; - - case GDK_WINDOW_PIXMAP: - g_error ("called gdk_window_destroy on a pixmap (use gdk_pixmap_unref)"); - break; - } -} - -/* Like internal_destroy, but also destroys the reference created by - gdk_window_new. */ - -void -gdk_window_destroy (GdkWindow *window) -{ - gdk_window_internal_destroy (window, TRUE, TRUE); - gdk_window_unref (window); -} - -/* This function is called when the XWindow is really gone. */ - -void -gdk_window_destroy_notify (GdkWindow *window) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - - if (!private->destroyed) - { - if (private->window_type == GDK_WINDOW_FOREIGN) - gdk_window_internal_destroy (window, FALSE, FALSE); - else - g_warning ("GdkWindow %#lx unexpectedly destroyed", private->xwindow); - } - - gdk_xid_table_remove (private->xwindow); - gdk_window_unref (window); -} - -GdkWindow* -gdk_window_ref (GdkWindow *window) -{ - GdkWindowPrivate *private = (GdkWindowPrivate *)window; - g_return_val_if_fail (window != NULL, NULL); - - private->ref_count += 1; - return window; -} - -void -gdk_window_unref (GdkWindow *window) -{ - GdkWindowPrivate *private = (GdkWindowPrivate *)window; - g_return_if_fail (window != NULL); - - private->ref_count -= 1; - if (private->ref_count == 0) - { - if (!private->destroyed) - g_warning ("losing last reference to undestroyed window\n"); - g_free (window); - } -} - -void -gdk_window_show (GdkWindow *window) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - if (!private->destroyed) - { - XRaiseWindow (private->xdisplay, private->xwindow); - XMapWindow (private->xdisplay, private->xwindow); - } -} - -void -gdk_window_hide (GdkWindow *window) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - if (!private->destroyed) - XUnmapWindow (private->xdisplay, private->xwindow); -} - -void -gdk_window_withdraw (GdkWindow *window) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - if (!private->destroyed) - XWithdrawWindow (private->xdisplay, private->xwindow, 0); -} - -void -gdk_window_move (GdkWindow *window, - gint x, - gint y) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - if (!private->destroyed) - { - XMoveWindow (private->xdisplay, private->xwindow, x, y); - - if (private->window_type == GDK_WINDOW_CHILD) - { - private->x = x; - private->y = y; - } - } -} - -void -gdk_window_resize (GdkWindow *window, - gint width, - gint height) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - if (width < 1) - width = 1; - if (height < 1) - height = 1; - - private = (GdkWindowPrivate*) window; - - if (!private->destroyed && - ((private->resize_count > 0) || - (private->width != (guint16) width) || - (private->height != (guint16) height))) - { - XResizeWindow (private->xdisplay, private->xwindow, width, height); - private->resize_count += 1; - - if (private->window_type == GDK_WINDOW_CHILD) - { - private->width = width; - private->height = height; - } - } -} - -void -gdk_window_move_resize (GdkWindow *window, - gint x, - gint y, - gint width, - gint height) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - if (width < 1) - width = 1; - if (height < 1) - height = 1; - - private = (GdkWindowPrivate*) window; - if (!private->destroyed) - { - XMoveResizeWindow (private->xdisplay, private->xwindow, x, y, width, height); - - if (private->window_type == GDK_WINDOW_CHILD) - { - private->x = x; - private->y = y; - private->width = width; - private->height = height; - } - } -} - -void -gdk_window_reparent (GdkWindow *window, - GdkWindow *new_parent, - gint x, - gint y) -{ - GdkWindowPrivate *window_private; - GdkWindowPrivate *parent_private; - GdkWindowPrivate *old_parent_private; - - g_return_if_fail (window != NULL); - - if (!new_parent) - new_parent = (GdkWindow*) &gdk_root_parent; - - window_private = (GdkWindowPrivate*) window; - old_parent_private = (GdkWindowPrivate*)window_private->parent; - parent_private = (GdkWindowPrivate*) new_parent; - - if (!window_private->destroyed && !parent_private->destroyed) - XReparentWindow (window_private->xdisplay, - window_private->xwindow, - parent_private->xwindow, - x, y); - - old_parent_private->children = g_list_remove (old_parent_private->children, window); - parent_private->children = g_list_prepend (parent_private->children, window); - -} - -void -gdk_window_clear (GdkWindow *window) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - - if (!private->destroyed) - XClearWindow (private->xdisplay, private->xwindow); -} - -void -gdk_window_clear_area (GdkWindow *window, - gint x, - gint y, - gint width, - gint height) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - - if (!private->destroyed) - XClearArea (private->xdisplay, private->xwindow, - x, y, width, height, False); -} - -void -gdk_window_clear_area_e (GdkWindow *window, - gint x, - gint y, - gint width, - gint height) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - - if (!private->destroyed) - XClearArea (private->xdisplay, private->xwindow, - x, y, width, height, True); -} - -void -gdk_window_copy_area (GdkWindow *window, - GdkGC *gc, - gint x, - gint y, - GdkWindow *source_window, - gint source_x, - gint source_y, - gint width, - gint height) -{ - GdkWindowPrivate *src_private; - GdkWindowPrivate *dest_private; - GdkGCPrivate *gc_private; - - g_return_if_fail (window != NULL); - g_return_if_fail (gc != NULL); - - if (source_window == NULL) - source_window = window; - - src_private = (GdkWindowPrivate*) source_window; - dest_private = (GdkWindowPrivate*) window; - gc_private = (GdkGCPrivate*) gc; - - if (!src_private->destroyed && !dest_private->destroyed) - { - XCopyArea (dest_private->xdisplay, src_private->xwindow, dest_private->xwindow, - gc_private->xgc, - source_x, source_y, - width, height, - x, y); - } -} - -void -gdk_window_raise (GdkWindow *window) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - - if (!private->destroyed) - XRaiseWindow (private->xdisplay, private->xwindow); -} - -void -gdk_window_lower (GdkWindow *window) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - - if (!private->destroyed) - XLowerWindow (private->xdisplay, private->xwindow); -} - -void -gdk_window_set_user_data (GdkWindow *window, - gpointer user_data) -{ - g_return_if_fail (window != NULL); - - window->user_data = user_data; -} - -void -gdk_window_set_hints (GdkWindow *window, - gint x, - gint y, - gint min_width, - gint min_height, - gint max_width, - gint max_height, - gint flags) -{ - GdkWindowPrivate *private; - XSizeHints size_hints; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - if (private->destroyed) - return; - - size_hints.flags = 0; - - if (flags & GDK_HINT_POS) - { - size_hints.flags |= PPosition; - size_hints.x = x; - size_hints.y = y; - } - - if (flags & GDK_HINT_MIN_SIZE) - { - size_hints.flags |= PMinSize; - size_hints.min_width = min_width; - size_hints.min_height = min_height; - } - - if (flags & GDK_HINT_MAX_SIZE) - { - size_hints.flags |= PMaxSize; - size_hints.max_width = max_width; - size_hints.max_height = max_height; - } - - if (flags) - XSetWMNormalHints (private->xdisplay, private->xwindow, &size_hints); -} - -void -gdk_window_set_title (GdkWindow *window, - const gchar *title) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - if (!private->destroyed) - XmbSetWMProperties (private->xdisplay, private->xwindow, - title, title, NULL, 0, NULL, NULL, NULL); -} - -void -gdk_window_set_background (GdkWindow *window, - GdkColor *color) -{ - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - if (!private->destroyed) - XSetWindowBackground (private->xdisplay, private->xwindow, color->pixel); -} - -void -gdk_window_set_back_pixmap (GdkWindow *window, - GdkPixmap *pixmap, - gint parent_relative) -{ - GdkWindowPrivate *window_private; - GdkPixmapPrivate *pixmap_private; - Pixmap xpixmap; - - g_return_if_fail (window != NULL); - - window_private = (GdkWindowPrivate*) window; - pixmap_private = (GdkPixmapPrivate*) pixmap; - - if (pixmap) - xpixmap = pixmap_private->xwindow; - else - xpixmap = None; - - if (parent_relative) - xpixmap = ParentRelative; - - if (!window_private->destroyed) - XSetWindowBackgroundPixmap (window_private->xdisplay, window_private->xwindow, xpixmap); -} - -void -gdk_window_set_cursor (GdkWindow *window, - GdkCursor *cursor) -{ - GdkWindowPrivate *window_private; - GdkCursorPrivate *cursor_private; - Cursor xcursor; - - g_return_if_fail (window != NULL); - - window_private = (GdkWindowPrivate*) window; - cursor_private = (GdkCursorPrivate*) cursor; - - if (!cursor) - xcursor = None; - else - xcursor = cursor_private->xcursor; - - if (!window_private->destroyed) - XDefineCursor (window_private->xdisplay, window_private->xwindow, xcursor); -} - -void -gdk_window_set_colormap (GdkWindow *window, - GdkColormap *colormap) -{ - GdkWindowPrivate *window_private; - GdkColormapPrivate *colormap_private; - - g_return_if_fail (window != NULL); - g_return_if_fail (colormap != NULL); - - window_private = (GdkWindowPrivate*) window; - colormap_private = (GdkColormapPrivate*) colormap; - - if (!window_private->destroyed) - { - XSetWindowColormap (window_private->xdisplay, - window_private->xwindow, - colormap_private->xcolormap); - - if (window_private->colormap) - gdk_colormap_unref (window_private->colormap); - window_private->colormap = colormap; - gdk_colormap_ref (window_private->colormap); - - if (window_private->window_type != GDK_WINDOW_TOPLEVEL) - gdk_window_add_colormap_windows (window); - } -} - -void -gdk_window_get_user_data (GdkWindow *window, - gpointer *data) -{ - g_return_if_fail (window != NULL); - - *data = window->user_data; -} - -void -gdk_window_get_geometry (GdkWindow *window, - gint *x, - gint *y, - gint *width, - gint *height, - gint *depth) -{ - GdkWindowPrivate *window_private; - Window root; - gint tx; - gint ty; - guint twidth; - guint theight; - guint tborder_width; - guint tdepth; - - if (!window) - window = (GdkWindow*) &gdk_root_parent; - - window_private = (GdkWindowPrivate*) window; - - if (!window_private->destroyed) - { - XGetGeometry (window_private->xdisplay, window_private->xwindow, - &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth); - - if (x) - *x = tx; - if (y) - *y = ty; - if (width) - *width = twidth; - if (height) - *height = theight; - if (depth) - *depth = tdepth; - } -} - -void -gdk_window_get_position (GdkWindow *window, - gint *x, - gint *y) -{ - GdkWindowPrivate *window_private; - - g_return_if_fail (window != NULL); - - window_private = (GdkWindowPrivate*) window; - - if (x) - *x = window_private->x; - if (y) - *y = window_private->y; -} - -void -gdk_window_get_size (GdkWindow *window, - gint *width, - gint *height) -{ - GdkWindowPrivate *window_private; - - g_return_if_fail (window != NULL); - - window_private = (GdkWindowPrivate*) window; - - if (width) - *width = window_private->width; - if (height) - *height = window_private->height; -} - -GdkVisual* -gdk_window_get_visual (GdkWindow *window) -{ - GdkWindowPrivate *window_private; - XWindowAttributes window_attributes; - - g_return_val_if_fail (window != NULL, NULL); - - window_private = (GdkWindowPrivate*) window; - /* Huh? ->parent is never set for a pixmap. We should just return - * null immeditately - */ - while (window_private && (window_private->window_type == GDK_WINDOW_PIXMAP)) - window_private = (GdkWindowPrivate*) window_private->parent; - - if (window_private && !window_private->destroyed) - { - if (window_private->colormap == NULL) - { - XGetWindowAttributes (window_private->xdisplay, - window_private->xwindow, - &window_attributes); - return gdk_visual_lookup (window_attributes.visual); - } - else - return ((GdkColormapPrivate *)window_private->colormap)->visual; - } - - return NULL; -} - -GdkColormap* -gdk_window_get_colormap (GdkWindow *window) -{ - GdkWindowPrivate *window_private; - XWindowAttributes window_attributes; - - g_return_val_if_fail (window != NULL, NULL); - window_private = (GdkWindowPrivate*) window; - - g_return_val_if_fail (window_private->window_type != GDK_WINDOW_PIXMAP, NULL); - if (!window_private->destroyed) - { - if (window_private->colormap == NULL) - { - XGetWindowAttributes (window_private->xdisplay, - window_private->xwindow, - &window_attributes); - return gdk_colormap_lookup (window_attributes.colormap); - } - else - return window_private->colormap; - } - - return NULL; -} - -GdkWindowType -gdk_window_get_type (GdkWindow *window) -{ - GdkWindowPrivate *window_private; - - g_return_val_if_fail (window != NULL, (GdkWindowType) -1); - - window_private = (GdkWindowPrivate*) window; - return window_private->window_type; -} - -gint -gdk_window_get_origin (GdkWindow *window, - gint *x, - gint *y) -{ - GdkWindowPrivate *private; - gint return_val; - Window child; - gint tx, ty; - - g_return_val_if_fail (window != NULL, 0); - - private = (GdkWindowPrivate*) window; - - if (!private->destroyed) - { - return_val = XTranslateCoordinates (private->xdisplay, - private->xwindow, - gdk_root_window, - 0, 0, &tx, &ty, - &child); - - if (x) - *x = tx; - if (y) - *y = ty; - } - else - return_val = 0; - - return return_val; -} - -GdkWindow* -gdk_window_get_pointer (GdkWindow *window, - gint *x, - gint *y, - GdkModifierType *mask) -{ - GdkWindowPrivate *private; - GdkWindow *return_val; - Window root; - Window child; - int rootx, rooty; - int winx, winy; - unsigned int xmask; - - if (!window) - window = (GdkWindow*) &gdk_root_parent; - - private = (GdkWindowPrivate*) window; - - return_val = NULL; - if (!private->destroyed && - XQueryPointer (private->xdisplay, private->xwindow, &root, &child, - &rootx, &rooty, &winx, &winy, &xmask)) - { - if (x) *x = winx; - if (y) *y = winy; - if (mask) *mask = xmask; - - if (child) - return_val = gdk_window_lookup (child); - } - - return return_val; -} - -GdkWindow* -gdk_window_get_parent (GdkWindow *window) -{ - g_return_val_if_fail (window != NULL, NULL); - - return ((GdkWindowPrivate*) window)->parent; -} - -GdkWindow* -gdk_window_get_toplevel (GdkWindow *window) -{ - GdkWindowPrivate *private; - - g_return_val_if_fail (window != NULL, NULL); - - private = (GdkWindowPrivate*) window; - - while (private->window_type == GDK_WINDOW_CHILD) - { - window = ((GdkWindowPrivate*) window)->parent; - private = (GdkWindowPrivate*) window; - } - - return window; -} - -GList* -gdk_window_get_children (GdkWindow *window) -{ - GdkWindowPrivate *private; - GdkWindow *child; - GList *children; - Window root; - Window parent; - Window *xchildren; - unsigned int nchildren; - unsigned int i; - - g_return_val_if_fail (window != NULL, NULL); - - private = (GdkWindowPrivate*) window; - if (private->destroyed) - return NULL; - - XQueryTree (private->xdisplay, private->xwindow, - &root, &parent, &xchildren, &nchildren); - - children = NULL; - - if (nchildren > 0) - { - for (i = 0; i < nchildren; i++) - { - child = gdk_window_lookup (xchildren[i]); - if (child) - children = g_list_prepend (children, child); - } - - XFree (xchildren); - } - - return children; -} - -GdkEventMask -gdk_window_get_events (GdkWindow *window) -{ - GdkWindowPrivate *private; - XWindowAttributes attrs; - GdkEventMask event_mask; - int i; - - g_return_val_if_fail (window != NULL, 0); - - private = (GdkWindowPrivate*) window; - if (private->destroyed) - return 0; - - XGetWindowAttributes (gdk_display, private->xwindow, - &attrs); - - event_mask = 0; - for (i = 0; i < nevent_masks; i++) - { - if (attrs.your_event_mask & event_mask_table[i]) - event_mask |= 1 << (i + 1); - } - - return event_mask; -} - -void -gdk_window_set_events (GdkWindow *window, - GdkEventMask event_mask) -{ - GdkWindowPrivate *private; - long xevent_mask; - int i; - - g_return_if_fail (window != NULL); - - private = (GdkWindowPrivate*) window; - if (private->destroyed) - return; - - xevent_mask = StructureNotifyMask; - for (i = 0; i < nevent_masks; i++) - { - if (event_mask & (1 << (i + 1))) - xevent_mask |= event_mask_table[i]; - } - - XSelectInput (gdk_display, private->xwindow, - xevent_mask); -} - -void -gdk_window_add_colormap_windows (GdkWindow *window) -{ - GdkWindow *toplevel; - GdkWindowPrivate *toplevel_private; - GdkWindowPrivate *window_private; - Window *old_windows; - Window *new_windows; - int i, count; - - g_return_if_fail (window != NULL); - - toplevel = gdk_window_get_toplevel (window); - toplevel_private = (GdkWindowPrivate*) toplevel; - window_private = (GdkWindowPrivate*) window; - if (window_private->destroyed) - return; - - if (!XGetWMColormapWindows (toplevel_private->xdisplay, - toplevel_private->xwindow, - &old_windows, &count)) - { - old_windows = NULL; - count = 0; - } - - for (i = 0; i < count; i++) - if (old_windows[i] == window_private->xwindow) - return; - - new_windows = g_new (Window, count + 1); - - for (i = 0; i < count; i++) - new_windows[i] = old_windows[i]; - new_windows[count] = window_private->xwindow; - - XSetWMColormapWindows (toplevel_private->xdisplay, - toplevel_private->xwindow, - new_windows, count + 1); - - g_free (new_windows); - if (old_windows) - XFree (old_windows); -} - -/* - * This needs the X11 shape extension. - * If not available, shaped windows will look - * ugly, but programs still work. Stefan Wille - */ -void -gdk_window_shape_combine_mask (GdkWindow *window, - GdkBitmap *mask, - gint x, gint y) -{ - enum { UNKNOWN, NO, YES }; - - static gint have_shape = UNKNOWN; - - GdkWindowPrivate *window_private; - Pixmap pixmap; - - g_return_if_fail (window != NULL); - -#ifdef HAVE_SHAPE_EXT - if (have_shape == UNKNOWN) - { - int ignore; - if (XQueryExtension(gdk_display, "SHAPE", &ignore, &ignore, &ignore)) - have_shape = YES; - else - have_shape = NO; - } - - if (have_shape == YES) - { - window_private = (GdkWindowPrivate*) window; - if (window_private->destroyed) - return; - - if (mask) - { - GdkWindowPrivate *pixmap_private; - - pixmap_private = (GdkWindowPrivate*) mask; - pixmap = (Pixmap) pixmap_private->xwindow; - } - else - { - x = 0; - y = 0; - pixmap = None; - } - - XShapeCombineMask (window_private->xdisplay, - window_private->xwindow, - ShapeBounding, - x, y, - pixmap, - ShapeSet); - } -#endif /* HAVE_SHAPE_EXT */ -} - -void -gdk_dnd_drag_addwindow (GdkWindow *window) -{ - GdkWindowPrivate *window_private; - - g_return_if_fail (window != NULL); - - window_private = (GdkWindowPrivate *) window; - if (window_private->destroyed) - return; - - if (window_private->dnd_drag_enabled == 1 && gdk_dnd.drag_really == 0) - { - gdk_dnd.drag_numwindows++; - gdk_dnd.drag_startwindows = g_realloc (gdk_dnd.drag_startwindows, - gdk_dnd.drag_numwindows - * sizeof(GdkWindow *)); - gdk_dnd.drag_startwindows[gdk_dnd.drag_numwindows - 1] = window; - window_private->dnd_drag_accepted = 0; - } - else - g_warning ("dnd_really is 1 or drag is not enabled! can't addwindow\n"); -} - -void -gdk_window_dnd_drag_set (GdkWindow *window, - guint8 drag_enable, - gchar **typelist, - guint numtypes) -{ - GdkWindowPrivate *window_private; - int i, wasset = 0; - - g_return_if_fail (window != NULL); - window_private = (GdkWindowPrivate *) window; - if (window_private->destroyed) - return; - - window_private->dnd_drag_enabled = drag_enable ? 1 : 0; - - if (drag_enable) - { - g_return_if_fail(typelist != NULL); - - if (window_private->dnd_drag_data_numtypesavail > 3) - wasset = 1; - window_private->dnd_drag_data_numtypesavail = numtypes; - - window_private->dnd_drag_data_typesavail = - g_realloc (window_private->dnd_drag_data_typesavail, - (numtypes + 1) * sizeof (GdkAtom)); - - for (i = 0; i < numtypes; i++) - { - /* Allow blanket use of ALL to get anything... */ - if (strcmp (typelist[i], "ALL")) - window_private->dnd_drag_data_typesavail[i] = - gdk_atom_intern (typelist[i], FALSE); - else - window_private->dnd_drag_data_typesavail[i] = None; - } - - /* - * set our extended type list if we need to - */ - if (numtypes > 3) - gdk_property_change(window, gdk_dnd.gdk_XdeTypelist, - XA_PRIMARY, 32, GDK_PROP_MODE_REPLACE, - (guchar *)(window_private->dnd_drag_data_typesavail - + (sizeof(GdkAtom) * 3)), - (numtypes - 3) * sizeof(GdkAtom)); - else if (wasset) - gdk_property_delete (window, gdk_dnd.gdk_XdeTypelist); - } - else - { - g_free (window_private->dnd_drag_data_typesavail); - window_private->dnd_drag_data_typesavail = NULL; - window_private->dnd_drag_data_numtypesavail = 0; - } -} - -void -gdk_window_dnd_drop_set (GdkWindow *window, - guint8 drop_enable, - gchar **typelist, - guint numtypes, - guint8 destructive_op) -{ - GdkWindowPrivate *window_private; - int i; - - g_return_if_fail (window != NULL); - window_private = (GdkWindowPrivate *) window; - if (window_private->destroyed) - return; - - window_private->dnd_drop_enabled = drop_enable ? 1 : 0; - if (drop_enable) - { - g_return_if_fail(typelist != NULL); - - window_private->dnd_drop_data_numtypesavail = numtypes; - - window_private->dnd_drop_data_typesavail = - g_realloc (window_private->dnd_drop_data_typesavail, - (numtypes + 1) * sizeof (GdkAtom)); - - for (i = 0; i < numtypes; i++) - window_private->dnd_drop_data_typesavail[i] = - gdk_atom_intern (typelist[i], FALSE); - - window_private->dnd_drop_destructive_op = destructive_op; - } -} - -/* - * This is used to reply to a GDK_DRAG_REQUEST event - * (which may be generated by XdeRequest or a confirmed drop... - */ -void -gdk_window_dnd_data_set (GdkWindow *window, - GdkEvent *event, - gpointer data, - gulong data_numbytes) -{ - GdkWindowPrivate *window_private; - XEvent sev; - GdkEventDropDataAvailable tmp_ev; - gchar *tmp; - - g_return_if_fail (window != NULL); - g_return_if_fail (event != NULL); - g_return_if_fail (data != NULL); - g_return_if_fail (data_numbytes > 0); - g_return_if_fail (event->type == GDK_DRAG_REQUEST); - - window_private = (GdkWindowPrivate *) window; - g_return_if_fail (window_private->dnd_drag_accepted != 0); - if (window_private->destroyed) - return; - - /* We set the property on our window... */ - gdk_property_change (window, window_private->dnd_drag_data_type, - XA_PRIMARY, 8, GDK_PROP_MODE_REPLACE, data, - data_numbytes); - tmp = gdk_atom_name(window_private->dnd_drag_data_type); -#ifdef DEBUG_DND - g_print("DnD type %s on window %ld\n", tmp, window_private->xwindow); -#endif - g_free(tmp); - - /* - * Then we send the event to tell the receiving window that the - * drop has happened - */ - tmp_ev.u.allflags = 0; - tmp_ev.u.flags.protocol_version = DND_PROTOCOL_VERSION; - tmp_ev.u.flags.isdrop = event->dragrequest.isdrop; - - sev.xclient.type = ClientMessage; - sev.xclient.format = 32; - sev.xclient.window = event->dragrequest.requestor; - sev.xclient.message_type = gdk_dnd.gdk_XdeDataAvailable; - sev.xclient.data.l[0] = window_private->xwindow; - sev.xclient.data.l[1] = tmp_ev.u.allflags; - sev.xclient.data.l[2] = window_private->dnd_drag_data_type; - - if (event->dragrequest.isdrop) - sev.xclient.data.l[3] = event->dragrequest.drop_coords.x + - (event->dragrequest.drop_coords.y << 16); - else - sev.xclient.data.l[3] = 0; - - sev.xclient.data.l[4] = event->dragrequest.timestamp; - - if (!gdk_send_xevent (event->dragrequest.requestor, False, - StructureNotifyMask, &sev)) - GDK_NOTE (DND, g_print("Sending XdeDataAvailable to %#x failed\n", - event->dragrequest.requestor)); - -} - -void -gdk_window_add_filter (GdkWindow *window, - GdkFilterFunc function, - gpointer data) -{ - GdkWindowPrivate *private; - GList *tmp_list; - GdkEventFilter *filter; - - private = (GdkWindowPrivate*) window; - if (private && private->destroyed) - return; - - if(private) - tmp_list = private->filters; - else - tmp_list = gdk_default_filters; - - while (tmp_list) - { - filter = (GdkEventFilter *)tmp_list->data; - if ((filter->function == function) && (filter->data == data)) - return; - tmp_list = tmp_list->next; - } - - filter = g_new (GdkEventFilter, 1); - filter->function = function; - filter->data = data; - - if(private) - private->filters = g_list_append (private->filters, filter); - else - gdk_default_filters = g_list_append (gdk_default_filters, filter); -} - -void -gdk_window_remove_filter (GdkWindow *window, - GdkFilterFunc function, - gpointer data) -{ - GdkWindowPrivate *private; - GList *tmp_list; - GdkEventFilter *filter; - - private = (GdkWindowPrivate*) window; - - if(private) - tmp_list = private->filters; - else - tmp_list = gdk_default_filters; - - while (tmp_list) - { - filter = (GdkEventFilter *)tmp_list->data; - tmp_list = tmp_list->next; - - if ((filter->function == function) && (filter->data == data)) - { - if(private) - private->filters = g_list_remove_link (private->filters, tmp_list); - else - gdk_default_filters = g_list_remove_link (gdk_default_filters, tmp_list); - g_list_free_1 (tmp_list); - g_free (filter); - - return; - } - } -} - -void -gdk_window_set_override_redirect(GdkWindow *window, - gboolean override_redirect) -{ - GdkWindowPrivate *private; - XSetWindowAttributes attr; - - g_return_if_fail (window != NULL); - private = (GdkWindowPrivate*) window; - if (private->destroyed) - return; - - attr.override_redirect = (override_redirect == FALSE)?False:True; - XChangeWindowAttributes(gdk_display, - ((GdkWindowPrivate *)window)->xwindow, - CWOverrideRedirect, - &attr); -} - -void -gdk_window_set_icon (GdkWindow *window, - GdkWindow *icon_window, - GdkPixmap *pixmap, - GdkBitmap *mask) -{ - XWMHints wm_hints; - GdkWindowPrivate *window_private; - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - window_private = (GdkWindowPrivate*) window; - if (window_private->destroyed) - return; - - wm_hints.flags = 0; - - if (icon_window != NULL) - { - private = (GdkWindowPrivate *)icon_window; - wm_hints.flags |= IconWindowHint; - wm_hints.icon_window = private->xwindow; - } - - if (pixmap != NULL) - { - private = (GdkWindowPrivate *)pixmap; - wm_hints.flags |= IconPixmapHint; - wm_hints.icon_pixmap = private->xwindow; - } - - if (mask != NULL) - { - private = (GdkWindowPrivate *)mask; - wm_hints.flags |= IconMaskHint; - wm_hints.icon_mask = private->xwindow; - } - - XSetWMHints (window_private->xdisplay, window_private->xwindow, &wm_hints); -} - -void -gdk_window_set_icon_name (GdkWindow *window, - gchar * name) -{ - GdkWindowPrivate *window_private; - XTextProperty property; - gint res; - - g_return_if_fail (window != NULL); - window_private = (GdkWindowPrivate*) window; - if (window_private->destroyed) - return; - res = XmbTextListToTextProperty (window_private->xdisplay, - &name, 1, XStdICCTextStyle, - &property); - if (res < 0) - { - g_warning("Error converting icon name to text property: %d\n", res); - return; - } - - XSetWMIconName (window_private->xdisplay, window_private->xwindow, - &property); - - XFree(property.value); -} - -void -gdk_window_set_group (GdkWindow *window, - GdkWindow *leader) -{ - XWMHints wm_hints; - GdkWindowPrivate *window_private; - GdkWindowPrivate *private; - - g_return_if_fail (window != NULL); - g_return_if_fail (leader != NULL); - window_private = (GdkWindowPrivate*) window; - if (window_private->destroyed) - return; - - private = (GdkWindowPrivate *)leader; - wm_hints.flags = WindowGroupHint; - wm_hints.window_group = private->xwindow; - - XSetWMHints (window_private->xdisplay, window_private->xwindow, &wm_hints); -} - -static void -gdk_window_set_mwm_hints (GdkWindow *window, - MotifWmHints *new_hints) -{ - static Atom hints_atom = None; - MotifWmHints *hints; - Atom type; - gint format; - gulong nitems; - gulong bytes_after; - - GdkWindowPrivate *window_private; - - g_return_if_fail (window != NULL); - window_private = (GdkWindowPrivate*) window; - if (window_private->destroyed) - return; - - if (!hints_atom) - hints_atom = XInternAtom (window_private->xdisplay, - _XA_MOTIF_WM_HINTS, FALSE); - - XGetWindowProperty (window_private->xdisplay, window_private->xwindow, - hints_atom, 0, sizeof(MotifWmHints)/4, - False, AnyPropertyType, &type, &format, &nitems, - &bytes_after, (guchar **)&hints); - - if (type == None) - hints = new_hints; - else - { - if (new_hints->flags & MWM_HINTS_FUNCTIONS) - { - hints->flags |= MWM_HINTS_FUNCTIONS; - hints->functions = new_hints->functions; - } - if (new_hints->flags & MWM_HINTS_DECORATIONS) - { - hints->flags |= MWM_HINTS_DECORATIONS; - hints->decorations = new_hints->decorations; - } - } - - XChangeProperty (window_private->xdisplay, window_private->xwindow, - hints_atom, hints_atom, 32, PropModeReplace, - (guchar *)hints, sizeof(MotifWmHints)/4); - - if (hints != new_hints) - XFree (hints); -} - -void -gdk_window_set_decorations (GdkWindow *window, - GdkWMDecoration decorations) -{ - MotifWmHints hints; - - hints.flags = MWM_HINTS_DECORATIONS; - hints.decorations = decorations; - - gdk_window_set_mwm_hints (window, &hints); -} - -void -gdk_window_set_functions (GdkWindow *window, - GdkWMFunction functions) -{ - MotifWmHints hints; - - hints.flags = MWM_HINTS_FUNCTIONS; - hints.functions = functions; - - gdk_window_set_mwm_hints (window, &hints); -} diff --git a/gdk/x11/gdkx.h b/gdk/x11/gdkx.h deleted file mode 100644 index 2f43fd85fe..0000000000 --- a/gdk/x11/gdkx.h +++ /dev/null @@ -1,49 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __GDK_X_H__ -#define __GDK_X_H__ - -#include <gdk/gdkprivate.h> - - -#define GDK_ROOT_WINDOW() gdk_root_window -#define GDK_ROOT_PARENT() ((GdkWindow *)&gdk_root_parent) -#define GDK_DISPLAY() gdk_display -#define GDK_WINDOW_XDISPLAY(win) (((GdkWindowPrivate*) win)->xdisplay) -#define GDK_WINDOW_XWINDOW(win) (((GdkWindowPrivate*) win)->xwindow) -#define GDK_IMAGE_XDISPLAY(image) (((GdkImagePrivate*) image)->xdisplay) -#define GDK_IMAGE_XIMAGE(image) (((GdkImagePrivate*) image)->ximage) -#define GDK_GC_XDISPLAY(gc) (((GdkGCPrivate*) gc)->xdisplay) -#define GDK_GC_XGC(gc) (((GdkGCPrivate*) gc)->xgc) -#define GDK_COLORMAP_XDISPLAY(cmap) (((GdkColormapPrivate*) cmap)->xdisplay) -#define GDK_COLORMAP_XCOLORMAP(cmap) (((GdkColormapPrivate*) cmap)->xcolormap) -#define GDK_VISUAL_XVISUAL(vis) (((GdkVisualPrivate*) vis)->xvisual) -#define GDK_FONT_XDISPLAY(font) (((GdkFontPrivate*) font)->xdisplay) -#define GDK_FONT_XFONT(font) (((GdkFontPrivate*) font)->xfont) - - -GdkVisual* gdkx_visual_get (VisualID xvisualid); -GdkColormap* gdkx_colormap_get (Colormap xcolormap); -/* Utility function in gdk.c - not sure where it belongs, but it's - needed in more than one place, so make it public */ -Window gdk_get_client_window (Display *dpy, - Window win); - - -#endif /* __GDK_X_H__ */ diff --git a/gdk/x11/gdkxid.c b/gdk/x11/gdkxid.c deleted file mode 100644 index 6a538ba520..0000000000 --- a/gdk/x11/gdkxid.c +++ /dev/null @@ -1,75 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#include "gdkprivate.h" -#include <stdio.h> - -static guint gdk_xid_hash (XID *xid); -static gint gdk_xid_compare (XID *a, - XID *b); - - -GHashTable *xid_ht = NULL; - - -void -gdk_xid_table_insert (XID *xid, - gpointer data) -{ - g_return_if_fail (xid != NULL); - - if (!xid_ht) - xid_ht = g_hash_table_new ((GHashFunc) gdk_xid_hash, - (GCompareFunc) gdk_xid_compare); - - g_hash_table_insert (xid_ht, xid, data); -} - -void -gdk_xid_table_remove (XID xid) -{ - if (!xid_ht) - xid_ht = g_hash_table_new ((GHashFunc) gdk_xid_hash, - (GCompareFunc) gdk_xid_compare); - - g_hash_table_remove (xid_ht, &xid); -} - -gpointer -gdk_xid_table_lookup (XID xid) -{ - gpointer data; - - data = g_hash_table_lookup (xid_ht, &xid); - - return data; -} - - -static guint -gdk_xid_hash (XID *xid) -{ - return *xid; -} - -static gint -gdk_xid_compare (XID *a, - XID *b) -{ - return (*a == *b); -} diff --git a/gdk/x11/gxid.c b/gdk/x11/gxid.c deleted file mode 100644 index 40b48fa31c..0000000000 --- a/gdk/x11/gxid.c +++ /dev/null @@ -1,863 +0,0 @@ -/* - * gxid version 0.3 - * - * Copyright 1997 Owen Taylor <owt1@cornell.edu> -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <signal.h> -#include <sys/time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <X11/Xlib.h> -#include <X11/extensions/XInput.h> - -#include "gxid_proto.h" - -/* #define DEBUG_CLIENTS */ -/* #define DEBUG_EVENTS */ - -char *program_name; -Display *dpy; -Window root_window; /* default root window of dpy */ -int port = 0; /* port to listen on */ -int socket_fd = 0; /* file descriptor of socket */ -typedef struct GxidWindow_ GxidWindow; - -typedef struct GxidDevice_ GxidDevice; -struct GxidDevice_ { - XID id; - int exclusive; - int ispointer; - - XDevice *xdevice; - int motionnotify_type; - int changenotify_type; -}; - -struct GxidWindow_ { - Window xwindow; - /* Immediate child of root that is ancestor of window */ - Window root_child; - int num_devices; - GxidDevice **devices; -}; - -GxidDevice **devices = NULL; -int num_devices = 0; -GxidWindow **windows = NULL; -int num_windows = 0; - -void -handler(int signal) -{ - fprintf(stderr,"%s: dying on signal %d\n",program_name,signal); - if (socket_fd) - close(socket_fd); - exit(1); -} - -void -init_socket(void) -{ - struct sockaddr_in sin; - - socket_fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); - if (socket_fd < 0) - { - fprintf (stderr, "%s: error getting socket\n", - program_name); - exit(1); - } - - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - sin.sin_addr.s_addr = INADDR_ANY; - - if (bind(socket_fd,(struct sockaddr *)(&sin), - sizeof(struct sockaddr_in)) < 0) - { - fprintf (stderr,"%s: cannot bind to port %d\n", - program_name,port); - exit(1); - } - - if (listen(socket_fd,5) < 0) - { - fprintf (stderr,"%s: error listening on socket\n", - program_name); - exit(1); - }; -} - -#define NUM_EVENTC 2 -static void -enable_device(GxidDevice *dev) -{ - XEventClass xevc[NUM_EVENTC]; - int num_eventc = NUM_EVENTC; - int i,j; - - if (!dev->xdevice) - { - if (dev->ispointer) return; - - dev->xdevice = XOpenDevice(dpy, dev->id); - if (!dev->xdevice) return; - - DeviceMotionNotify (dev->xdevice, dev->motionnotify_type, - xevc[0]); - ChangeDeviceNotify (dev->xdevice, dev->changenotify_type, - xevc[1]); - - /* compress out zero event classes */ - for (i=0,j=0;i<NUM_EVENTC;i++) - { - if (xevc[i]) { - xevc[j] = xevc[i]; - j++; - } - } - num_eventc = j; - - XSelectExtensionEvent (dpy, root_window, xevc, num_eventc); - } -} - -/* switch the core pointer from whatever it is now to something else, - return true on success, false otherwise */ -static int -switch_core_pointer(void) -{ - GxidDevice *old_pointer = 0; - GxidDevice *new_pointer = 0; - int result; - int i; - - for (i=0;i<num_devices;i++) - { - if (devices[i]->ispointer) - old_pointer = devices[i]; - else - if (!new_pointer && !devices[i]->exclusive) - new_pointer = devices[i]; - } - - if (!old_pointer || !new_pointer) - return 0; - -#ifdef DEBUG_EVENTS - fprintf(stderr,"gxid: Switching core from %ld to %ld\n", - old_pointer->id,new_pointer->id); -#endif - result = XChangePointerDevice(dpy,new_pointer->xdevice, 0, 1); - if (result != Success) - { - fprintf(stderr,"gxid: Error %d switching core from %ld to %ld\n", - result, old_pointer->id, new_pointer->id); - } - else - { - new_pointer->ispointer = 1; - old_pointer->ispointer = 0; - if (!old_pointer->xdevice) - enable_device(old_pointer); - } - - return 1; -} - -void -disable_device(GxidDevice *dev) -{ - if (dev->xdevice) - { - if (dev->ispointer) - return; - XCloseDevice(dpy,dev->xdevice); - dev->xdevice = 0; - } -} - -GxidDevice * -init_device(XDeviceInfo *xdevice) -{ - GxidDevice *dev = (GxidDevice *)malloc(sizeof(GxidDevice)); - XAnyClassPtr class; - int num_axes, i; - - dev->id = xdevice->id; - dev->exclusive = 0; - dev->xdevice = NULL; - - dev->ispointer = (xdevice->use == IsXPointer); - - /* step through the classes */ - - num_axes = 0; - class = xdevice->inputclassinfo; - for (i=0;i<xdevice->num_classes;i++) - { - if (class->class == ValuatorClass) - { - XValuatorInfo *xvi = (XValuatorInfo *)class; - num_axes = xvi->num_axes; - } - class = (XAnyClassPtr)(((char *)class) + class->length); - } - - /* return NULL if insufficient axes */ - if (num_axes < 2) - { - free((void *)dev); - return NULL; - } - - if (!dev->ispointer) - enable_device(dev); - return dev; -} - -void -init_xinput(void) -{ - char **extensions; - XDeviceInfo *xdevices; - int num_xdevices; - int num_extensions; - int i; - - extensions = XListExtensions(dpy, &num_extensions); - for (i = 0; i < num_extensions && - (strcmp(extensions[i], "XInputExtension") != 0); i++); - XFreeExtensionList(extensions); - if (i == num_extensions) /* XInput extension not found */ - { - fprintf(stderr,"XInput extension not found\n"); - exit(1); - } - - xdevices = XListInputDevices(dpy, &num_xdevices); - devices = (GxidDevice **)malloc(num_xdevices * sizeof(GxidDevice *)); - - num_devices = 0; - for(i=0; i<num_xdevices; i++) - { - GxidDevice *dev = init_device(&xdevices[i]); - if (dev) - devices[num_devices++] = dev; - } - XFreeDeviceList(xdevices); -} - -/* If this routine needs fixing, the corresponding routine - in gdkinputgxi.h will need it too. */ - -Window -gxi_find_root_child(Display *dpy, Window w) -{ - Window root,parent; - Window *children; - int nchildren; - - parent = w; - do - { - w = parent; - XQueryTree(dpy,w,&root,&parent,&children,&nchildren); - if (children) XFree(children); - } - while (parent != root); - - return w; -} - -int -handle_claim_device(GxidClaimDevice *msg) -{ - int i,j; - XID devid; - XID winid; - int exclusive; - GxidDevice *device = NULL; - GxidWindow *window = NULL; - - if (msg->length != sizeof(GxidClaimDevice)) - { - fprintf(stderr,"Bad length for ClaimDevice message\n"); - return GXID_RETURN_ERROR; - } - - devid = ntohl(msg->device); - winid = ntohl(msg->window); - exclusive = ntohl(msg->exclusive); - -#ifdef DEBUG_CLIENTS - fprintf(stderr,"device %ld claimed (window 0x%lx)\n",devid,winid); -#endif - - for (i=0;i<num_devices;i++) - { - if (devices[i]->id == devid) - { - device = devices[i]; - break; - } - } - if (!device) - { - fprintf(stderr,"%s: Unknown device id %ld\n",program_name,devid); - return GXID_RETURN_ERROR; - } - - if (device->exclusive) - { - /* already in use */ - fprintf(stderr, - "%s: Device %ld already claimed in exclusive mode\n", - program_name,devid); - return GXID_RETURN_ERROR; - } - - if (exclusive) - { - for (i=0;i<num_windows;i++) - { - for (j=0;j<windows[i]->num_devices;j++) - if (windows[i]->devices[j]->id == devid) - { - /* already in use */ - fprintf(stderr, - "%s: Can't establish exclusive use of device %ld\n", - program_name,devid); - return GXID_RETURN_ERROR; - } - } - if (device->ispointer) - if (!switch_core_pointer()) - { - fprintf(stderr, - "%s: Can't free up core pointer %ld\n", - program_name,devid); - return GXID_RETURN_ERROR; - } - - device->exclusive = 1; - disable_device(device); - XSelectInput(dpy,winid,StructureNotifyMask); - } - else /* !exclusive */ - { - /* FIXME: this is a bit improper. We probably should do this only - when a window is first claimed. But we might be fooled if - an old client died without releasing it's windows. So until - we look for client-window closings, do it here - - (We do look for closings now...) - */ - - XSelectInput(dpy,winid,EnterWindowMask|StructureNotifyMask); - } - - for (i=0;i<num_windows;i++) - { - if (windows[i]->xwindow == winid) - { - window = windows[i]; - break; - } - } - - /* Create window structure if no devices have been previously - claimed on it */ - if (!window) - { - num_windows++; - windows = (GxidWindow **)realloc(windows, - sizeof(GxidWindow*)*num_windows); - window = (GxidWindow *)malloc(sizeof(GxidWindow)); - windows[num_windows-1] = window; - - window->xwindow = winid; - window->root_child = gxi_find_root_child(dpy,winid); - window->num_devices = 0; - window->devices = 0; - } - - - for (i=0;i<window->num_devices;i++) - { - if (window->devices[i] == device) - return GXID_RETURN_OK; - } - - window->num_devices++; - window->devices = (GxidDevice **)realloc(window->devices, - sizeof(GxidDevice*)*num_devices); - /* we need add the device to the window */ - window->devices[i] = device; - - return GXID_RETURN_OK; -} - -int -handle_release_device(GxidReleaseDevice *msg) -{ - int i,j; - XID devid; - XID winid; - - GxidDevice *device = NULL; - - if (msg->length != sizeof(GxidReleaseDevice)) - { - fprintf(stderr,"Bad length for ReleaseDevice message\n"); - return GXID_RETURN_ERROR; - } - - devid = ntohl(msg->device); - winid = ntohl(msg->window); - -#ifdef DEBUG_CLIENTS - fprintf(stderr,"device %ld released (window 0x%lx)\n",devid,winid); -#endif - - for (i=0;i<num_devices;i++) - { - if (devices[i]->id == devid) - { - device = devices[i]; - break; - } - } - if (!device) - { - fprintf(stderr,"%s: Unknown device id %ld\n",program_name,devid); - return GXID_RETURN_ERROR; - } - - for (i=0;i<num_windows;i++) - { - GxidWindow *w = windows[i]; - - if (w->xwindow == winid) - for (j=0;j<w->num_devices;j++) - if (w->devices[j]->id == devid) - { - if (j<w->num_devices-1) - w->devices[j] = w->devices[w->num_devices-1]; - w->num_devices--; - - if (w->num_devices == 0) - { - if (i<num_windows-1) - windows[i] = windows[num_windows-1]; - num_windows--; - - free((void *)w); - /* FIXME: should we deselect input? But what - what if window is already destroyed */ - } - - if (device->exclusive) - { - device->exclusive = 0; - enable_device(device); - } - return GXID_RETURN_OK; - } - } - - /* device/window combination not found */ - fprintf(stderr, - "%s: Device %ld not claimed for window 0x%lx\n", - program_name,devid,winid); - return GXID_RETURN_ERROR; -} - -void -handle_connection (void) -{ - GxidMessage msg; - GxidU32 type; - GxidU32 length; - GxidI32 retval; - - int conn_fd; - struct sockaddr_in sin; - int sin_length; - int count; - - sin_length = sizeof(struct sockaddr_in); - conn_fd = accept(socket_fd,(struct sockaddr *)&sin,&sin_length); - if (conn_fd < 0) - { - fprintf(stderr,"%s: Error accepting connection\n", - program_name); - exit(1); - } - - /* read type and length of message */ - - count = read(conn_fd,(char *)&msg,2*sizeof(GxidU32)); - if (count != 2*sizeof(GxidU32)) - { - fprintf(stderr,"%s: Error reading message header\n", - program_name); - close(conn_fd); - return; - } - type = ntohl(msg.any.type); - length = ntohl(msg.any.length); - - /* read rest of message */ - - if ((length > sizeof(GxidMessage)) || (length < 2*sizeof(GxidU32))) - { - fprintf(stderr,"%s: Bad message length\n", - program_name); - close(conn_fd); - return; - } - - count = read(conn_fd,2*sizeof(GxidU32) + (char *)&msg, - length - 2*sizeof(GxidU32)); - if (count != length - 2*sizeof(GxidU32)) - { - fprintf(stderr,"%s: Error reading message body\n", - program_name); - close(conn_fd); - return; - } - - switch (type) - { - case GXID_CLAIM_DEVICE: - retval = handle_claim_device((GxidClaimDevice *)&msg); - break; - case GXID_RELEASE_DEVICE: - retval = handle_release_device((GxidReleaseDevice *)&msg); - break; - default: - fprintf(stderr,"%s: Unknown message type: %ld (ignoring)\n", - program_name,type); - close(conn_fd); - return; - } - - count = write(conn_fd,&retval,sizeof(GxidI32)); - if (count != sizeof(GxidI32)) - { - fprintf(stderr,"%s: Error writing return code\n", - program_name); - } - - close(conn_fd); -} - -void -handle_motion_notify(XDeviceMotionEvent *event) -{ - int i,j; - GxidDevice *old_device = NULL; - GxidDevice *new_device = NULL; - Window w, root, child; - int root_x, root_y, x, y, mask; - - for (j=0;j<num_devices;j++) - { - if (devices[j]->ispointer) - old_device = devices[j]; - if (devices[j]->id == event->deviceid) - new_device = devices[j]; - } - - if (new_device && !new_device->exclusive && !new_device->ispointer) - { - /* make sure we aren't stealing the pointer back from a slow - client */ - child = root_window; - do - { - w = child; - /* FIXME: this fails disasterously if child vanishes between - calls. (Which is prone to happening since we get events - on root just as the client exits) */ - - XQueryPointer(dpy,w,&root,&child,&root_x,&root_y, - &x,&y,&mask); - } - while (child != None); - - for (i=0;i<num_windows;i++) - if (windows[i]->xwindow == w) - for (j=0;j<windows[i]->num_devices;j++) - if (windows[i]->devices[j] == new_device) - return; - - /* FIXME: do something smarter with axes */ - XChangePointerDevice(dpy,new_device->xdevice, 0, 1); - new_device->ispointer = 1; - - old_device->ispointer = 0; - if (!old_device->xdevice) - enable_device(old_device); - } -} - -void -handle_change_notify(XChangeDeviceNotifyEvent *event) -{ - int j; - GxidDevice *old_device = NULL; - GxidDevice *new_device = NULL; - - - for (j=0;j<num_devices;j++) - { - if (devices[j]->ispointer) - old_device = devices[j]; - if (devices[j]->id == event->deviceid) - new_device = devices[j]; - } - -#ifdef DEBUG_EVENTS - fprintf(stderr,"gxid: ChangeNotify event; old = %ld; new = %ld\n", - old_device->id, new_device->id); -#endif - - if (old_device != new_device) - { - new_device->ispointer = 1; - - old_device->ispointer = 0; - if (!old_device->xdevice) - enable_device(old_device); - } -} - -void -handle_enter_notify(XEnterWindowEvent *event, GxidWindow *window) -{ - int i; - GxidDevice *old_pointer = NULL; - for (i=0;i<num_devices;i++) - { - if (devices[i]->ispointer) - { - old_pointer = devices[i]; - break; - } - } - -#ifdef DEBUG_EVENTS - fprintf(stderr,"gxid: Enter event; oldpointer = %ld\n", - old_pointer->id); -#endif - - if (old_pointer) - for (i=0;i<window->num_devices;i++) - { - if (window->devices[i] == old_pointer) - { - switch_core_pointer(); - break; - } - } -} - -void -handle_destroy_notify(XDestroyWindowEvent *event) -{ - int i,j; - - for (i=0;i<num_windows;i++) - if (windows[i]->xwindow == event->window) - { - GxidWindow *w = windows[i]; - - for (j=0;j<w->num_devices;j++) - { -#ifdef DEBUG_CLIENTS - fprintf(stderr,"device %ld released on destruction of window 0x%lx.\n", - w->devices[j]->id,w->xwindow); -#endif - - if (w->devices[j]->exclusive) - { - w->devices[j]->exclusive = 0; - enable_device(devices[j]); - } - } - - if (i<num_windows-1) - windows[i] = windows[num_windows-1]; - num_windows--; - - if (w->devices) - free((void *)w->devices); - free((void *)w); - /* FIXME: should we deselect input? But what - what if window is already destroyed */ - - return; - } -} - -void -handle_xevent(void) -{ - int i; - XEvent event; - - XNextEvent (dpy, &event); - -#ifdef DEBUG_EVENTS - fprintf(stderr,"Event - type = %d; window = 0x%lx\n", - event.type,event.xany.window); -#endif - - if (event.type == ConfigureNotify) - { -#ifdef DEBUG_EVENTS - XConfigureEvent *xce = (XConfigureEvent *)&event; - fprintf(stderr," configureNotify: window = 0x%lx\n",xce->window); -#endif - } - else if (event.type == EnterNotify) - { - /* pointer entered a claimed window */ - for (i=0;i<num_windows;i++) - { - if (event.xany.window == windows[i]->xwindow) - handle_enter_notify((XEnterWindowEvent *)&event,windows[i]); - } - } - else if (event.type == DestroyNotify) - { - /* A claimed window was destroyed */ - for (i=0;i<num_windows;i++) - { - if (event.xany.window == windows[i]->xwindow) - handle_destroy_notify((XDestroyWindowEvent *)&event); - } - } - else - for (i=0;i<num_devices;i++) - { - if (event.type == devices[i]->motionnotify_type) - { - handle_motion_notify((XDeviceMotionEvent *)&event); - break; - } - else if (event.type == devices[i]->changenotify_type) - { - handle_change_notify((XChangeDeviceNotifyEvent *)&event); - break; - } - } -} - -void -usage(void) -{ - fprintf(stderr,"Usage: %s [-d display] [-p --gxid-port port]\n", - program_name); - exit(1); -} - -int -main(int argc, char **argv) -{ - int i; - char *display_name = NULL; - fd_set readfds; - - program_name = argv[0]; - - for (i=1;i<argc;i++) - { - if (!strcmp(argv[i],"-d")) - { - if (++i >= argc) usage(); - display_name = argv[i]; - } - else if (!strcmp(argv[i],"--gxid-port") || - !strcmp(argv[i],"-p")) - { - if (++i >= argc) usage(); - port = atoi(argv[i]); - break; - } - else - usage(); - } - - if (!port) - { - char *t = getenv("GXID_PORT"); - if (t) - port = atoi(t); - else - port = 6951; - } - /* set up a signal handler so we can clean up if killed */ - - signal(SIGTERM,handler); - signal(SIGINT,handler); - - /* initialize the X connection */ - - dpy = XOpenDisplay (display_name); - if (!dpy) - { - fprintf (stderr, "%s: unable to open display '%s'\n", - program_name, XDisplayName (display_name)); - exit (1); - } - - root_window = DefaultRootWindow(dpy); - - /* We'll want to do this in the future if we are to support - gxid monitoring visibility information for clients */ -#if 0 - XSelectInput(dpy,root_window,SubstructureNotifyMask); -#endif - init_xinput(); - - /* set up our server connection */ - - init_socket(); - - /* main loop */ - - if (XPending(dpy)) /* this seems necessary to get things - in sync */ - handle_xevent(); - while (1) - { - - FD_ZERO(&readfds); - FD_SET(ConnectionNumber(dpy),&readfds); - FD_SET(socket_fd,&readfds); - - if (select(8*sizeof(readfds),&readfds, - (fd_set *)0,(fd_set *)0, (struct timeval *)0) < 0) - { - fprintf(stderr,"Error in select\n"); - exit(1); - } - - if (FD_ISSET(socket_fd,&readfds)) - handle_connection(); - - while (XPending(dpy)) - handle_xevent(); - } - - XCloseDisplay (dpy); - exit (0); -} diff --git a/gdk/x11/gxid_lib.c b/gdk/x11/gxid_lib.c deleted file mode 100644 index 64c1e53b1f..0000000000 --- a/gdk/x11/gxid_lib.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * gxid version 0.3 - * - * Copyright 1997 Owen Taylor <owt1@cornell.edu> -*/ - -#include "../config.h" -#include "gxid_lib.h" - -#ifdef XINPUT_GXI - -#include <stdio.h> -#include <unistd.h> -#include <sys/time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> - -/* handles mechanics of communicating with a client */ -static int -gxid_send_message(char *host, int port, GxidMessage *msg) -{ - int socket_fd; - struct sockaddr_in sin; - int count; - GxidI32 retval; - struct hostent *he; - - if (!port) port = 6951; - - if (!host || strcmp(host,"localhost") ) - { - /* looking it up as localhost can be _SLOW_ on ppp systems */ - /* FIXME: Could localhost be anything other than loopback? */ - host = "127.0.0.1"; - } - - he = gethostbyname(host); - if (!he) - { - fprintf(stderr,"gxid_lib: error looking up %s\n",host); - return GXID_RETURN_ERROR; - } - - sin.sin_family = he->h_addrtype; - sin.sin_port = htons(port); - memcpy(&sin.sin_addr,he->h_addr_list[0],he->h_length); - - socket_fd = socket(AF_INET,SOCK_STREAM,0); - if (socket_fd < 0) - { - fprintf(stderr,"gxid_lib: can't get socket"); - return GXID_RETURN_ERROR; - } - - if (connect(socket_fd, (struct sockaddr *)&sin, - sizeof sin) < 0) - { - fprintf(stderr,"gxid_lib: can't connect to %s:%d\n",host,port); - close(socket_fd); - return GXID_RETURN_ERROR; - } - - count = write(socket_fd,(char *)msg,ntohl(msg->any.length)); - if (count != ntohl(msg->any.length)) - { - fprintf(stderr,"gxid_lib: error writing"); - close(socket_fd); - return GXID_RETURN_ERROR; - } - - /* now read the return code */ - count = read(socket_fd,(char *)&retval,sizeof(GxidI32)); - if (count != sizeof(GxidI32)) - { - fprintf(stderr,"gxid_lib: error reading return code"); - close(socket_fd); - return GXID_RETURN_ERROR; - } - - close (socket_fd); - return ntohl(retval); -} - -/* claim a device. If exclusive, device is claimed exclusively */ -int -gxid_claim_device(char *host, int port, GxidU32 device, GxidU32 window, - int exclusive) -{ - GxidClaimDevice msg; - msg.type = htonl(GXID_CLAIM_DEVICE); - msg.length = htonl(sizeof(GxidClaimDevice)); - msg.device = htonl(device); - msg.window = htonl(window); - msg.exclusive = htonl(exclusive); - - return gxid_send_message(host,port,(GxidMessage *)&msg); -} - -/* release a device/window pair */ -int -gxid_release_device(char *host, int port, GxidU32 device, GxidU32 window) -{ - GxidReleaseDevice msg; - msg.type = htonl(GXID_RELEASE_DEVICE); - msg.length = htonl(sizeof(GxidReleaseDevice)); - msg.device = htonl(device); - msg.window = htonl(window); - - return gxid_send_message(host,port,(GxidMessage *)&msg); -} - -#else /* !XINPUT_GXI */ - -/* Some compilers don't like empty source files */ -int -gxid_claim_device(char *host, int port, GxidU32 device, GxidU32 window, - int exclusive) -{ - return 0; -} - -#endif /* XINPUT_GXI */ - diff --git a/gdk/x11/gxid_lib.h b/gdk/x11/gxid_lib.h deleted file mode 100644 index 6a7103bbe0..0000000000 --- a/gdk/x11/gxid_lib.h +++ /dev/null @@ -1,6 +0,0 @@ -#include "gxid_proto.h" - -int gxid_claim_device(char *host, int port, - GxidU32 device, GxidU32 window, int exclusive); -int gxid_release_device(char *host, int port, GxidU32 device, - GxidU32 window); diff --git a/gdk/x11/gxid_proto.h b/gdk/x11/gxid_proto.h deleted file mode 100644 index 24959b806c..0000000000 --- a/gdk/x11/gxid_proto.h +++ /dev/null @@ -1,39 +0,0 @@ -#define GXID_CLAIM_DEVICE 1 -#define GXID_RELEASE_DEVICE 2 - -#define GXID_RETURN_OK 0 -#define GXID_RETURN_ERROR -1 - -typedef struct GxidClaimDevice_ GxidClaimDevice; -typedef struct GxidReleaseDevice_ GxidReleaseDevice; -typedef struct GxidMessageAny_ GxidMessageAny; -typedef union GxidMessage_ GxidMessage; - -typedef unsigned long GxidU32; -typedef long GxidI32; - -struct GxidClaimDevice_ { - GxidU32 type; - GxidU32 length; - GxidU32 device; - GxidU32 window; - GxidU32 exclusive; -}; - -struct GxidReleaseDevice_ { - GxidU32 type; - GxidU32 length; - GxidU32 device; - GxidU32 window; -}; - -struct GxidMessageAny_ { - GxidU32 type; - GxidU32 length; -}; - -union GxidMessage_ { - GxidMessageAny any; - GxidClaimDevice claim; - GxidReleaseDevice release; -}; |