diff --git a/src/cpicker.c b/src/cpicker.c index 261424b..4fd89fc 100644 --- a/src/cpicker.c +++ b/src/cpicker.c @@ -23,6 +23,16 @@ #include "cpicker.h" +#include /* For _() macro */ + +/* Forward declaration - defined in main.c when building yad */ +gboolean yad_check_x11 (void); + +/* Weak symbol: if yad_check_x11 doesn't exist (tools build), return TRUE for X11 */ +#ifdef __GNUC__ +gboolean __attribute__((weak)) yad_check_x11 (void) { return TRUE; } +#endif + #define BIG_STEP 20 typedef struct { @@ -215,6 +225,15 @@ yad_get_screen_color (GtkWidget *widget) GdkGrabStatus grab_status; GdkWindow *window; + /* Color picking doesn't work on Wayland - screen capture and device grab are restricted */ + if (!yad_check_x11 ()) + { + g_printerr (_("WARNING: Color picker is not supported on Wayland.\n" + "Screen capture and pointer grab require X11 or a portal.\n" + "Use GDK_BACKEND=x11 to enable color picking.\n")); + return; + } + gd = g_new0 (GrabData, 1); gd->color_widget = widget; gd->time = gtk_get_current_event_time (); diff --git a/src/main.c b/src/main.c index 1bfce7e..c397c59 100644 --- a/src/main.c +++ b/src/main.c @@ -56,6 +56,12 @@ static gboolean is_x11 = FALSE; YadNTabs *tabs; +gboolean +yad_check_x11 (void) +{ + return is_x11; +} + #ifndef G_OS_WIN32 static void sa_usr1 (gint sig) diff --git a/src/print.c b/src/print.c index c7f61cb..5e7183f 100644 --- a/src/print.c +++ b/src/print.c @@ -284,7 +284,11 @@ yad_print_run (void) if (options.data.center) gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER); else if (options.data.mouse) - gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE); + { + /* Mouse positioning doesn't work on Wayland */ + if (yad_check_x11 ()) + gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE); + } /* create yad's top box */ if (options.data.dialog_text || options.data.dialog_image) diff --git a/src/yad.h b/src/yad.h index 6f39282..dd214d9 100644 --- a/src/yad.h +++ b/src/yad.h @@ -714,6 +714,8 @@ gboolean yad_send_notify (gboolean); void notebook_close_childs (void); void paned_close_childs (void); +gboolean yad_check_x11 (void); + void read_settings (void); void write_settings (void);