Skip to content

Commit

Permalink
avoid X-specific calls under Wayland (fixes #412)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Aug 5, 2022
1 parent e6f2918 commit 4784c5d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/desktop/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifdef DESKTOP_INTEGRATION

#include <gtk/gtk.h>
#include <gdk/gdkx.h>
//#include "fm-desktop.h"

#include "vfs-file-info.h"
Expand Down Expand Up @@ -74,6 +75,12 @@ void fm_turn_on_desktop_icons(gboolean transparent)
gint i;
int big = 0;

gdpy = gdk_display_get_default();
#if GTK_CHECK_VERSION (3, 0, 0)
if( ! GDK_IS_X11_DISPLAY( gdpy ) )
return;
#endif

if( ! group )
group = gtk_window_group_new();

Expand All @@ -82,8 +89,6 @@ void fm_turn_on_desktop_icons(gboolean transparent)

vfs_mime_type_get_icon_size( &big, NULL );

gdpy = gdk_display_get_default();

n_screens = gdk_display_get_n_screens( gdpy );
desktops = g_new( GtkWidget *, n_screens );
for ( i = 0; i < n_screens; i++ )
Expand Down
5 changes: 5 additions & 0 deletions src/desktop/working-area.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
This piece of code detecting working area is got from Guifications, a plug-in for Gaim.
*/

# include <gtk/gtk.h>
# include <gdk/gdk.h>
# include <gdk/gdkx.h>
# include <X11/Xlib.h>
Expand All @@ -43,7 +44,11 @@ gf_display_get_workarea(GdkScreen* g_screen, GdkRectangle *rect) {

/* get the gdk display */
g_display = gdk_display_get_default();
#if GTK_CHECK_VERSION(3, 0, 0)
if(!g_display || !GDK_IS_X11_DISPLAY(g_display))
#else
if(!g_display)
#endif
return FALSE;

/* get the x display from the gdk display */
Expand Down
4 changes: 4 additions & 0 deletions src/main-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -4175,7 +4175,11 @@ static long get_desktop_index( GtkWindow* win )
{
// get current desktop
display = gdk_display_get_default();
#if GTK_CHECK_VERSION (3, 0, 0)
if ( display && GDK_IS_X11_DISPLAY (display ) )
#else
if ( display )
#endif
window = gdk_x11_window_lookup_for_display( display,
gdk_x11_get_default_root_xwindow() );
}
Expand Down
21 changes: 16 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,23 @@ gboolean on_socket_event( GIOChannel* ioc, GIOCondition cond, gpointer data )

void get_socket_name_nogdk( char* buf, int len )
{
char* dpy = g_strdup( g_getenv( "DISPLAY" ) );
if ( dpy && !strcmp( dpy, ":0.0" ) )
char* dpy;
#if GTK_CHECK_VERSION(3, 0, 0)
const char* tmp = g_getenv( "WAYLAND_DISPLAY" );
if ( tmp )
dpy = g_strdup( tmp );
else
#else
if ( TRUE )
#endif
{
// treat :0.0 as :0 to prevent multiple instances on screen 0
g_free( dpy );
dpy = g_strdup( ":0" );
dpy = g_strdup( g_getenv( "DISPLAY" ) );
if ( dpy && !strcmp( dpy, ":0.0" ) )
{
// treat :0.0 as :0 to prevent multiple instances on screen 0
g_free( dpy );
dpy = g_strdup( ":0" );
}
}
g_snprintf( buf, len, "%s/.spacefm-socket%s-%s", xset_get_tmp_dir(),
dpy,
Expand Down
24 changes: 23 additions & 1 deletion src/vfs/vfs-execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ tvsn_get_active_workspace_number ( GdkScreen *screen )
gint format_ret;
gint ws_num = 0;

# if GTK_CHECK_VERSION (3, 0, 0)
if ( ! GDK_IS_X11_SCREEN ( screen ) )
return ws_num;
# endif

gdk_error_trap_push ();

root = gdk_screen_get_root_window ( screen );
Expand Down Expand Up @@ -131,7 +136,11 @@ gboolean vfs_exec_on_screen( GdkScreen* screen,
for ( i = 0; i < n_env; ++i )
{
/* g_debug( "old envp[%d] = \"%s\"" , i, envp[i]); */
#if GTK_CHECK_VERSION (3, 0, 0)
if ( ( GDK_IS_X11_SCREEN ( screen ) && 0 == strncmp( envp[ i ], "DISPLAY=", 8 ) ) || ( ( ! GDK_IS_X11_SCREEN ( screen ) ) && ( 0 == strncmp( envp[ i ], "WAYLAND_DISPLAY=", 16 ) ) ) )
#else
if ( 0 == strncmp( envp[ i ], "DISPLAY=", 8 ) )
#endif
display_index = i;
else
{
Expand All @@ -142,7 +151,11 @@ gboolean vfs_exec_on_screen( GdkScreen* screen,
}

#ifdef HAVE_SN
# if GTK_CHECK_VERSION (3, 0, 0)
if ( use_startup_notify && GDK_IS_X11_SCREEN ( screen ) )
# else
if ( use_startup_notify )
# endif
display = sn_display_new ( GDK_SCREEN_XDISPLAY ( screen ),
( SnDisplayErrorTrapPush ) gdk_error_trap_push,
( SnDisplayErrorTrapPush ) gdk_error_trap_pop );
Expand Down Expand Up @@ -182,7 +195,16 @@ gboolean vfs_exec_on_screen( GdkScreen* screen,

/* This is taken from gdk_spawn_on_screen */
display_name = gdk_screen_make_display_name ( screen );
if ( display_index >= 0 )

#if GTK_CHECK_VERSION (3, 0, 0)
if ( ( ! GDK_IS_X11_SCREEN ( screen ) ) && display_index >= 0 )
new_env[ display_index ] = g_strconcat( "WAYLAND_DISPLAY=", display_name, NULL );
if ( ! GDK_IS_X11_SCREEN ( screen ) )
new_env[ i++ ] = g_strconcat( "WAYLAND_DISPLAY=", display_name, NULL );
#else
if ( FALSE ) do {} while ( 0 );
#endif
else if ( display_index >= 0 )
new_env[ display_index ] = g_strconcat( "DISPLAY=", display_name, NULL );
else
new_env[ i++ ] = g_strconcat( "DISPLAY=", display_name, NULL );
Expand Down

0 comments on commit 4784c5d

Please sign in to comment.