Detecting the gdk backend

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Detecting the gdk backend

Gtk+ - Apps Dev mailing list
Hi all. Is there a way to detect the gdk backend an app is using? I know
about the environment variable - GDK_BACKEND. But often this is not set,
and gtk just picks whatever's available. I need ever-so-slightly different
app behaviour, depending on the backend. Any ideas?

Dan
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Detecting the gdk backend

Gtk+ - Apps Dev mailing list
Hi! There is some reference code here:
https://developer.gnome.org/gdk3/stable/gdk3-Wayland-Interaction.html
https://developer.gnome.org/gdk3/stable/gdk3-X-Window-System-Interaction.html

   - Include the backend specific headers: gdk/gdkx.h, gdk/gdkwayland.h
   - Link with backend specific libs: gdk-x11-3.0.pc, gdk-wayland-3.0.pc
   - Check the backend for the default display: if
   (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { /*...*/ }

Here is an example:

/* compile with
cc -o print-gdk-backend print-gdk-backend.c \
$(pkg-config --cflags --libs gtk+-3.0 gdk-x11-3.0 gdk-wayland-3.0)
*/

#include <gtk/gtk.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
#ifdef GDK_WINDOWING_WAYLAND
#include <gdk/gdkwayland.h>
#endif
/*
   GDK_WINDOWING macros are defined in header
   /usr/include/gtk-3.0/gdk/gdkconfig.h
*/

int main() {
  gtk_init(NULL, NULL);

#ifdef GDK_WINDOWING_X11
  if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
    g_print("X11 backend\n");
  }
#endif
#ifdef GDK_WINDOWING_WAYLAND
  if (GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default())) {
    g_print("Wayland backend\n");
  }
#endif

  return 0;
}


Il giorno gio 7 feb 2019 alle ore 06:28 Daniel Kasak via gtk-app-devel-list
<[hidden email]> ha scritto:

> Hi all. Is there a way to detect the gdk backend an app is using? I know
> about the environment variable - GDK_BACKEND. But often this is not set,
> and gtk just picks whatever's available. I need ever-so-slightly different
> app behaviour, depending on the backend. Any ideas?
>
> Dan
> _______________________________________________
> gtk-app-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Detecting the gdk backend

rastersoft
In reply to this post by Gtk+ - Apps Dev mailing list
Hi:

You have the GDK_IS_WAYLAND_DISPLAY() C macro. You have an example in my
program Terminus ( https://gitlab.com/rastersoft/terminus ), in the
'checkwayland.c' and 'checkwayland.vapi' files (which is also an example
of how to do it in Vala, BTW).

El 8/2/19 a las 6:28, Daniel Kasak via gtk-app-devel-list escribió:

> Hi all. Is there a way to detect the gdk backend an app is using? I know
> about the environment variable - GDK_BACKEND. But often this is not set,
> and gtk just picks whatever's available. I need ever-so-slightly different
> app behaviour, depending on the backend. Any ideas?
>
> Dan
> _______________________________________________
> gtk-app-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
--
Nos leemos
                         RASTER    (Linux user #228804)
[hidden email]              http://www.rastersoft.com

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list