Ejemplo n.º 1
0
bool wxGetFrameExtents(GdkWindow* window, int* left, int* right, int* top, int* bottom)
{
#ifdef GDK_WINDOWING_X11
    static GdkAtom property = gdk_atom_intern("_NET_FRAME_EXTENTS", false);
    Atom xproperty = gdk_x11_atom_to_xatom_for_display(
                        gdk_drawable_get_display(window), property);
    Atom type;
    int format;
    gulong nitems, bytes_after;
    guchar* data;
    Status status = XGetWindowProperty(
        gdk_x11_drawable_get_xdisplay(window),
        gdk_x11_drawable_get_xid(window),
        xproperty,
        0, 4, false, XA_CARDINAL,
        &type, &format, &nitems, &bytes_after, &data);
    const bool success = status == Success && data && nitems == 4;
    if (success)
    {
        long* p = (long*)data;
        if (left)   *left   = int(p[0]);
        if (right)  *right  = int(p[1]);
        if (top)    *top    = int(p[2]);
        if (bottom) *bottom = int(p[3]);
    }
    if (data)
        XFree(data);
    return success;
#else
    return false;
#endif
}
Ejemplo n.º 2
0
GdkCursor *
create_cursor(GdkWindow *window,
	      const guint8 *data,
	      int hot_x, int hot_y)
{
  GdkPixbuf *pixbuf;
  GdkCursor *cursor;
  GdkDisplay *display;

  g_return_val_if_fail(window != NULL, NULL);
#if GTK_CHECK_VERSION (2,24,0)
  display = gdk_window_get_display (window);
#else
  display = gdk_drawable_get_display (GDK_DRAWABLE (window));
#endif

  pixbuf = gdk_pixbuf_new_from_inline(-1, data, FALSE, NULL);

  cursor = gdk_cursor_new_from_pixbuf (display, pixbuf, hot_x,hot_y);
  g_assert(cursor != NULL);

  g_object_unref(pixbuf);

  return cursor;
}
Ejemplo n.º 3
0
static GtkWidget *create_video_window(LinphoneCall *call, LinphoneCallState cstate) {
	GtkWidget *video_window;
	GdkDisplay *display;
	GdkColor color;
	MSVideoSize vsize = MS_VIDEO_SIZE_CIF;
	const char *cstate_str;
	char *title;
	stats* counters = get_stats(call->core);

	cstate_str = linphone_call_state_to_string(cstate);
	title = g_strdup_printf("%s", cstate_str);
	video_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(video_window), title);
	g_free(title);
	gtk_window_resize(GTK_WINDOW(video_window), vsize.width, vsize.height);
	gdk_color_parse("black", &color);
	gtk_widget_modify_bg(video_window, GTK_STATE_NORMAL, &color);
	gtk_widget_show(video_window);
	g_object_set_data(G_OBJECT(video_window), "call", call);
#if GTK_CHECK_VERSION(2,24,0)
	display = gdk_window_get_display(gtk_widget_get_window(video_window));
#else // backward compatibility with Debian 6 and Centos 6
	display = gdk_drawable_get_display(gtk_widget_get_window(video_window));
#endif
	gdk_display_flush(display);
	counters->number_of_video_windows_created++;
	return video_window;
}
static void
hd_incoming_event_window_set_string_xwindow_property (GtkWidget *widget,
                                                      const gchar *prop,
                                                      const gchar *value)
{
  Atom atom;
  GdkWindow *window;
  GdkDisplay *dpy;

  /* Check if widget is realized. */
  if (!GTK_WIDGET_REALIZED (widget))
    return;

  window = widget->window;

  dpy = gdk_drawable_get_display (window);
  atom = gdk_x11_get_xatom_by_name_for_display (dpy, prop);

  if (value)
    {
      /* Set property to given value */
      XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
                       atom, XA_STRING, 8, PropModeReplace,
                       (const guchar *)value, strlen (value));
    }
  else
    {
      /* Delete property if no value is given */
      XDeleteProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
                       atom);
    }
}
Ejemplo n.º 5
0
void
gdk_property_change (GdkWindow    *window,
		     GdkAtom       property,
		     GdkAtom       type,
		     gint          format,
		     GdkPropMode   mode,
		     const guchar *data,
		     gint          nelements)
{
  GdkDisplay *display;
  Window xwindow;
  Atom xproperty;
  Atom xtype;

  g_return_if_fail (!window || GDK_IS_WINDOW (window));

  if (!window)
    {
      GdkScreen *screen;
      
      screen = gdk_screen_get_default ();
      window = gdk_screen_get_root_window (screen);
      
      GDK_NOTE (MULTIHEAD, g_message ("gdk_property_change(): window is NULL\n"));
    }


  if (GDK_WINDOW_DESTROYED (window))
    return;

  display = gdk_drawable_get_display (window);
  
  xproperty = gdk_x11_atom_to_xatom_for_display (display, property);
  xtype = gdk_x11_atom_to_xatom_for_display (display, type);
  xwindow = GDK_WINDOW_XID (window);

  if (xtype == XA_ATOM ||
      xtype == gdk_x11_get_xatom_by_name_for_display (display, "ATOM_PAIR"))
    {
      /*
       * data is an array of GdkAtom, we need to convert it
       * to an array of X Atoms
       */
      gint i;
      GdkAtom *atoms = (GdkAtom*) data;
      Atom *xatoms;

      xatoms = g_new (Atom, nelements);
      for (i = 0; i < nelements; i++)
	xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, atoms[i]);

      XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
		       xproperty, xtype,
		       format, mode, (guchar *)xatoms, nelements);
      g_free (xatoms);
    }
  else
    XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow, xproperty, 
		     xtype, format, mode, (guchar *)data, nelements);
}
Ejemplo n.º 6
0
static void
hildon_app_menu_realize                         (GtkWidget *widget)
{
    Atom property, window_type;
    Display *xdisplay;
    GdkDisplay *gdkdisplay;
    GdkScreen *screen;

    GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->realize (widget);

    gdk_window_set_decorations (widget->window, GDK_DECOR_BORDER);

    gdkdisplay = gdk_drawable_get_display (widget->window);
    xdisplay = GDK_WINDOW_XDISPLAY (widget->window);

    property = gdk_x11_get_xatom_by_name_for_display (gdkdisplay, "_NET_WM_WINDOW_TYPE");
    window_type = XInternAtom (xdisplay, "_HILDON_WM_WINDOW_TYPE_APP_MENU", False);
    XChangeProperty (xdisplay, GDK_WINDOW_XID (widget->window), property,
                     XA_ATOM, 32, PropModeReplace, (guchar *) &window_type, 1);

    /* Detect any screen changes */
    screen = gtk_widget_get_screen (widget);
    g_signal_connect (screen, "size-changed", G_CALLBACK (screen_size_changed), widget);

    /* Force menu to set the initial layout */
    screen_size_changed (screen, HILDON_APP_MENU (widget));
}
Ejemplo n.º 7
0
static void really_make_transient(GtkWidget *window, ALLEGRO_DISPLAY_XGLX *glx)
{
   GdkDisplay *gdk = gdk_drawable_get_display(GDK_DRAWABLE(window->window));
   GdkWindow *parent = gdk_window_lookup_for_display(gdk, glx->window);
   if (!parent)
      parent = gdk_window_foreign_new_for_display(gdk, glx->window);
   gdk_window_set_transient_for(window->window, parent);
}
static void
draw_background (MateBGCrossfade *fade)
{
	if (GDK_WINDOW_TYPE (fade->priv->window) == GDK_WINDOW_ROOT) {
		GdkDisplay *display;
		display = gdk_drawable_get_display (fade->priv->window);
		gdk_window_clear (fade->priv->window);
		gdk_flush ();
	} else {
		gdk_window_invalidate_rect (fade->priv->window, NULL, FALSE);
		gdk_window_process_updates (fade->priv->window, FALSE);
	}
}
Ejemplo n.º 9
0
static bool wxXGetWindowProperty(GdkWindow* window, Atom& type, int& format, gulong& nitems, guchar*& data)
{
    bool success = false;
#if GTK_CHECK_VERSION(2, 2, 0)
    if (gtk_check_version(2, 2, 0) == NULL)
    {
        gulong bytes_after;
        success = XGetWindowProperty(
            GDK_DISPLAY_XDISPLAY(gdk_drawable_get_display(window)),
            GDK_WINDOW_XWINDOW(window),
            gdk_x11_get_xatom_by_name_for_display(
                gdk_drawable_get_display(window),
                "_NET_FRAME_EXTENTS"),
            0, // left, right, top, bottom, CARDINAL[4]/32
            G_MAXLONG, // size of long
            false, // do not delete property
            XA_CARDINAL, // 32 bit
            &type, &format, &nitems, &bytes_after, &data
            ) == Success;
    }
#endif
    return success;
}
/**
 * maybe_grab_key:
 *
 * @grab_window: window to grab the key
 * @keyval: the keyval (used extensively by Gtk). 0 for AnyKey.
 * @state: modifier state (used extensively by Gtk)
 * @maybe: TRUE to grab, FALSE to ungrab.
 *
 * This function grabs/ungrabs the key by calling XGrabKey.
 * Before calling XGrabKey, the hardware keycodes are found
 * by @gdk_keymap_get_entries_from_keyval.
 *
 * returns FALSE if there is an error. TRUE if OK.
 */
static gboolean maybe_grab_key (GdkWindow * grab_window, 
				guint keyval, 
				GdkModifierType state, 
				gboolean maybe) {

	GdkDisplay * display = gdk_drawable_get_display(grab_window);
	g_assert(display);
	g_assert(grab_window);
	GdkKeymapKey * keys = NULL;
	guint modifiers; 
	gint n_keys = 0;
	int i;
	int min, max;
	gboolean rt;
	if(keyval != 0) {
		rt = gdk_keymap_get_entries_for_keyval(NULL, keyval, &keys, &n_keys);
		if(rt == FALSE) return FALSE;
	} else {
		keys = g_new0(GdkKeymapKey, 1);
		n_keys = 1;
		keys[0].keycode = AnyKey;
		keys[0].group = 0;
	}
	state &= ~(1 << 13 | 1 << 14);
	for(i = 0; i < n_keys; i++) {
		modifiers = state | (keys[i].group << 13);
		gdk_error_trap_push();
		if(maybe) {
			XGrabKey(GDK_DISPLAY_XDISPLAY(display), 
					keys[i].keycode, modifiers,
					GDK_WINDOW_XWINDOW(grab_window),
					True,
					GrabModeAsync,
					GrabModeAsync);
		} else {
			XUngrabKey(GDK_DISPLAY_XDISPLAY(display), 
					keys[i].keycode, modifiers, 
					GDK_WINDOW_XWINDOW(grab_window));
		}
		gdk_flush ();
		int errcode = gdk_error_trap_pop();
		if(errcode) {
			rt = FALSE;
			break;
		}
	}
	g_free(keys);
	return rt;
}
Ejemplo n.º 11
0
/**
 * gdk_event_request_motions:
 * @event: a valid #GdkEvent
 *
 * Request more motion notifies if @event is a motion notify hint event.
 * This function should be used instead of gdk_window_get_pointer() to
 * request further motion notifies, because it also works for extension
 * events where motion notifies are provided for devices other than the
 * core pointer. Coordinate extraction, processing and requesting more
 * motion events from a %GDK_MOTION_NOTIFY event usually works like this:
 *
 * |[
 * { 
 *   /&ast; motion_event handler &ast;/
 *   x = motion_event->x;
 *   y = motion_event->y;
 *   /&ast; handle (x,y) motion &ast;/
 *   gdk_event_request_motions (motion_event); /&ast; handles is_hint events &ast;/
 * }
 * ]|
 *
 * Since: 2.12
 **/
void
gdk_event_request_motions (const GdkEventMotion *event)
{
  GdkDisplay *display;
  
  g_return_if_fail (event != NULL);
  
  if (event->type == GDK_MOTION_NOTIFY && event->is_hint)
    {
      gdk_device_get_state (event->device, event->window, NULL, NULL);
      
      display = gdk_drawable_get_display (event->window);
      _gdk_display_enable_motion_hints (display);
    }
}
Ejemplo n.º 12
0
/**
 * gdk_event_put:
 * @event: a #GdkEvent.
 *
 * Appends a copy of the given event onto the front of the event
 * queue for event->any.window's display, or the default event
 * queue if event->any.window is %NULL. See gdk_display_put_event().
 **/
void
gdk_event_put (const GdkEvent *event)
{
  GdkDisplay *display;
  
  g_return_if_fail (event != NULL);

  if (event->any.window)
    display = gdk_drawable_get_display (event->any.window);
  else
    {
      GDK_NOTE (MULTIHEAD,
		g_message ("Falling back to default display for gdk_event_put()"));
      display = gdk_display_get_default ();
    }

  gdk_display_put_event (display, event);
}
Ejemplo n.º 13
0
/* from GtkMenu sources */
gboolean popup_grab_on_window (GdkWindow * window, guint32 activate_time)
{
	if ((gdk_pointer_grab (window, TRUE,
			       GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
			       | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK
			       | GDK_POINTER_MOTION_MASK, NULL, NULL,
			       activate_time) == 0)) {
		if (gdk_keyboard_grab (window, TRUE, activate_time) == 0)
			return TRUE;
		else {
			gdk_display_pointer_ungrab (gdk_drawable_get_display
						    (window), activate_time);
			return FALSE;
		}
	}

	return FALSE;
}
FloatRect screenAvailableRect(Widget* widget)
{
    if (!widget)
        return FloatRect();

#if PLATFORM(X11)
    GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformPageClient());
    if (!container)
        return FloatRect();

    if (!gtk_widget_get_realized(container))
        return screenRect(widget);

    GdkDrawable* rootWindow = GDK_DRAWABLE(gtk_widget_get_root_window(container));
    GdkDisplay* display = gdk_drawable_get_display(rootWindow);
    Atom xproperty = gdk_x11_get_xatom_by_name_for_display(display, "_NET_WORKAREA");

    Atom retType;
    int retFormat;
    long *workAreaPos = NULL;
    unsigned long retNItems;
    unsigned long retAfter;
    int xRes = XGetWindowProperty(GDK_DISPLAY_XDISPLAY(display), GDK_WINDOW_XWINDOW(rootWindow), xproperty,
        0, 4, FALSE, XA_CARDINAL, &retType, &retFormat, &retNItems, &retAfter, (guchar**)&workAreaPos);

    FloatRect rect;
    if (xRes == Success && workAreaPos != NULL && retType == XA_CARDINAL && retNItems == 4 && retFormat == 32) {
        rect = FloatRect(workAreaPos[0], workAreaPos[1], workAreaPos[2], workAreaPos[3]);
        // rect contains the available space in the whole screen not just in the monitor
        // containing the widget, so we intersect it with the monitor rectangle.
        rect.intersect(screenRect(widget));
    } else
        rect = screenRect(widget);

    if (workAreaPos)
        XFree(workAreaPos);

    return rect;
#else
    return screenRect(widget);
#endif
}
Ejemplo n.º 15
0
/**
 * he_helper_show_cursor:
 * @context: A realized GtkWidget.
 *
 * Shows a cursor on the screen, for a window.
 * Its method of getting the x and y coordinate is dodgy - please fix...
 *
 **/
void
he_helper_show_cursor                  (GtkWidget *widget)
{
	GdkDisplay *display;
	GdkScreen *screen;
	GtkIconTheme *theme;
	GdkPixbuf *pixbuf;
	gint x;
	gint y;
	GdkCursor *cursor = NULL;

	g_return_if_fail (widget);
	g_return_if_fail (GTK_WIDGET_DRAWABLE(widget));

	display = gdk_drawable_get_display (GDK_DRAWABLE(widget->window));
	g_return_if_fail (display);

	screen = gtk_widget_get_screen (widget);
	g_return_if_fail (screen);

	theme = gtk_icon_theme_get_for_screen (screen);
	g_return_if_fail (theme);

	pixbuf = gtk_icon_theme_load_icon (theme, CURSOR_ICON_NAME, CURSOR_ICON_SIZE, 0, NULL);
	if (!pixbuf)
		goto cleanup;

	x = (gdk_pixbuf_get_width (pixbuf) / 2) - 7;
	y = (gdk_pixbuf_get_height (pixbuf) / 2) - 7;

	cursor = gdk_cursor_new_from_pixbuf (display, pixbuf, x, y);
	if (!cursor)
		goto cleanup;

	gdk_window_set_cursor (widget->window, cursor);

cleanup:
	if (pixbuf)
		g_object_unref (pixbuf); 
	if (cursor)
		gdk_cursor_unref (cursor);
}
Ejemplo n.º 16
0
/**
 * _gdk_xgrab_check_unmap:
 * @window: a #GdkWindow
 * @serial: serial from Unmap event (or from NextRequest(display)
 *   if the unmap is being done by this client.)
 * 
 * Checks to see if an unmap request or event causes the current
 * grab window to become not viewable, and if so, clear the
 * the pointer we keep to it.
 **/
void
_gdk_xgrab_check_unmap (GdkWindow *window,
			gulong     serial)
{
  GdkDisplay *display = gdk_drawable_get_display (window);

  _gdk_display_end_pointer_grab (display, serial, window, TRUE);

  if (display->keyboard_grab.window &&
      serial >= display->keyboard_grab.serial)
    {
      GdkWindowObject *private = GDK_WINDOW_OBJECT (window);
      GdkWindowObject *tmp = GDK_WINDOW_OBJECT (display->keyboard_grab.window);

      while (tmp && tmp != private)
	tmp = tmp->parent;

      if (tmp)
	_gdk_display_unset_has_keyboard_grab (display, TRUE);
    }
Ejemplo n.º 17
0
static gboolean
rb_vis_widget_expose_event (GtkWidget *widget,
			    GdkEventExpose *event)
{
	GdkWindow   *window;
	RBVisWidget *rbvw = RB_VIS_WIDGET (widget);

	window = gtk_widget_get_window (widget);

	if (rbvw->window_xid != GDK_WINDOW_XWINDOW (window)) {
		rbvw->window_xid = GDK_WINDOW_XWINDOW (window);

		gdk_display_sync (gdk_drawable_get_display (GDK_DRAWABLE (window)));

		rb_debug ("got new window ID %lu", rbvw->window_xid);
		g_object_notify (G_OBJECT (rbvw), "window-xid");
	}

	return TRUE;
}
Ejemplo n.º 18
0
static JSValueRef runPasteTestCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    // Simulate a paste keyboard sequence.
    GdkEvent* event = gdk_event_new(GDK_KEY_PRESS);
    event->key.keyval = gdk_unicode_to_keyval('v');
    event->key.state = GDK_CONTROL_MASK;
    event->key.window = gtk_widget_get_window(GTK_WIDGET(currentFixture->webView));
    g_object_ref(event->key.window);
#ifndef GTK_API_VERSION_2
    GdkDeviceManager* manager =  gdk_display_get_device_manager(gdk_drawable_get_display(event->key.window));
    gdk_event_set_device(event, gdk_device_manager_get_client_pointer(manager));
#endif

    GdkKeymapKey* keys;
    gint n_keys;
    if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), event->key.keyval, &keys, &n_keys)) {
        event->key.hardware_keycode = keys[0].keycode;
        g_free(keys);
    }

    gtk_main_do_event(event);
    event->key.type = GDK_KEY_RELEASE;
    gtk_main_do_event(event);
    gdk_event_free(event);

    JSStringRef scriptString = JSStringCreateWithUTF8CString("document.body.innerHTML;");
    JSValueRef value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0);
    JSStringRelease(scriptString);

    g_assert(JSValueIsString(context, value));
    JSStringRef actual = JSValueToStringCopy(context, value, exception);
    g_assert(!exception || !*exception);
    g_assert(currentFixture->info->expectedContent);
    JSStringRef expected = JSStringCreateWithUTF8CString(currentFixture->info->expectedContent);
    g_assert(JSStringIsEqual(expected, actual));

    JSStringRelease(expected);
    JSStringRelease(actual);
    g_main_loop_quit(currentFixture->loop);
    return JSValueMakeUndefined(context);
}
Ejemplo n.º 19
0
/**
 * gedit_utils_get_window_workspace: Get the workspace the window is on
 *
 * This function gets the workspace that the #GtkWindow is visible on,
 * it returns GEDIT_ALL_WORKSPACES if the window is sticky, or if
 * the window manager doesn support this function
 */
guint
gedit_utils_get_window_workspace (GtkWindow *gtkwindow)
{
#ifdef GDK_WINDOWING_X11
	GdkWindow *window;
	GdkDisplay *display;
	Atom type;
	gint format;
	gulong nitems;
	gulong bytes_after;
	guint *workspace;
	gint err, result;
	guint ret = GEDIT_ALL_WORKSPACES;

	g_return_val_if_fail (GTK_IS_WINDOW (gtkwindow), 0);
	g_return_val_if_fail (GTK_WIDGET_REALIZED (GTK_WIDGET (gtkwindow)), 0);

	window = gtk_widget_get_window (GTK_WIDGET (gtkwindow));
	display = gdk_drawable_get_display (window);

	gdk_error_trap_push ();
	result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
				     gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
				     0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems,
				     &bytes_after, (gpointer) &workspace);
	err = gdk_error_trap_pop ();

	if (err != Success || result != Success)
		return ret;

	if (type == XA_CARDINAL && format == 32 && nitems > 0)
		ret = workspace[0];

	XFree (workspace);
	return ret;
#else
	/* FIXME: on mac etc proably there are native APIs
	 * to get the current workspace etc */
	return 0;
#endif
}
Ejemplo n.º 20
0
Ogre::String getWindowHandleString(GtkWidget *widget)
{
    Ogre::String handle;
    // GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
    gtk_widget_realize(widget);
    GdkWindow *parent = gtk_widget_get_parent_window(widget);

//    gdk_window_show(parent);

#if defined(__WIN32__) || defined(_WIN32)

    handle = Ogre::StringConverter::toString((unsigned long) GDK_WINDOW_HWND(parent));

#else
// #elif defined(__WXGTK__)

    GdkDisplay* display = gdk_drawable_get_display(GDK_DRAWABLE(parent));
    Display *xdisplay = GDK_DISPLAY_XDISPLAY(display);
    XSync(xdisplay, false);


    GdkScreen* screen = gdk_drawable_get_screen(GDK_DRAWABLE(parent));
    Screen *xscreen = GDK_SCREEN_XSCREEN(screen);
    int screen_number = XScreenNumberOfScreen(xscreen);
//    XID xid_parent = GDK_WINDOW_XWINDOW(parent);

    // "parentWindowHandle"
//    handle =
//        Ogre::StringConverter::toString(reinterpret_cast<unsigned long>(xdisplay)) + ":" +
//        Ogre::StringConverter::toString(static_cast<unsigned int>(screen_number)) + ":" +
//        Ogre::StringConverter::toString(static_cast<unsigned long>(xid_parent));

    handle = Ogre::StringConverter::toString(static_cast<unsigned long>(GDK_WINDOW_XID(parent)));


#endif

    // dunno what MacOS needs - you tell me

    return handle;
}
Ejemplo n.º 21
0
/**
 * he_helper_hide_cursor:
 * @context: A realized GtkWidget.
 *
 * Hides a cursor on the screen, for a window.
 *
 **/
void
he_helper_hide_cursor                  (GtkWidget *widget)
{
	GdkDisplay *display;
	GdkCursor *cursor = NULL;

	g_return_if_fail (widget);
	g_return_if_fail (GTK_WIDGET_DRAWABLE(widget));

	display = gdk_drawable_get_display (GDK_DRAWABLE(widget->window));
	g_return_if_fail (display);

	#if GTK_CHECK_VERSION(2, 16, 0)
	cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
	#else
	cursor = make_blank_cursor (display);
	#endif
	if (!cursor)
		return;

	gdk_window_set_cursor (widget->window, cursor);

	gdk_cursor_unref (cursor);
}
Ejemplo n.º 22
0
static VALUE
rg_display(VALUE self)
{
    return GOBJ2RVAL(gdk_drawable_get_display(_SELF(self)));
}
Ejemplo n.º 23
0
bool wxTopLevelWindowGTK::Show( bool show )
{
    wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );

    bool deferShow = show && !m_isShown && m_deferShow;
    if (deferShow)
    {
        deferShow = gs_requestFrameExtentsStatus != 2 &&
            m_deferShowAllowed && !gtk_widget_get_realized(m_widget);
        if (deferShow)
        {
            deferShow = g_signal_handler_find(m_widget,
                GSignalMatchType(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA),
                g_signal_lookup("property_notify_event", GTK_TYPE_WIDGET),
                0, NULL, NULL, this) != 0;
        }
        GdkScreen* screen = NULL;
        if (deferShow)
        {
#ifdef GDK_WINDOWING_X11
            screen = gtk_widget_get_screen(m_widget);
            GdkAtom atom = gdk_atom_intern("_NET_REQUEST_FRAME_EXTENTS", false);
            deferShow = gdk_x11_screen_supports_net_wm_hint(screen, atom) != 0;
#else
            deferShow = false;
#endif
            // If _NET_REQUEST_FRAME_EXTENTS not supported, don't allow changes
            // to m_decorSize, it breaks saving/restoring window size with
            // GetSize()/SetSize() because it makes window bigger between each
            // restore and save.
            m_updateDecorSize = deferShow;
        }

        m_deferShow = deferShow;
    }
    if (deferShow)
    {
        // Initial show. If WM supports _NET_REQUEST_FRAME_EXTENTS, defer
        // calling gtk_widget_show() until _NET_FRAME_EXTENTS property
        // notification is received, so correct frame extents are known.
        // This allows resizing m_widget to keep the overall size in sync with
        // what wxWidgets expects it to be without an obvious change in the
        // window size immediately after it becomes visible.

        // Realize m_widget, so m_widget->window can be used. Realizing normally
        // causes the widget tree to be size_allocated, which generates size
        // events in the wrong order. However, the size_allocates will not be
        // done if the allocation is not the default (1,1).
        GtkAllocation alloc;
        gtk_widget_get_allocation(m_widget, &alloc);
        const int alloc_width = alloc.width;
        if (alloc_width == 1)
        {
            alloc.width = 2;
            gtk_widget_set_allocation(m_widget, &alloc);
        }
        gtk_widget_realize(m_widget);
        if (alloc_width == 1)
        {
            alloc.width = 1;
            gtk_widget_set_allocation(m_widget, &alloc);
        }

#ifdef GDK_WINDOWING_X11
        // send _NET_REQUEST_FRAME_EXTENTS
        XClientMessageEvent xevent;
        memset(&xevent, 0, sizeof(xevent));
        xevent.type = ClientMessage;
        GdkWindow* window = gtk_widget_get_window(m_widget);
        xevent.window = gdk_x11_drawable_get_xid(window);
        xevent.message_type = gdk_x11_atom_to_xatom_for_display(
            gdk_drawable_get_display(window),
            gdk_atom_intern("_NET_REQUEST_FRAME_EXTENTS", false));
        xevent.format = 32;
        Display* display = gdk_x11_drawable_get_xdisplay(window);
        XSendEvent(display, DefaultRootWindow(display), false,
            SubstructureNotifyMask | SubstructureRedirectMask,
            (XEvent*)&xevent);
#endif // GDK_WINDOWING_X11

        if (gs_requestFrameExtentsStatus == 0)
        {
            // if WM does not respond to request within 1 second,
            // we assume support for _NET_REQUEST_FRAME_EXTENTS is not working
            m_netFrameExtentsTimerId =
                g_timeout_add(1000, request_frame_extents_timeout, this);
        }

        // defer calling gtk_widget_show()
        m_isShown = true;
        return true;
    }

    if (show && !gtk_widget_get_realized(m_widget))
    {
        // size_allocate signals occur in reverse order (bottom to top).
        // Things work better if the initial wxSizeEvents are sent (from the
        // top down), before the initial size_allocate signals occur.
        wxSizeEvent event(GetSize(), GetId());
        event.SetEventObject(this);
        HandleWindowEvent(event);
    }

    bool change = base_type::Show(show);

    if (change && !show)
    {
        // make sure window has a non-default position, so when it is shown
        // again, it won't be repositioned by WM as if it were a new window
        // Note that this must be done _after_ the window is hidden.
        gtk_window_move((GtkWindow*)m_widget, m_x, m_y);
    }

    return change;
}
Ejemplo n.º 24
0
int wxSystemSettingsNative::GetMetric( wxSystemMetric index, wxWindow* win )
{
    guchar *data = NULL;
    Atom type;
    int format;
    gulong nitems;
    GdkWindow *window = NULL;
    if(win && GTK_WIDGET_REALIZED(win->GetHandle()))
        window = win->GetHandle()->window;

    switch (index)
    {
        case wxSYS_BORDER_X:
        case wxSYS_BORDER_Y:
        case wxSYS_EDGE_X:
        case wxSYS_EDGE_Y:
        case wxSYS_FRAMESIZE_X:
        case wxSYS_FRAMESIZE_Y:
            // If a window is specified/realized, and it is a toplevel window, we can query from wm.
            // The returned border thickness is outside the client area in that case.
            if (window)
            {
                wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow);
                if (!tlw)
                    return -1; // not a tlw, not sure how to approach
                else
                {
                    // Check if wm supports frame extents - we can't know
                    // the border widths if it does not.
#if GTK_CHECK_VERSION(2,2,0)
                    if (!gtk_check_version(2,2,0))
                    {
                        if (!gdk_x11_screen_supports_net_wm_hint(
                                gdk_drawable_get_screen(window),
                                gdk_atom_intern("_NET_FRAME_EXTENTS", false) ) )
                            return -1;
                    }
                    else
#endif
                    {
                        if (!gdk_net_wm_supports(gdk_atom_intern("_NET_FRAME_EXTENTS", false)))
                            return -1;
                    }

                    // Get the frame extents from the windowmanager.
                    // In most cases the top extent is the titlebar, so we use the bottom extent
                    // for the heights.
                    if (wxXGetWindowProperty(window, type, format, nitems, data))
                    {
                        int border_return = -1;

                        if ((type == XA_CARDINAL) && (format == 32) && (nitems >= 4) && (data))
                        {
                            switch(index)
                            {
                                case wxSYS_BORDER_X:
                                case wxSYS_EDGE_X:
                                case wxSYS_FRAMESIZE_X:
                                    border_return = ((long*)data)[1]; // width of right extent
                                    break;
                                default:
                                    border_return = ((long*)data)[3]; // height of bottom extent
                                    break;
                            }
                        }

                        if (data)
                            XFree(data);

                        return border_return;
                    }
                }
            }

            return -1; // no window specified

        case wxSYS_CURSOR_X:
        case wxSYS_CURSOR_Y:
#ifdef __WXGTK24__
            if (!gtk_check_version(2,4,0))
            {
                if (window)
                    return gdk_display_get_default_cursor_size(gdk_drawable_get_display(window));
                else
                    return gdk_display_get_default_cursor_size(gdk_display_get_default());
            }
            else
#endif
                return 16;

        case wxSYS_DCLICK_X:
        case wxSYS_DCLICK_Y:
            gint dclick_distance;
#if GTK_CHECK_VERSION(2,2,0)
            if (window && !gtk_check_version(2,2,0))
                g_object_get(gtk_settings_get_for_screen(gdk_drawable_get_screen(window)),
                                "gtk-double-click-distance", &dclick_distance, NULL);
            else
#endif
                g_object_get(gtk_settings_get_default(),
                                "gtk-double-click-distance", &dclick_distance, NULL);

            return dclick_distance * 2;

        case wxSYS_DRAG_X:
        case wxSYS_DRAG_Y:
            gint drag_threshold;
#if GTK_CHECK_VERSION(2,2,0)
            if (window && !gtk_check_version(2,2,0))
            {
                g_object_get(
                        gtk_settings_get_for_screen(gdk_drawable_get_screen(window)),
                        "gtk-dnd-drag-threshold",
                        &drag_threshold, NULL);
            }
            else
#endif
            {
                g_object_get(gtk_settings_get_default(),
                             "gtk-dnd-drag-threshold", &drag_threshold, NULL);
            }

            // The correct thing here would be to double the value
            // since that is what the API wants. But the values
            // are much bigger under GNOME than under Windows and
            // just seem to much in many cases to be useful.
            // drag_threshold *= 2;

            return drag_threshold;

        // MBN: ditto for icons
        case wxSYS_ICON_X:     return 32;
        case wxSYS_ICON_Y:     return 32;

        case wxSYS_SCREEN_X:
#if GTK_CHECK_VERSION(2,2,0)
            if (window && !gtk_check_version(2,2,0))
                return gdk_screen_get_width(gdk_drawable_get_screen(window));
            else
#endif
                return gdk_screen_width();

        case wxSYS_SCREEN_Y:
#if GTK_CHECK_VERSION(2,2,0)
            if (window && !gtk_check_version(2,2,0))
                return gdk_screen_get_height(gdk_drawable_get_screen(window));
            else
#endif
                return gdk_screen_height();

        case wxSYS_HSCROLL_Y:  return 15;
        case wxSYS_VSCROLL_X:  return 15;

        case wxSYS_CAPTION_Y:
            if (!window)
                // No realized window specified, and no implementation for that case yet.
                return -1;

            // Check if wm supports frame extents - we can't know the caption height if it does not.
#if GTK_CHECK_VERSION(2,2,0)
            if (!gtk_check_version(2,2,0))
            {
                if (!gdk_x11_screen_supports_net_wm_hint(
                        gdk_drawable_get_screen(window),
                        gdk_atom_intern("_NET_FRAME_EXTENTS", false) ) )
                    return -1;
            }
            else
#endif
            {
                if (!gdk_net_wm_supports(gdk_atom_intern("_NET_FRAME_EXTENTS", false)))
                    return -1;
            }

            wxASSERT_MSG( wxDynamicCast(win, wxTopLevelWindow),
                          wxT("Asking for caption height of a non toplevel window") );

            // Get the height of the top windowmanager border.
            // This is the titlebar in most cases. The titlebar might be elsewhere, and
            // we could check which is the thickest wm border to decide on which side the
            // titlebar is, but this might lead to interesting behaviours in used code.
            // Reconsider when we have a way to report to the user on which side it is.
            if (wxXGetWindowProperty(window, type, format, nitems, data))
            {
                int caption_height = -1;

                if ((type == XA_CARDINAL) && (format == 32) && (nitems >= 3) && (data))
                {
                    caption_height = ((long*)data)[2]; // top frame extent
                }

                if (data)
                    XFree(data);

                return caption_height;
            }

            // Try a default approach without a window pointer, if possible
            // ...

            return -1;

        case wxSYS_PENWINDOWS_PRESENT:
            // No MS Windows for Pen computing extension available in X11 based gtk+.
            return 0;

        default:
            return -1;   // metric is unknown
    }
}
JNIEXPORT void JNICALL 
Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetCursorUnlocked
  (JNIEnv *env, jobject obj, jint type, jobject image, jint x, jint y) 
{
  void *ptr;
  GtkWidget *widget;
  GdkWindow *win;
  GdkCursorType gdk_cursor_type;
  GdkCursor *gdk_cursor;

  ptr = gtkpeer_get_widget (env, obj);

  switch (type)
    {
    case AWT_CROSSHAIR_CURSOR:
      gdk_cursor_type = GDK_CROSSHAIR;
      break;
    case AWT_TEXT_CURSOR:
      gdk_cursor_type = GDK_XTERM;
      break;
    case AWT_WAIT_CURSOR:
      gdk_cursor_type = GDK_WATCH;
      break;
    case AWT_SW_RESIZE_CURSOR:
      gdk_cursor_type = GDK_BOTTOM_LEFT_CORNER;
      break;
    case AWT_SE_RESIZE_CURSOR:
      gdk_cursor_type = GDK_BOTTOM_RIGHT_CORNER;
      break;
    case AWT_NW_RESIZE_CURSOR:
      gdk_cursor_type = GDK_TOP_LEFT_CORNER;
      break;
    case AWT_NE_RESIZE_CURSOR:
      gdk_cursor_type = GDK_TOP_RIGHT_CORNER;
      break;
    case AWT_N_RESIZE_CURSOR:
      gdk_cursor_type = GDK_TOP_SIDE;
      break;
    case AWT_S_RESIZE_CURSOR:
      gdk_cursor_type = GDK_BOTTOM_SIDE;
      break;
    case AWT_W_RESIZE_CURSOR:
      gdk_cursor_type = GDK_LEFT_SIDE;
      break;
    case AWT_E_RESIZE_CURSOR:
      gdk_cursor_type = GDK_RIGHT_SIDE;
      break;
    case AWT_HAND_CURSOR:
      gdk_cursor_type = GDK_HAND2;
      break;
    case AWT_MOVE_CURSOR:
      gdk_cursor_type = GDK_FLEUR;
      break;
    default:
      gdk_cursor_type = GDK_LEFT_PTR;
    }
      
  widget = get_widget(GTK_WIDGET(ptr));
  
  win = widget->window;
  if ((widget->window) == NULL)
    win = GTK_WIDGET(ptr)->window;
    
  if (image == NULL)
    gdk_cursor = gdk_cursor_new (gdk_cursor_type);
  else
    gdk_cursor
      = gdk_cursor_new_from_pixbuf (gdk_drawable_get_display (win),
				    cp_gtk_image_get_pixbuf (env, image),
				    x, y);

  gdk_window_set_cursor (win, gdk_cursor);
  gdk_cursor_unref (gdk_cursor);

  /* Make sure the cursor is replaced on screen. */
  gdk_flush();
}
Ejemplo n.º 26
0
/**
\brief      Control redirection input events to window.
\author     William J Giddings
\date       12-Apr-09
\note       Gdk Documentation for the implemented features.
            http://library.gnome.org/devel/gdk/stable/gdk-General.html
**/
int gnoclGrabCmd ( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] )
{
	static const char *cmd[] = { "pointer", "keyboard", "release", "status", NULL };
	enum optIdx { PointerIdx, KeyboardIdx, ReleaseIdx, StatusIdx };
	int idx;

	if ( objc != 3 )
	{
		Tcl_WrongNumArgs ( interp, 1, objv, "option widgetid " );
		return TCL_ERROR;
	}

	if ( Tcl_GetIndexFromObj ( interp, objv[1], cmd, "option", TCL_EXACT, &idx ) != TCL_OK )
	{
		return TCL_ERROR;
	}

	/*
	    g_print ( "opt = %s  id = %s\n",  Tcl_GetString ( objv[1] ),  Tcl_GetString ( objv[2] ) );
	*/
	switch ( idx )
	{
			/* deny any pointer events, ie. grab all pointer inputs */
		case PointerIdx:
			{
				GtkWidget *widget;
				guint32 activate_time;

				widget = gnoclGetWidgetFromName (  Tcl_GetString ( objv[2] ), interp );

				gdk_pointer_grab ( widget->window ,
								   TRUE,
								   GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
								   NULL, NULL, GDK_CURRENT_TIME );
				break;
			}

			/* deny any keyboard events, ie. grab all keyboard inputs */
		case KeyboardIdx:
			{
				GtkWidget *widget;
				guint32 activate_time;

				widget = gnoclGetWidgetFromName (  Tcl_GetString ( objv[2] ), interp );
				gdk_keyboard_grab ( widget->window , TRUE, GDK_CURRENT_TIME );
				break;
			}

			/* relase all grabs applied to the current display */
		case ReleaseIdx:
			{
				GtkWidget *widget;
				guint32 activate_time;

				widget = gnoclGetWidgetFromName (  Tcl_GetString ( objv[2] ), interp );
				gdk_display_pointer_ungrab ( gdk_drawable_get_display ( widget->window ), GDK_CURRENT_TIME );
				gdk_keyboard_ungrab ( GDK_CURRENT_TIME );
			}

			break;

			/* give status on pointer input grab, no equivalent for the keyboard */
		case StatusIdx:
			{
				char buffer[5];

				sprintf ( buffer, "%s", gdk_pointer_is_grabbed );
				Tcl_SetObjResult ( interp, Tcl_NewStringObj ( buffer, -1 ) );
			}

	}

	return TCL_OK;
}
Ejemplo n.º 27
0
int wxSystemSettingsNative::GetMetric( wxSystemMetric index, wxWindow* win )
{
    GdkWindow *window = NULL;
    if(win && GTK_WIDGET_REALIZED(win->GetHandle()))
        window = win->GetHandle()->window;

    switch (index)
    {
        case wxSYS_BORDER_X:
        case wxSYS_BORDER_Y:
        case wxSYS_EDGE_X:
        case wxSYS_EDGE_Y:
        case wxSYS_FRAMESIZE_X:
        case wxSYS_FRAMESIZE_Y:
            if (win)
            {
                wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow);
                if (!tlw)
                    return GetBorderWidth(index, win);
                else if (window)
                {
                    // Get the frame extents from the windowmanager.
                    // In most cases the top extent is the titlebar, so we use the bottom extent
                    // for the heights.
                    int right, bottom;
                    if (wxGetFrameExtents(window, NULL, &right, NULL, &bottom))
                    {
                        switch (index)
                        {
                            case wxSYS_BORDER_X:
                            case wxSYS_EDGE_X:
                            case wxSYS_FRAMESIZE_X:
                                return right; // width of right extent
                            default:
                                return bottom; // height of bottom extent
                        }
                    }
                }
            }

            return -1; // no window specified

        case wxSYS_CURSOR_X:
        case wxSYS_CURSOR_Y:
                return gdk_display_get_default_cursor_size(
                            window ? gdk_drawable_get_display(window)
                                   : gdk_display_get_default());

        case wxSYS_DCLICK_X:
        case wxSYS_DCLICK_Y:
            gint dclick_distance;
            g_object_get(GetSettingsForWindowScreen(window),
                            "gtk-double-click-distance", &dclick_distance, NULL);

            return dclick_distance * 2;

        case wxSYS_DCLICK_MSEC:
            gint dclick;
            g_object_get(GetSettingsForWindowScreen(window),
                            "gtk-double-click-time", &dclick, NULL);
            return dclick;

        case wxSYS_DRAG_X:
        case wxSYS_DRAG_Y:
            gint drag_threshold;
            g_object_get(GetSettingsForWindowScreen(window),
                            "gtk-dnd-drag-threshold", &drag_threshold, NULL);

            // The correct thing here would be to double the value
            // since that is what the API wants. But the values
            // are much bigger under GNOME than under Windows and
            // just seem to much in many cases to be useful.
            // drag_threshold *= 2;

            return drag_threshold;

        case wxSYS_ICON_X:
        case wxSYS_ICON_Y:
            return 32;

        case wxSYS_SCREEN_X:
            if (window)
                return gdk_screen_get_width(gdk_drawable_get_screen(window));
            else
                return gdk_screen_width();

        case wxSYS_SCREEN_Y:
            if (window)
                return gdk_screen_get_height(gdk_drawable_get_screen(window));
            else
                return gdk_screen_height();

        case wxSYS_HSCROLL_Y:
        case wxSYS_VSCROLL_X:
            return 15;

        case wxSYS_CAPTION_Y:
            if (!window)
                // No realized window specified, and no implementation for that case yet.
                return -1;

            wxASSERT_MSG( wxDynamicCast(win, wxTopLevelWindow),
                          wxT("Asking for caption height of a non toplevel window") );

            // Get the height of the top windowmanager border.
            // This is the titlebar in most cases. The titlebar might be elsewhere, and
            // we could check which is the thickest wm border to decide on which side the
            // titlebar is, but this might lead to interesting behaviours in used code.
            // Reconsider when we have a way to report to the user on which side it is.
            {
                int top;
                if (wxGetFrameExtents(window, NULL, NULL, &top, NULL))
                {
                    return top; // top frame extent
                }
            }

            // Try a default approach without a window pointer, if possible
            // ...

            return -1;

        case wxSYS_PENWINDOWS_PRESENT:
            // No MS Windows for Pen computing extension available in X11 based gtk+.
            return 0;

        default:
            return -1;   // metric is unknown
    }
}
static void
hildon_remote_texture_realize                 (GtkWidget *widget)
{
    GdkDisplay *display;
    Atom wm_type, applet_type;

    GTK_WIDGET_CLASS (hildon_remote_texture_parent_class)->realize (widget);

    /* Set remote texture window type. */

    display = gdk_drawable_get_display (widget->window);

    wm_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE");
    applet_type = gdk_x11_get_xatom_by_name_for_display (display, "_HILDON_WM_WINDOW_TYPE_REMOTE_TEXTURE");

    XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (widget->window), wm_type,
                     XA_ATOM, 32, PropModeReplace,
                     (unsigned char *) &applet_type, 1);

    /* This is a bit of a hack, but for the sake of speed (it is assumed that
     * once HildonRemoteTexture is created, a lot of ClientMessages will
     * follow), we cache all ClientMessages atoms in static variables. */

    if (!atoms_initialized)
    {
        shm_atom =
            gdk_x11_get_xatom_by_name_for_display
            (display, "_HILDON_TEXTURE_CLIENT_MESSAGE_SHM");
        damage_atom =
            gdk_x11_get_xatom_by_name_for_display
            (display, "_HILDON_TEXTURE_CLIENT_MESSAGE_DAMAGE");
	show_atom =
	    gdk_x11_get_xatom_by_name_for_display
	    (display, "_HILDON_TEXTURE_CLIENT_MESSAGE_SHOW");
	position_atom =
	    gdk_x11_get_xatom_by_name_for_display
	    (display, "_HILDON_TEXTURE_CLIENT_MESSAGE_POSITION");
	offset_atom =
            gdk_x11_get_xatom_by_name_for_display
            (display, "_HILDON_TEXTURE_CLIENT_MESSAGE_OFFSET");
	scale_atom =
	    gdk_x11_get_xatom_by_name_for_display
	    (display, "_HILDON_TEXTURE_CLIENT_MESSAGE_SCALE");
	parent_atom =
	    gdk_x11_get_xatom_by_name_for_display
	    (display, "_HILDON_TEXTURE_CLIENT_MESSAGE_PARENT");
	ready_atom =
	    gdk_x11_get_xatom_by_name_for_display
	    (display, "_HILDON_TEXTURE_CLIENT_READY");
#if 0
	g_debug ("shm atom = %lu\n", shm_atom);
	g_debug ("damage atom = %lu\n", damage_atom);
	g_debug ("show atom = %lu\n", show_atom);
	g_debug ("position atom = %lu\n", position_atom);
	g_debug ("offset atom = %lu\n", offset_atom);
	g_debug ("scale atom = %lu\n", scale_atom);
	g_debug ("parent atom = %lu\n", parent_atom);
	g_debug ("ready atom = %lu\n", ready_atom);
#endif

	atoms_initialized = TRUE;
    }

    /* Wait for a ready message */

    gdk_window_add_filter (widget->window,
			   hildon_remote_texture_event_filter,
			   widget);
}
Ejemplo n.º 29
0
void
_gtk_tooltip_handle_event (GdkEvent *event)
{
  gint x, y;
  gboolean return_value = FALSE;
  GtkWidget *has_tooltip_widget = NULL;
  GdkDisplay *display;
  GtkTooltip *current_tooltip;

  if (!tooltips_enabled (event->any.window))
    return;

  /* Returns coordinates relative to has_tooltip_widget's allocation. */
  has_tooltip_widget = find_topmost_widget_coords_from_event (event, &x, &y);
  display = gdk_drawable_get_display (event->any.window);
  current_tooltip = g_object_get_data (G_OBJECT (display),
				       "gdk-display-current-tooltip");

  if (current_tooltip)
    {
      gtk_tooltip_set_last_window (current_tooltip, event->any.window);
      gdk_event_get_root_coords (event,
				&current_tooltip->last_x,
				&current_tooltip->last_y);
    }

  if (current_tooltip && current_tooltip->keyboard_mode_enabled)
    {
      has_tooltip_widget = current_tooltip->keyboard_widget;
      if (!has_tooltip_widget)
	return;

      return_value = gtk_tooltip_run_requery (&has_tooltip_widget,
					      current_tooltip,
					      &x, &y);

      if (!return_value)
	gtk_tooltip_hide_tooltip (current_tooltip);
      else
	gtk_tooltip_start_delay (display);

      return;
    }

#ifdef DEBUG_TOOLTIP
  if (has_tooltip_widget)
    g_print ("%p (%s) at (%d, %d) %dx%d     pointer: (%d, %d)\n",
	     has_tooltip_widget, gtk_widget_get_name (has_tooltip_widget),
	     has_tooltip_widget->allocation.x,
	     has_tooltip_widget->allocation.y,
	     has_tooltip_widget->allocation.width,
	     has_tooltip_widget->allocation.height,
	     x, y);
#endif /* DEBUG_TOOLTIP */

  /* Always poll for a next motion event */
  gdk_event_request_motions (&event->motion);

  /* Hide the tooltip when there's no new tooltip widget */
  if (!has_tooltip_widget)
    {
      if (current_tooltip)
	gtk_tooltip_hide_tooltip (current_tooltip);

      return;
    }

  switch (event->type)
    {
      case GDK_BUTTON_PRESS:
      case GDK_2BUTTON_PRESS:
      case GDK_3BUTTON_PRESS:
      case GDK_KEY_PRESS:
      case GDK_DRAG_ENTER:
      case GDK_GRAB_BROKEN:
	gtk_tooltip_hide_tooltip (current_tooltip);
	break;

      case GDK_MOTION_NOTIFY:
      case GDK_ENTER_NOTIFY:
      case GDK_LEAVE_NOTIFY:
      case GDK_SCROLL:
	if (current_tooltip)
	  {
	    gboolean tip_area_set;
	    GdkRectangle tip_area;
	    gboolean hide_tooltip;

	    tip_area_set = current_tooltip->tip_area_set;
	    tip_area = current_tooltip->tip_area;

	    return_value = gtk_tooltip_run_requery (&has_tooltip_widget,
						    current_tooltip,
						    &x, &y);

	    /* Requested to be hidden? */
	    hide_tooltip = !return_value;

	    /* Leave notify should override the query function */
	    hide_tooltip = (event->type == GDK_LEAVE_NOTIFY);

	    /* Is the pointer above another widget now? */
	    if (GTK_TOOLTIP_VISIBLE (current_tooltip))
	      hide_tooltip |= has_tooltip_widget != current_tooltip->tooltip_widget;

	    /* Did the pointer move out of the previous "context area"? */
	    if (tip_area_set)
	      hide_tooltip |= (x <= tip_area.x
			       || x >= tip_area.x + tip_area.width
			       || y <= tip_area.y
			       || y >= tip_area.y + tip_area.height);

	    if (hide_tooltip)
	      gtk_tooltip_hide_tooltip (current_tooltip);
	    else
	      gtk_tooltip_start_delay (display);
	  }
	else
	  {
	    /* Need a new tooltip for this display */
	    current_tooltip = g_object_new (GTK_TYPE_TOOLTIP, NULL);
	    g_object_set_data_full (G_OBJECT (display),
				    "gdk-display-current-tooltip",
				    current_tooltip, g_object_unref);
	    g_signal_connect (display, "closed",
			      G_CALLBACK (gtk_tooltip_display_closed),
			      current_tooltip);

	    gtk_tooltip_set_last_window (current_tooltip, event->any.window);
	    gdk_event_get_root_coords (event,
				       &current_tooltip->last_x,
				       &current_tooltip->last_y);

	    gtk_tooltip_start_delay (display);
	  }
	break;

      default:
	break;
    }
}
Ejemplo n.º 30
0
gboolean
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)
{
  GdkDisplay *display;
  Atom ret_prop_type;
  gint ret_format;
  gulong ret_nitems;
  gulong ret_bytes_after;
  gulong get_length;
  gulong ret_length;
  guchar *ret_data;
  Atom xproperty;
  Atom xtype;
  int res;

  g_return_val_if_fail (!window || GDK_WINDOW_IS_X11 (window), FALSE);

  if (!window)
    {
      GdkScreen *screen = gdk_screen_get_default ();
      window = gdk_screen_get_root_window (screen);
      
      GDK_NOTE (MULTIHEAD, g_message ("gdk_property_get(): window is NULL\n"));
    }
  else if (!GDK_WINDOW_IS_X11 (window))
    return FALSE;

  if (GDK_WINDOW_DESTROYED (window))
    return FALSE;

  display = gdk_drawable_get_display (window);
  xproperty = gdk_x11_atom_to_xatom_for_display (display, property);
  if (type == GDK_NONE)
    xtype = AnyPropertyType;
  else
    xtype = gdk_x11_atom_to_xatom_for_display (display, type);

  ret_data = NULL;
  
  /* 
   * Round up length to next 4 byte value.  Some code is in the (bad?)
   * habit of passing G_MAXLONG as the length argument, causing an
   * overflow to negative on the add.  In this case, we clamp the
   * value to G_MAXLONG.
   */
  get_length = length + 3;
  if (get_length > G_MAXLONG)
    get_length = G_MAXLONG;

  /* To fail, either the user passed 0 or G_MAXULONG */
  get_length = get_length / 4;
  if (get_length == 0)
    {
      g_warning ("gdk_propery-get(): invalid length 0");
      return FALSE;
    }

  res = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
			    GDK_WINDOW_XWINDOW (window), xproperty,
			    offset, get_length, pdelete,
			    xtype, &ret_prop_type, &ret_format,
			    &ret_nitems, &ret_bytes_after,
			    &ret_data);

  if (res != Success || (ret_prop_type == None && ret_format == 0))
    {
      return FALSE;
    }

  if (actual_property_type)
    *actual_property_type = gdk_x11_xatom_to_atom_for_display (display, ret_prop_type);
  if (actual_format_type)
    *actual_format_type = ret_format;

  if ((xtype != AnyPropertyType) && (ret_prop_type != xtype))
    {
      XFree (ret_data);
      g_warning ("Couldn't match property type %s to %s\n", 
		 gdk_x11_get_xatom_name_for_display (display, ret_prop_type), 
		 gdk_x11_get_xatom_name_for_display (display, xtype));
      return FALSE;
    }

  /* FIXME: ignoring bytes_after could have very bad effects */

  if (data)
    {
      if (ret_prop_type == XA_ATOM ||
	  ret_prop_type == gdk_x11_get_xatom_by_name_for_display (display, "ATOM_PAIR"))
	{
	  /*
	   * data is an array of X atom, we need to convert it
	   * to an array of GDK Atoms
	   */
	  gint i;
	  GdkAtom *ret_atoms = g_new (GdkAtom, ret_nitems);
	  Atom *xatoms = (Atom *)ret_data;

	  *data = (guchar *)ret_atoms;

	  for (i = 0; i < ret_nitems; i++)
	    ret_atoms[i] = gdk_x11_xatom_to_atom_for_display (display, xatoms[i]);
	  
	  if (actual_length)
	    *actual_length = ret_nitems * sizeof (GdkAtom);
	}
      else
	{
	  switch (ret_format)
	    {
	    case 8:
	      ret_length = ret_nitems;
	      break;
	    case 16:
	      ret_length = sizeof(short) * ret_nitems;
	      break;
	    case 32:
	      ret_length = sizeof(long) * 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;
}