void
S9xOpenGLDisplayDriver::swap_control (int enable)
{
    glSwapIntervalProc glSwapInterval = NULL;
    const char         *ext_str;

    ext_str = glXQueryExtensionsString (GDK_DISPLAY (),
                                        GDK_SCREEN_XNUMBER (
                                            gdk_screen_get_default ()));

    /* We try to set this with both extensions since some cards pretend
     * to support both, but ignore one. */

    if (strstr (ext_str, "GLX_MESA_swap_control"))
    {
        glSwapInterval = (glSwapIntervalProc)
            glGetProcAddress ((GLubyte *) "glXSwapIntervalMESA");
        if (glSwapInterval)
            glSwapInterval (enable ? 1 : 0);
    }

    else if (strstr (ext_str, "GLX_SGI_swap_control"))
    {
        glSwapInterval = (glSwapIntervalProc)
            glGetProcAddress ((GLubyte *) "glXSwapIntervalSGI");
        if (glSwapInterval)
        {
            glSwapInterval (enable ? 1 : 0);
        }
    }

    return;
}
Exemplo n.º 2
0
static int
get_current_desktop (GdkScreen *screen)
{
        Display *display;
        Window win;
        Atom current_desktop, type;
        int format;
        unsigned long n_items, bytes_after;
        unsigned char *data_return = NULL;
        int workspace = 0;

        display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen));
        win = XRootWindow (display, GDK_SCREEN_XNUMBER (screen));

        current_desktop = XInternAtom (display, "_NET_CURRENT_DESKTOP", True);

        XGetWindowProperty (display,
                            win,
                            current_desktop,
                            0, G_MAXLONG,
                            False, XA_CARDINAL,
                            &type, &format, &n_items, &bytes_after,
                            &data_return);

        if (type == XA_CARDINAL && format == 32 && n_items > 0)
                workspace = (int) data_return[0];
        if (data_return)
                XFree (data_return);

        return workspace;
}
Exemplo n.º 3
0
static gboolean
gdk_gl_pixmap_impl_x11_make_context_current (GdkGLDrawable *draw,
                                             GdkGLDrawable *read,
                                             GdkGLContext  *glcontext)
{
  GdkGLConfig *glconfig;
  GLXPixmap glxpixmap;
  GLXContext glxcontext;

  g_return_val_if_fail (GDK_IS_GL_PIXMAP_IMPL_X11 (draw), FALSE);
  g_return_val_if_fail (GDK_IS_GL_CONTEXT_IMPL_X11 (glcontext), FALSE);

  glconfig = GDK_GL_PIXMAP_IMPL_X11 (draw)->glconfig;
  glxpixmap = GDK_GL_PIXMAP_IMPL_X11 (draw)->glxpixmap;
  glxcontext = GDK_GL_CONTEXT_GLXCONTEXT (glcontext);

  if (glxpixmap == None || glxcontext == NULL)
    return FALSE;

#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
  GDK_GL_NOTE (MISC,
    g_message (" -- Pixmap: screen number = %d",
      GDK_SCREEN_XNUMBER (gdk_drawable_get_screen (GDK_DRAWABLE (draw)))));
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */
  GDK_GL_NOTE (MISC,
    g_message (" -- Pixmap: visual id = 0x%lx",
      GDK_VISUAL_XVISUAL (gdk_drawable_get_visual (GDK_DRAWABLE (draw)))->visualid));

  GDK_GL_NOTE_FUNC_IMPL ("glXMakeCurrent");

  if (!glXMakeCurrent (GDK_GL_CONFIG_XDISPLAY (glconfig), glxpixmap, glxcontext))
    {
      g_warning ("glXMakeCurrent() failed");
      _gdk_gl_context_set_gl_drawable (glcontext, NULL);
      /* currently unused. */
      /* _gdk_gl_context_set_gl_drawable_read (glcontext, NULL); */
      return FALSE;
    }

  _gdk_gl_context_set_gl_drawable (glcontext, draw);
  /* currently unused. */
  /* _gdk_gl_context_set_gl_drawable_read (glcontext, read); */

  if (_GDK_GL_CONFIG_AS_SINGLE_MODE (glconfig))
    {
      /* We do this because we are treating a double-buffered frame
         buffer as a single-buffered frame buffer because the system
         does not appear to export any suitable single-buffered
         visuals (in which the following are necessary). */
      glDrawBuffer (GL_FRONT);
      glReadBuffer (GL_FRONT);
    }

  GDK_GL_NOTE (MISC, _gdk_gl_print_gl_info ());

  return TRUE;
}
Exemplo n.º 4
0
bool VideoOverlay::getDescription( VideoDescription &desc ) {
#ifdef _WIN32
	desc = NULL;
#else
	desc.display = GDK_WINDOW_XDISPLAY(gtk_widget_get_window(_window));
	desc.screenID = GDK_SCREEN_XNUMBER(gtk_widget_get_screen(GTK_WIDGET(_window)));
	desc.winID = GDK_WINDOW_XID(gtk_widget_get_window(_window));
#endif
	return true;
}
Exemplo n.º 5
0
static GdkNativeWindow select_window(GdkScreen *screen) {
    Display    *x_dpy;
    Cursor      x_cursor;
    XEvent      x_event;
    Window      x_win = None;
    Window      x_root;
    gint        x_scr;
    gint        status;
    gint        buttons = 0;

    x_dpy = GDK_SCREEN_XDISPLAY (screen);
    x_scr = GDK_SCREEN_XNUMBER (screen);

    x_root   = RootWindow (x_dpy, x_scr);
    x_cursor = XCreateFontCursor (x_dpy, GDK_CROSSHAIR);

    status = XGrabPointer (x_dpy, x_root, False,
                           MASK, GrabModeSync, GrabModeAsync,
                           x_root, x_cursor, CurrentTime);

    if (status != GrabSuccess) {
        printf("!GrabSucces\n");
        return 0;
    }

    while ( (x_win == None) || (buttons != 0))
    {
        XAllowEvents (x_dpy, SyncPointer, CurrentTime);
        XWindowEvent (x_dpy, x_root, MASK, &x_event);

        switch (x_event.type)
        {
        case ButtonPress:
            if (x_win == None)
            {
                x_win = x_event.xbutton.subwindow;
                if (x_win == None)
                    x_win = x_root;
            }
            buttons++;
            break;

        case ButtonRelease:
            if (buttons > 0)
                buttons--;
            break;

        }
    }

    XUngrabPointer (x_dpy, CurrentTime);
    XFreeCursor (x_dpy, x_cursor);

    return x_win;
}
Exemplo n.º 6
0
/* This function queries the _XROOTPMAP_ID property from the root window
 * to determine the current root window background pixmap and returns a
 * surface to draw directly to it.
 * If _XROOTPMAP_ID is not set, then NULL returned.
 */
static cairo_surface_t *
get_root_pixmap_id_surface (GdkDisplay *display)
{
	GdkScreen       *screen;
	Display         *xdisplay;
	Visual          *xvisual;
	Window           xroot;
	Atom             type;
	int              format, result;
	unsigned long    nitems, bytes_after;
	unsigned char   *data;
	cairo_surface_t *surface = NULL;

	g_return_val_if_fail (display != NULL, NULL);

	screen   = gdk_display_get_default_screen (display);
	xdisplay = GDK_DISPLAY_XDISPLAY (display);
	xvisual  = GDK_VISUAL_XVISUAL (gdk_screen_get_system_visual (screen));
	xroot    = RootWindow (xdisplay, GDK_SCREEN_XNUMBER (screen));

	result = XGetWindowProperty (xdisplay, xroot,
				     gdk_x11_get_xatom_by_name ("_XROOTPMAP_ID"),
				     0L, 1L, False, XA_PIXMAP,
				     &type, &format, &nitems, &bytes_after,
				     &data);

	if (result != Success || type != XA_PIXMAP ||
	    format != 32 || nitems != 1) {
		XFree (data);
		data = NULL;
	}

	if (data != NULL) {
		Pixmap pixmap = *(Pixmap *) data;
		Window root_ret;
		int x_ret, y_ret;
		unsigned int w_ret, h_ret, bw_ret, depth_ret;

		gdk_x11_display_error_trap_push (display);
		if (XGetGeometry (xdisplay, pixmap, &root_ret,
		                  &x_ret, &y_ret, &w_ret, &h_ret,
		                  &bw_ret, &depth_ret))
		{
			surface = cairo_xlib_surface_create (xdisplay,
			                                     pixmap, xvisual,
			                                     w_ret, h_ret);
		}

		gdk_x11_display_error_trap_pop_ignored (display);
		XFree (data);
	}

	gdk_display_flush (display);
	return surface;
}
Exemplo n.º 7
0
gboolean
gdk_gl_window_make_context_current (GdkGLDrawable *draw, GdkGLContext *glcontext)
{
  GdkGLDrawable *read = draw;
  GdkGLConfig *glconfig;
  Window glxwindow;
  GLXContext glxcontext;

  g_return_val_if_fail (GDK_IS_GL_WINDOW (draw), FALSE);
  g_return_val_if_fail (GDK_IS_GL_CONTEXT_IMPL_X11 (glcontext), FALSE);

  glconfig = GDK_GL_WINDOW (draw)->glconfig;
  glxwindow = GDK_GL_WINDOW (draw)->glxwindow;
  glxcontext = GDK_GL_CONTEXT_GLXCONTEXT (glcontext);

  if (glxwindow == None || glxcontext == NULL)
    return FALSE;

  GDK_GL_NOTE (MISC, g_message (" -- Window: screen number = %d", GDK_SCREEN_XNUMBER (gdk_drawable_get_screen (GDK_DRAWABLE (draw)))));
  GDK_GL_NOTE (MISC, g_message (" -- Window: visual id = 0x%lx", GDK_VISUAL_XVISUAL (gdk_drawable_get_visual (GDK_DRAWABLE (draw)))->visualid));

  GDK_GL_NOTE_FUNC_IMPL ("glXMakeCurrent");

  if (!glXMakeCurrent (GDK_GL_CONFIG_XDISPLAY (glconfig), glxwindow, glxcontext))
    {
      g_warning ("glXMakeCurrent() failed");
      _gdk_gl_context_set_gl_drawable (glcontext, NULL);
      return FALSE;
    }

  _gdk_gl_context_set_gl_drawable (glcontext, draw);

  if (_GDK_GL_CONFIG_AS_SINGLE_MODE (glconfig))
    {
      /* We do this because we are treating a double-buffered frame
         buffer as a single-buffered frame buffer because the system
         does not appear to export any suitable single-buffered
         visuals (in which the following are necessary). */
      glDrawBuffer (GL_FRONT);
      glReadBuffer (GL_FRONT);
    }

  GDK_GL_NOTE (MISC, _gdk_gl_print_gl_info ());

  return TRUE;
}
Exemplo n.º 8
0
void glyph_cache_set_font(TGlyphCache *cache, PangoFontDescription *font_desc)
{
	PangoFontMap *font_map;
	PangoFontMetrics *metrics;

	if (cache->hash) {
		g_hash_table_destroy(cache->hash);
		g_object_unref(cache->font_set);
	}

	cache->hash = g_hash_table_new_full(NULL, NULL, NULL, glyph_destroy_gfi);

	font_map = pango_xft_get_font_map(
		GDK_DISPLAY_XDISPLAY(cache->display),
		GDK_SCREEN_XNUMBER(cache->screen)
	);
	g_object_ref (font_map);

	cache->font_set = pango_font_map_load_fontset(
		font_map,
		cache->context,
		font_desc,
		cache->lang
	);

	g_object_unref(font_map);
	font_map = NULL;

	metrics = pango_fontset_get_metrics(cache->font_set);
	pango_font_metrics_ref(metrics);

	cache->ascent = pango_font_metrics_get_ascent(metrics);
	cache->descent = pango_font_metrics_get_descent(metrics);

	cache->width = pango_font_metrics_get_approximate_digit_width(metrics);
	cache->height = cache->ascent + cache->descent;
	if (cache->width <= 0) {
		fprintf (stderr, "Warning: cache->width = %d\n", cache->width);
		cache->width = cache->height / 2;
	}

	pango_font_metrics_unref(metrics);
}
Exemplo n.º 9
0
static void
gtku_gl_drawing_area_init (GtkuGLDrawingArea * self)
{
    GtkuGLDrawingAreaPrivate * priv = GTKU_GL_DRAWING_AREA_GET_PRIVATE (self);

    gtk_widget_set_double_buffered (GTK_WIDGET (self), FALSE);
    priv->dpy = NULL;
    priv->visual = NULL;
    priv->context = NULL;
#ifdef USE_VBLANK
    priv->vblank_watch = 0;
    priv->pipe[0] = -1;
    priv->thread = 0;
    priv->quit_thread = 0;
    priv->swap_requested = 0;
#endif

    XVisualInfo * vinfo = glXChooseVisual (GDK_DISPLAY (),
            GDK_SCREEN_XNUMBER (gdk_screen_get_default ()),
            attr_list);
    if (!vinfo) {
        fprintf (stderr, "Preferred visual not found, using default...\n");
        return;
    }
    VisualID desired_id = vinfo->visualid;
    XFree (vinfo);

    GList * visuals = gdk_list_visuals ();
    GList * vis;
    for (vis = visuals; vis; vis = vis->next) {
        Visual * xv = GDK_VISUAL_XVISUAL (vis->data);
        if (XVisualIDFromVisual (xv) == desired_id) {
            GdkColormap * colormap = gdk_colormap_new (vis->data, FALSE);
            gtk_widget_set_colormap (GTK_WIDGET (self), colormap);
            g_object_unref (G_OBJECT (colormap));
            break;
        }
    }
    g_list_free (visuals);
}
Exemplo n.º 10
0
static gboolean
get_work_area (NotifyStack  *stack,
               GdkRectangle *rect)
{
        Atom            workarea;
        Atom            type;
        Window          win;
        int             format;
        gulong          num;
        gulong          leftovers;
        gulong          max_len = 4 * 32;
        guchar         *ret_workarea;
        long           *workareas;
        int             result;
        int             disp_screen;

	#if GTK_CHECK_VERSION(3, 0, 0)
		workarea = XInternAtom(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "_NET_WORKAREA", True);
	#else
		workarea = XInternAtom(GDK_DISPLAY(), "_NET_WORKAREA", True);
	#endif


        disp_screen = GDK_SCREEN_XNUMBER (stack->screen);

        /* Defaults in case of error */
        rect->x = 0;
        rect->y = 0;
        rect->width = gdk_screen_get_width (stack->screen);
        rect->height = gdk_screen_get_height (stack->screen);

        if (workarea == None)
                return FALSE;


	#if GTK_CHECK_VERSION(3, 0, 0)

		win = XRootWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), disp_screen);

		result = XGetWindowProperty(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
									win,
									workarea,
									0,
									max_len,
									False,
									AnyPropertyType,
									&type,
									&format,
									&num,
									&leftovers,
									&ret_workarea);
	#else

		win = XRootWindow(GDK_DISPLAY(), disp_screen);

		result = XGetWindowProperty(GDK_DISPLAY(),
									win,
									workarea,
									0,
									max_len,
									False,
									AnyPropertyType,
									&type,
									&format,
									&num,
									&leftovers,
									&ret_workarea);
	#endif

        if (result != Success
            || type == None
            || format == 0
            || leftovers
            || num % 4) {
                return FALSE;
        }

        workareas = (long *) ret_workarea;
        rect->x = workareas[disp_screen * 4];
        rect->y = workareas[disp_screen * 4 + 1];
        rect->width = workareas[disp_screen * 4 + 2];
        rect->height = workareas[disp_screen * 4 + 3];

        XFree (ret_workarea);

        return TRUE;
}
Exemplo n.º 11
0
static GdkNativeWindow
select_window_x11 (GdkScreen *screen)
{
  Display      *x_dpy       = GDK_SCREEN_XDISPLAY (screen);
  gint          x_scr       = GDK_SCREEN_XNUMBER (screen);
  Window        x_root      = RootWindow (x_dpy, x_scr);
  Window        x_win       = None;
  GC            x_gc          = None;
  Cursor        x_cursor    = XCreateFontCursor (x_dpy, GDK_CROSSHAIR);
  GdkKeymapKey *keys        = NULL;
  gint          status;
  gint          i, num_keys;
  gint          buttons     = 0;
  gint          mask        = ButtonPressMask | ButtonReleaseMask;
  gboolean      cancel      = FALSE;

  if (shootvals.shoot_type == SHOOT_REGION)
    mask |= PointerMotionMask;

  status = XGrabPointer (x_dpy, x_root, False,
                         mask, GrabModeSync, GrabModeAsync,
                         x_root, x_cursor, CurrentTime);

  if (status != GrabSuccess)
    {
      gint  x, y;
      guint xmask;

      /* if we can't grab the pointer, return the window under the pointer */
      XQueryPointer (x_dpy, x_root, &x_root, &x_win, &x, &y, &x, &y, &xmask);

      if (x_win == None || x_win == x_root)
        g_message (_("Error selecting the window"));
    }

  if (shootvals.shoot_type == SHOOT_REGION)
    {
      XGCValues gc_values;

      gc_values.function           = GXxor;
      gc_values.plane_mask         = AllPlanes;
      gc_values.foreground         = WhitePixel (x_dpy, x_scr);
      gc_values.background         = BlackPixel (x_dpy, x_scr);
      gc_values.line_width         = 0;
      gc_values.line_style         = LineSolid;
      gc_values.fill_style         = FillSolid;
      gc_values.cap_style          = CapButt;
      gc_values.join_style         = JoinMiter;
      gc_values.graphics_exposures = FALSE;
      gc_values.clip_x_origin      = 0;
      gc_values.clip_y_origin      = 0;
      gc_values.clip_mask          = None;
      gc_values.subwindow_mode     = IncludeInferiors;

      x_gc = XCreateGC (x_dpy, x_root,
                        GCFunction | GCPlaneMask | GCForeground | GCLineWidth |
                        GCLineStyle | GCCapStyle | GCJoinStyle |
                        GCGraphicsExposures | GCBackground | GCFillStyle |
                        GCClipXOrigin | GCClipYOrigin | GCClipMask |
                        GCSubwindowMode,
                        &gc_values);
    }

  if (gdk_keymap_get_entries_for_keyval (NULL, GDK_Escape, &keys, &num_keys))
    {
      gdk_error_trap_push ();

#define X_GRAB_KEY(index, modifiers) \
      XGrabKey (x_dpy, keys[index].keycode, modifiers, x_root, False, \
                GrabModeAsync, GrabModeAsync)

      for (i = 0; i < num_keys; i++)
        {
          X_GRAB_KEY (i, 0);
          X_GRAB_KEY (i, LockMask);            /* CapsLock              */
          X_GRAB_KEY (i, Mod2Mask);            /* NumLock               */
          X_GRAB_KEY (i, Mod5Mask);            /* ScrollLock            */
          X_GRAB_KEY (i, LockMask | Mod2Mask); /* CapsLock + NumLock    */
          X_GRAB_KEY (i, LockMask | Mod5Mask); /* CapsLock + ScrollLock */
          X_GRAB_KEY (i, Mod2Mask | Mod5Mask); /* NumLock  + ScrollLock */
          X_GRAB_KEY (i, LockMask | Mod2Mask | Mod5Mask); /* all        */
        }

#undef X_GRAB_KEY

      gdk_flush ();
      gdk_error_trap_pop ();
    }

  while (! cancel && ((x_win == None) || (buttons != 0)))
    {
      XEvent x_event;
      gint   x, y, w, h;

      XAllowEvents (x_dpy, SyncPointer, CurrentTime);
      XWindowEvent (x_dpy, x_root, mask | KeyPressMask, &x_event);

      switch (x_event.type)
        {
        case ButtonPress:
          if (x_win == None)
            {
              x_win = x_event.xbutton.subwindow;

              if (x_win == None)
                x_win = x_root;
#ifdef HAVE_X11_XMU_WINUTIL_H
              else if (! shootvals.decorate)
                x_win = XmuClientWindow (x_dpy, x_win);
#endif

              shootvals.x2 = shootvals.x1 = x_event.xbutton.x_root;
              shootvals.y2 = shootvals.y1 = x_event.xbutton.y_root;
            }

          buttons++;
          break;

        case ButtonRelease:
          if (buttons > 0)
            buttons--;

          if (! buttons && shootvals.shoot_type == SHOOT_REGION)
            {
              x = MIN (shootvals.x1, shootvals.x2);
              y = MIN (shootvals.y1, shootvals.y2);
              w = ABS (shootvals.x2 - shootvals.x1);
              h = ABS (shootvals.y2 - shootvals.y1);

              if (w > 0 && h > 0)
                XDrawRectangle (x_dpy, x_root, x_gc, x, y, w, h);

              shootvals.x2 = x_event.xbutton.x_root;
              shootvals.y2 = x_event.xbutton.y_root;
            }
          break;

        case MotionNotify:
          if (buttons > 0)
            {
              x = MIN (shootvals.x1, shootvals.x2);
              y = MIN (shootvals.y1, shootvals.y2);
              w = ABS (shootvals.x2 - shootvals.x1);
              h = ABS (shootvals.y2 - shootvals.y1);

              if (w > 0 && h > 0)
                XDrawRectangle (x_dpy, x_root, x_gc, x, y, w, h);

              shootvals.x2 = x_event.xmotion.x_root;
              shootvals.y2 = x_event.xmotion.y_root;

              x = MIN (shootvals.x1, shootvals.x2);
              y = MIN (shootvals.y1, shootvals.y2);
              w = ABS (shootvals.x2 - shootvals.x1);
              h = ABS (shootvals.y2 - shootvals.y1);

              if (w > 0 && h > 0)
                XDrawRectangle (x_dpy, x_root, x_gc, x, y, w, h);
            }
          break;

        case KeyPress:
          {
            guint *keyvals;
            gint   n;

            if (gdk_keymap_get_entries_for_keycode (NULL, x_event.xkey.keycode,
                                                    NULL, &keyvals, &n))
              {
                gint i;

                for (i = 0; i < n && ! cancel; i++)
                  if (keyvals[i] == GDK_Escape)
                    cancel = TRUE;

                g_free (keyvals);
              }
          }
          break;

        default:
          break;
        }
    }

  if (keys)
    {
#define X_UNGRAB_KEY(index, modifiers) \
      XUngrabKey (x_dpy, keys[index].keycode, modifiers, x_root)

      for (i = 0; i < num_keys; i++)
        {
          X_UNGRAB_KEY (i, 0);
          X_UNGRAB_KEY (i, LockMask);            /* CapsLock              */
          X_UNGRAB_KEY (i, Mod2Mask);            /* NumLock               */
          X_UNGRAB_KEY (i, Mod5Mask);            /* ScrollLock            */
          X_UNGRAB_KEY (i, LockMask | Mod2Mask); /* CapsLock + NumLock    */
          X_UNGRAB_KEY (i, LockMask | Mod5Mask); /* CapsLock + ScrollLock */
          X_UNGRAB_KEY (i, Mod2Mask | Mod5Mask); /* NumLock  + ScrollLock */
          X_UNGRAB_KEY (i, LockMask | Mod2Mask | Mod5Mask); /* all        */
        }
#undef X_UNGRAB_KEY

      g_free (keys);
    }

  if (status == GrabSuccess)
    XUngrabPointer (x_dpy, CurrentTime);

  XFreeCursor (x_dpy, x_cursor);

  if (x_gc != None)
    XFreeGC (x_dpy, x_gc);

  return x_win;
}
Exemplo n.º 12
0
static void widget_realized (void)
{
    GdkWindow * window = gtk_widget_get_window (s_widget);

#ifdef GDK_WINDOWING_X11
    GdkScreen * screen = gdk_window_get_screen (window);
    int nscreen = GDK_SCREEN_XNUMBER (screen);

    s_display = GDK_SCREEN_XDISPLAY (screen);
    s_xwindow = GDK_WINDOW_XID (window);

    /* Create s_context */
    int attribs[] = {
     GLX_RGBA,
     GLX_RED_SIZE, 1,
     GLX_GREEN_SIZE, 1,
     GLX_BLUE_SIZE, 1,
     GLX_ALPHA_SIZE, 1,
     GLX_DOUBLEBUFFER,
     GLX_DEPTH_SIZE, 1,
     None
    };

    XVisualInfo * xvinfo = glXChooseVisual (s_display, nscreen, attribs);
    g_return_if_fail (xvinfo);

    /* Fix up visual/colormap */
    GdkVisual * visual = gdk_x11_screen_lookup_visual (screen, xvinfo->visualid);
    g_return_if_fail (visual);

    gtk_widget_set_visual (s_widget, visual);

    s_context = glXCreateContext (s_display, xvinfo, 0, True);
    g_return_if_fail (s_context);

    XFree (xvinfo);

    glXMakeCurrent (s_display, s_xwindow, s_context);
#endif

#ifdef GDK_WINDOWING_WIN32
    s_hwnd = GDK_WINDOW_HWND (window);
    s_hdc = GetDC (s_hwnd);

    PIXELFORMATDESCRIPTOR desc = {
     sizeof (PIXELFORMATDESCRIPTOR),
     1,                                 // version number (?)
     PFD_DRAW_TO_WINDOW |               // format must support window
     PFD_SUPPORT_OPENGL |               // format must support OpenGL
     PFD_DOUBLEBUFFER,                  // must support double buffering
     PFD_TYPE_RGBA,                     // request an RGBA format
     24,                                // select a 8:8:8 bit color depth
     0, 0, 0, 0, 0, 0,                  // color bits ignored (?)
     0,                                 // no alpha buffer
     0,                                 // shift bit ignored (?)
     0,                                 // no accumulation buffer
     0, 0, 0, 0,                        // accumulation bits ignored (?)
     16,                                // 16-bit z-buffer (depth buffer)
     0,                                 // no stencil buffer
     0,                                 // no auxiliary buffer (?)
     PFD_MAIN_PLANE,                    // main drawing layer
     0,                                 // reserved (?)
     0, 0, 0                            // layer masks ignored (?)
    };

    int format = ChoosePixelFormat (s_hdc, & desc);
    g_return_if_fail (format != 0);

    SetPixelFormat (s_hdc, format, & desc);

    s_glrc = wglCreateContext (s_hdc);
    g_return_if_fail (s_glrc);

    wglMakeCurrent (s_hdc, s_glrc);
#endif
}
static GdkNativeWindow
select_window (GdkScreen *screen)
{
#define MASK (ButtonPressMask | ButtonReleaseMask)

  Display    *x_dpy;
  Cursor      x_cursor;
  XEvent      x_event;
  Window      x_win;
  Window      x_root;
  gint        x_scr;
  gint        status;
  gint        buttons;

  x_dpy = GDK_SCREEN_XDISPLAY (screen);
  x_scr = GDK_SCREEN_XNUMBER (screen);

  x_win    = None;
  x_root   = RootWindow (x_dpy, x_scr);
  x_cursor = XCreateFontCursor (x_dpy, GDK_CROSSHAIR);
  buttons  = 0;

  status = XGrabPointer (x_dpy, x_root, False,
                         MASK, GrabModeSync, GrabModeAsync,
                         x_root, x_cursor, CurrentTime);

  if (status != GrabSuccess)
    {
      g_message (_("Error grabbing the pointer %d"), status);
      return 0;
    }

  while ((x_win == None) || (buttons != 0))
    {
      XAllowEvents (x_dpy, SyncPointer, CurrentTime);
      XWindowEvent (x_dpy, x_root, MASK, &x_event);

      switch (x_event.type)
        {
        case ButtonPress:
          if (x_win == None)
            {
              x_win = x_event.xbutton.subwindow;
              if (x_win == None)
                x_win = x_root;
            }
          buttons++;
          break;

        case ButtonRelease:
          if (buttons > 0)
            buttons--;
          break;

        default:
          g_assert_not_reached ();
        }
    }

  XUngrabPointer (x_dpy, CurrentTime);
  XFreeCursor (x_dpy, x_cursor);

  return x_win;
}
Exemplo n.º 14
0
static void
init_xft_settings (GdkScreen *screen)
{
  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
  Display *xdisplay = GDK_SCREEN_XDISPLAY (screen);
  int xscreen = GDK_SCREEN_XNUMBER (screen);
  double dpi_double;

  if (screen_x11->xft_init)
    return;

  screen_x11->xft_init = TRUE;

  if (!get_boolean_default (xdisplay, "antialias", &screen_x11->xft_antialias))
    screen_x11->xft_antialias = TRUE;

  if (!get_boolean_default (xdisplay, "hinting", &screen_x11->xft_hinting))
    screen_x11->xft_hinting = TRUE;

  if (!get_integer_default (xdisplay, "hintstyle", &screen_x11->xft_hintstyle))
    screen_x11->xft_hintstyle = FC_HINT_FULL;

  if (!get_integer_default (xdisplay, "rgba", &screen_x11->xft_rgba))
			    
    {
      int subpixel = FC_RGBA_UNKNOWN;
      
#if RENDER_MAJOR > 0 || RENDER_MINOR >= 6
      if (_gdk_x11_have_render (screen_x11->display))
	{
	  int render_order = XRenderQuerySubpixelOrder (xdisplay, xscreen);
	  
	  switch (render_order)
	    {
	    default:
	    case SubPixelUnknown:
	      subpixel = FC_RGBA_UNKNOWN;
	      break;
	    case SubPixelHorizontalRGB:
	      subpixel = FC_RGBA_RGB;
	      break;
	    case SubPixelHorizontalBGR:
	      subpixel = FC_RGBA_BGR;
	      break;
	    case SubPixelVerticalRGB:
	      subpixel = FC_RGBA_VRGB;
	      break;
	    case SubPixelVerticalBGR:
	      subpixel = FC_RGBA_VBGR;
	      break;
	    case SubPixelNone:
	      subpixel = FC_RGBA_NONE;
	      break;
	    }
	}
#endif

      screen_x11->xft_rgba = subpixel;
    }

  if (!get_double_default (xdisplay, "dpi", &dpi_double))
    dpi_double = (((double) DisplayHeight (xdisplay, xscreen) * 25.4) / 
		  (double) DisplayHeightMM (xdisplay, xscreen));

  screen_x11->xft_dpi = (int)(0.5 + PANGO_SCALE * dpi_double);
}
Exemplo n.º 15
0
static void
gtku_gl_drawing_area_realize (GtkWidget * widget)
{
    GtkuGLDrawingArea * self = GTKU_GL_DRAWING_AREA (widget);
    GtkuGLDrawingAreaPrivate * priv = GTKU_GL_DRAWING_AREA_GET_PRIVATE (self);

    /* chain up */
    GTK_WIDGET_CLASS (gtku_gl_drawing_area_parent_class)->realize (widget);

    priv->dpy = GDK_WINDOW_XDISPLAY(widget->window);

#if 0
    priv->visual = glXChooseVisual (priv->dpy,
            GDK_SCREEN_XNUMBER (gdk_drawable_get_screen (GDK_DRAWABLE (widget->window))),
            //DefaultScreen (priv->dpy),
            attr_list);
#endif
    GdkDrawable * draw = GDK_DRAWABLE (widget->window);
    int screen = GDK_SCREEN_XNUMBER (gdk_drawable_get_screen (draw));
    XVisualInfo vinfo_template = {
        .visualid = XVisualIDFromVisual (gdk_x11_visual_get_xvisual (
                    gdk_drawable_get_visual (draw))),
        .screen = screen,
        .depth = gdk_drawable_get_depth (draw),
    };
    int nitems;
    fprintf (stderr, "Using X Visual 0x%x\n",
            (unsigned int) vinfo_template.visualid);
    priv->visual = XGetVisualInfo (priv->dpy,
            VisualIDMask | VisualScreenMask | VisualDepthMask,
            &vinfo_template, &nitems);
    if (priv->visual == NULL) {
        g_warning ("Failed to find GLX visual\n");
        return;
    }
    if (nitems != 1)
        fprintf (stderr, "Warning: more than one matching X visual found\n");

    priv->context = glXCreateContext (priv->dpy, priv->visual, 0,
            GL_TRUE);
    if (!priv->context) {
        g_warning ("Failed to get GLX context\n");
        XFree (priv->visual);
        priv->visual = NULL;
        return;
    }

    if (!glXMakeCurrent (priv->dpy, GDK_WINDOW_XID (widget->window),
                priv->context)) {
        g_warning ("Could not make GLX context current\n");
        return;
    }

    /* If the user doesn't want vblank sync, we are done */
    if (!self->vblank_sync)
        return;

    /* Check for the presence of the video_sync extension */
    if (!is_glx_extension_present (priv->dpy, screen, "GLX_SGI_video_sync")) {
        self->vblank_sync = 0;
        fprintf (stderr, "Video sync functions not found, disabling...\n");
        return;
    }

#ifdef USE_VBLANK
    /* Below we create a new thread to monitor the vblank.  We will
     * signal back to this thread by writing to a file descriptor
     * when each vblank occurs. */

    /* TODO: check extension list */

    GetVideoSyncSGI = (PFNGLXGETVIDEOSYNCSGIPROC) glXGetProcAddressARB (
            (unsigned char *)"glXGetVideoSyncSGI");
    WaitVideoSyncSGI = (PFNGLXWAITVIDEOSYNCSGIPROC) glXGetProcAddressARB (
            (unsigned char *)"glXWaitVideoSyncSGI");

    if (!GetVideoSyncSGI || !WaitVideoSyncSGI) {
        self->vblank_sync = 0;
        fprintf (stderr, "Video sync functions not found, disabling...\n");
        return;
    }

    unsigned int count = 0;
    if (GetVideoSyncSGI (&count) != 0) {
        self->vblank_sync = 0;
        fprintf (stderr, "Video sync counter failed, disabling...\n");
        return;
    }

    int pp = pipe (priv->pipe);
    assert (pp >= 0);

    fcntl (priv->pipe[0], F_SETFL, O_NONBLOCK);

    if (pthread_create (&priv->thread, NULL, swap_thread, priv) != 0) {
        self->vblank_sync = 0;
        fprintf (stderr, "Video sync thread creation failed, disabling...\n");
        return;
    }

    GIOChannel * chan = g_io_channel_unix_new (priv->pipe[0]);
    priv->vblank_watch = g_io_add_watch (chan, G_IO_IN, swap_func, self);
    g_io_channel_unref (chan);
#endif
}
Exemplo n.º 16
0
static void
get_work_area (GdkScreen    *screen,
               GdkRectangle *area)
{
  Atom            workarea;
  Atom            type;
  Window          win;
  int             format;
  gulong          num;
  gulong          leftovers;
  gulong          max_len = 4 * 32;
  guchar         *ret_workarea;
  long           *workareas;
  int             result;
  int             disp_screen;
  int             desktop;
  Display        *display;

  display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen));
  disp_screen = GDK_SCREEN_XNUMBER (screen);
  workarea = XInternAtom (display, "_NET_WORKAREA", True);

  /* Defaults in case of error */
  area->x = 0;
  area->y = 0;
  area->width = gdk_screen_get_width (screen);
  area->height = gdk_screen_get_height (screen);

  if (workarea == None)
    return;

  win = XRootWindow (display, disp_screen);
  result = XGetWindowProperty (display,
                               win,
                               workarea,
                               0,
                               max_len,
                               False,
                               AnyPropertyType,
                               &type,
                               &format,
                               &num,
                               &leftovers,
                               &ret_workarea);
  if (result != Success ||
      type == None ||
      format == 0 ||
      leftovers ||
      num % 4 != 0)
    return;

  desktop = get_current_desktop (screen);

  workareas = (long *) ret_workarea;
  area->x = workareas[desktop * 4];
  area->y = workareas[desktop * 4 + 1];
  area->width = workareas[desktop * 4 + 2];
  area->height = workareas[desktop * 4 + 3];

  XFree (ret_workarea);
}
Exemplo n.º 17
0
static gboolean
get_work_area (MateRRLabeler *labeler,
	       GdkRectangle   *rect)
{
	Atom            workarea;
	Atom            type;
	Window          win;
	int             format;
	gulong          num;
	gulong          leftovers;
	gulong          max_len = 4 * 32;
	guchar         *ret_workarea;
	long           *workareas;
	int             result;
	int             disp_screen;
	int             desktop;
	Display        *display;

	display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (labeler->priv->screen));
	workarea = XInternAtom (display, "_NET_WORKAREA", True);

	disp_screen = GDK_SCREEN_XNUMBER (labeler->priv->screen);

	/* Defaults in case of error */
	rect->x = 0;
	rect->y = 0;
	rect->width = gdk_screen_get_width (labeler->priv->screen);
	rect->height = gdk_screen_get_height (labeler->priv->screen);

	if (workarea == None)
		return FALSE;

	win = XRootWindow (display, disp_screen);
	result = XGetWindowProperty (display,
				     win,
				     workarea,
				     0,
				     max_len,
				     False,
				     AnyPropertyType,
				     &type,
				     &format,
				     &num,
				     &leftovers,
				     &ret_workarea);

	if (result != Success
	    || type == None
	    || format == 0
	    || leftovers
	    || num % 4) {
		return FALSE;
	}

	desktop = get_current_desktop (labeler->priv->screen);

	workareas = (long *) ret_workarea;
	rect->x = workareas[desktop * 4];
	rect->y = workareas[desktop * 4 + 1];
	rect->width = workareas[desktop * 4 + 2];
	rect->height = workareas[desktop * 4 + 3];

	XFree (ret_workarea);

	return TRUE;
}
Exemplo n.º 18
0
void
gdk_x11_screen_get_work_area (GdkScreen    *screen,
                              GdkRectangle *area)
{
  GdkX11Screen   *x11_screen = GDK_X11_SCREEN (screen);
  Atom            workarea;
  Atom            type;
  Window          win;
  int             format;
  gulong          num;
  gulong          leftovers;
  gulong          max_len = 4 * 32;
  guchar         *ret_workarea = NULL;
  long           *workareas;
  int             result;
  int             disp_screen;
  int             desktop;
  Display        *display;

  display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen));
  disp_screen = GDK_SCREEN_XNUMBER (screen);
  workarea = XInternAtom (display, "_NET_WORKAREA", True);

  /* Defaults in case of error */
  area->x = 0;
  area->y = 0;
  area->width = gdk_screen_get_width (screen);
  area->height = gdk_screen_get_height (screen);

  if (!gdk_x11_screen_supports_net_wm_hint (screen,
                                            gdk_atom_intern_static_string ("_NET_WORKAREA")))
    return;

  if (workarea == None)
    return;

  win = XRootWindow (display, disp_screen);
  result = XGetWindowProperty (display,
                               win,
                               workarea,
                               0,
                               max_len,
                               False,
                               AnyPropertyType,
                               &type,
                               &format,
                               &num,
                               &leftovers,
                               &ret_workarea);
  if (result != Success ||
      type == None ||
      format == 0 ||
      leftovers ||
      num % 4 != 0)
    goto out;

  desktop = get_current_desktop (screen);
  if (desktop + 1 > num / 4) /* fvwm gets this wrong */
    goto out;

  workareas = (long *) ret_workarea;
  area->x = workareas[desktop * 4];
  area->y = workareas[desktop * 4 + 1];
  area->width = workareas[desktop * 4 + 2];
  area->height = workareas[desktop * 4 + 3];

  area->x /= x11_screen->window_scale;
  area->y /= x11_screen->window_scale;
  area->width /= x11_screen->window_scale;
  area->height /= x11_screen->window_scale;

out:
  if (ret_workarea)
    XFree (ret_workarea);
}
Exemplo n.º 19
0
static __SOVPropArray *
gdk_gl_overlay_get_sov_props (GdkScreen *screen)
{
  __SOVPropArray *sov_props;
  GdkWindow *root_window;
#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
  GdkDisplay *display;
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */
  Display *xdisplay;
  Atom xa_sov;
  Status status;
  Atom actual_type;
  int actual_format;
  unsigned long nitems, bytes_after;
  unsigned char *prop = NULL;

  GDK_GL_NOTE_FUNC_PRIVATE ();

#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
  root_window = gdk_screen_get_root_window (screen);
#else  /* GDKGLEXT_MULTIHEAD_SUPPORT */
  root_window = gdk_get_default_root_window ();
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */

  if (quark_sov_props == 0)
    quark_sov_props = g_quark_from_static_string (quark_sov_props_string);

  sov_props = g_object_get_qdata (G_OBJECT (root_window), quark_sov_props);
  if (sov_props != NULL)
    return sov_props;

  sov_props = g_malloc (sizeof (__SOVPropArray));

#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
  display = gdk_screen_get_display (screen);
  xdisplay = GDK_DISPLAY_XDISPLAY (display);
  xa_sov = gdk_x11_get_xatom_by_name_for_display (display, "SERVER_OVERLAY_VISUALS");
#else  /* GDKGLEXT_MULTIHEAD_SUPPORT */
  xdisplay = gdk_x11_get_default_xdisplay ();
  xa_sov = gdk_x11_get_xatom_by_name ("SERVER_OVERLAY_VISUALS");
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */

  status = XGetWindowProperty (xdisplay, GDK_WINDOW_XWINDOW (root_window),
                               xa_sov, 0L, 1000000L, False, AnyPropertyType,
                               &actual_type, &actual_format,
                               &nitems, &bytes_after, &prop);
  if (status != Success ||
      actual_type == None ||
      actual_format != 32 ||
      nitems < 4)
    {
      GDK_GL_NOTE (MISC, g_message (" -- SERVER_OVERLAY_VISUALS: not supported"));

      if (prop != NULL)
        XFree (prop);

      sov_props->prop = NULL;
      sov_props->num = 0;
    }
  else
    {
      GDK_GL_NOTE (MISC, g_message (" -- SERVER_OVERLAY_VISUALS: supported"));

      sov_props->prop = (__SOVProp *) prop;
      sov_props->num = nitems / (sizeof (__SOVProp) / 4);
    }

  g_object_set_qdata_full (G_OBJECT (root_window), quark_sov_props, sov_props,
                           (GDestroyNotify) sov_prop_array_destroy);

#ifdef G_ENABLE_DEBUG
  if (gdk_gl_debug_flags & GDK_GL_DEBUG_MISC)
    {
#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
      int screen_num = GDK_SCREEN_XNUMBER (screen);
#else  /* GDKGLEXT_MULTIHEAD_SUPPORT */
      int screen_num = gdk_x11_get_default_screen ();
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */
      int i;

      g_message (" -- SERVER_OVERLAY_VISUALS: properties");
      g_print ("screen\tvisual\ttype\tvalue\tlayer\n");
      for (i = 0; i < sov_props->num; i++)
        {
          g_print ("%d\t0x%lx\t%lu\t%lu\t%ld\n",
                   screen_num,
                   (VisualID) (sov_props->prop[i].overlay_visual),
                   (CARD32)   (sov_props->prop[i].transparent_type),
                   (CARD32)   (sov_props->prop[i].value),
                   (INT32)    (sov_props->prop[i].layer));
        }
    }
#endif /* G_ENABLE_DEBUG */

  return sov_props;
}