3333
3434#include <glib/gi18n-lib.h>
3535#include <cairo.h>
36- #include <cairo-xlib.h>
3736#include <gdk/gdk.h>
38- #include <gdk/gdkx.h>
3937#include <gdk/gdkkeysyms.h>
4038#include <gtk/gtk.h>
39+
40+ #ifdef HAVE_X11
41+ #include <cairo-xlib.h>
42+ #include <gdk/gdkx.h>
4143#include <gtk/gtkx.h>
4244#include <X11/Xatom.h>
45+ #include "panel-plug-private.h"
46+ #endif
4347
4448#include "mate-panel-applet.h"
4549#include "panel-applet-private.h"
4650#include "mate-panel-applet-factory.h"
4751#include "mate-panel-applet-marshal.h"
4852#include "mate-panel-applet-enums.h"
49- #include "panel-plug-private.h"
5053
5154#define MATE_PANEL_APPLET_GET_PRIVATE (o ) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_APPLET, MatePanelAppletPrivate))
5255
@@ -449,6 +452,8 @@ mate_panel_applet_set_locked_down (MatePanelApplet *applet,
449452 g_object_notify (G_OBJECT (applet ), "locked-down" );
450453}
451454
455+ #ifdef HAVE_X11
456+
452457static Atom _net_wm_window_type = None ;
453458static Atom _net_wm_window_type_dock = None ;
454459static Atom _net_active_window = None ;
@@ -533,6 +538,8 @@ mate_panel_applet_find_toplevel_dock_window (MatePanelApplet *applet,
533538 return None ;
534539}
535540
541+ #endif // HAVE_X11
542+
536543/* This function
537544 * 1) Gets the window id of the panel that contains the applet
538545 * using XQueryTree and XGetWindowProperty to find an ancestor
543550mate_panel_applet_request_focus (MatePanelApplet * applet ,
544551 guint32 timestamp )
545552{
553+ #ifdef HAVE_X11
546554 GdkScreen * screen ;
547555 GdkWindow * root ;
548556 GdkDisplay * display ;
@@ -551,6 +559,9 @@ mate_panel_applet_request_focus (MatePanelApplet *applet,
551559 Window xroot ;
552560 XEvent xev ;
553561
562+ if (!GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
563+ return ;
564+
554565 g_return_if_fail (PANEL_IS_APPLET (applet ));
555566
556567 screen = gtk_window_get_screen (GTK_WINDOW (applet -> priv -> plug ));
@@ -582,6 +593,7 @@ mate_panel_applet_request_focus (MatePanelApplet *applet,
582593 xroot , False ,
583594 SubstructureRedirectMask | SubstructureNotifyMask ,
584595 & xev );
596+ #endif
585597}
586598
587599static GtkAction *
@@ -834,16 +846,21 @@ mate_panel_applet_position_menu (GtkMenu *menu,
834846 GtkAllocation allocation ;
835847 GtkRequisition requisition ;
836848 GdkDevice * device ;
849+ GdkMonitor * monitor ;
837850 GdkScreen * screen ;
838851 int menu_x = 0 ;
839852 int menu_y = 0 ;
840853 int pointer_x ;
841854 int pointer_y ;
855+ GdkRectangle screen_geom ;
842856
843857 g_return_if_fail (PANEL_IS_APPLET (widget ));
844858
845859 applet = MATE_PANEL_APPLET (widget );
846860
861+ monitor = gdk_display_get_monitor_at_window (gtk_widget_get_display (widget ), gtk_widget_get_window (widget ));
862+ gdk_monitor_get_geometry (monitor , & screen_geom );
863+
847864 screen = gtk_widget_get_screen (widget );
848865 gtk_menu_set_screen (menu , screen );
849866
@@ -874,19 +891,19 @@ mate_panel_applet_position_menu (GtkMenu *menu,
874891 allocation .width - requisition .width );
875892 }
876893 }
877- menu_x = MIN (menu_x , WidthOfScreen ( gdk_x11_screen_get_xscreen ( screen )) - requisition .width );
894+ menu_x = MIN (menu_x , screen_geom . width - requisition .width );
878895
879- if (menu_y > HeightOfScreen ( gdk_x11_screen_get_xscreen ( screen )) / 2 )
896+ if (menu_y > screen_geom . height / 2 )
880897 menu_y -= requisition .height ;
881898 else
882899 menu_y += allocation .height ;
883900 } else {
884901 if (pointer_y < allocation .height &&
885902 requisition .height < pointer_y )
886903 menu_y += MIN (pointer_y , allocation .height - requisition .height );
887- menu_y = MIN (menu_y , HeightOfScreen ( gdk_x11_screen_get_xscreen ( screen )) - requisition .height );
904+ menu_y = MIN (menu_y , screen_geom . height - requisition .height );
888905
889- if (menu_x > WidthOfScreen ( gdk_x11_screen_get_xscreen ( screen )) / 2 )
906+ if (menu_x > screen_geom . width / 2 )
890907 menu_x -= requisition .width ;
891908 else
892909 menu_x += allocation .width ;
@@ -947,6 +964,7 @@ static gboolean
947964mate_panel_applet_button_event (MatePanelApplet * applet ,
948965 GdkEventButton * event )
949966{
967+ #ifdef HAVE_X11
950968 GtkWidget * widget ;
951969 GdkWindow * window ;
952970 GdkWindow * socket_window ;
@@ -966,6 +984,9 @@ mate_panel_applet_button_event (MatePanelApplet *applet,
966984
967985 display = gdk_display_get_default ();
968986
987+ if (!GDK_IS_X11_DISPLAY (display ))
988+ return FALSE;
989+
969990 if (event -> type == GDK_BUTTON_PRESS ) {
970991 GdkSeat * seat ;
971992
@@ -1009,6 +1030,9 @@ mate_panel_applet_button_event (MatePanelApplet *applet,
10091030 gdk_x11_display_error_trap_pop_ignored (display );
10101031
10111032 return TRUE;
1033+ #else
1034+ return FALSE;
1035+ #endif
10121036}
10131037
10141038static gboolean
@@ -1251,6 +1275,7 @@ mate_panel_applet_parse_color (const gchar *color_str,
12511275 return gdk_rgba_parse (color , color_str );
12521276}
12531277
1278+ #ifdef HAVE_X11
12541279static gboolean
12551280mate_panel_applet_parse_pixmap_str (const char * str ,
12561281 Window * xid ,
@@ -1378,6 +1403,7 @@ mate_panel_applet_get_pattern_from_pixmap (MatePanelApplet *applet,
13781403
13791404 return pattern ;
13801405}
1406+ #endif
13811407
13821408static MatePanelAppletBackgroundType
13831409mate_panel_applet_handle_background_string (MatePanelApplet * applet ,
@@ -1410,27 +1436,34 @@ mate_panel_applet_handle_background_string (MatePanelApplet *applet,
14101436 retval = PANEL_COLOR_BACKGROUND ;
14111437
14121438 } else if (elements [0 ] && !strcmp (elements [0 ], "pixmap" )) {
1413- Window pixmap_id ;
1414- int x , y ;
1439+ #ifdef HAVE_X11
1440+ if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) {
1441+ Window pixmap_id ;
1442+ int x , y ;
14151443
1416- g_return_val_if_fail (pattern != NULL , PANEL_NO_BACKGROUND );
1444+ g_return_val_if_fail (pattern != NULL , PANEL_NO_BACKGROUND );
14171445
1418- if (!mate_panel_applet_parse_pixmap_str (elements [1 ], & pixmap_id , & x , & y )) {
1419- g_warning ("Incomplete '%s' background type received: %s" ,
1420- elements [0 ], elements [1 ]);
1446+ if (!mate_panel_applet_parse_pixmap_str (elements [1 ], & pixmap_id , & x , & y )) {
1447+ g_warning ("Incomplete '%s' background type received: %s" ,
1448+ elements [0 ], elements [1 ]);
14211449
1422- g_strfreev (elements );
1423- return PANEL_NO_BACKGROUND ;
1424- }
1450+ g_strfreev (elements );
1451+ return PANEL_NO_BACKGROUND ;
1452+ }
14251453
1426- * pattern = mate_panel_applet_get_pattern_from_pixmap (applet , pixmap_id , x , y );
1427- if (!* pattern ) {
1428- g_warning ("Failed to get pattern %s" , elements [1 ]);
1429- g_strfreev (elements );
1430- return PANEL_NO_BACKGROUND ;
1431- }
1454+ * pattern = mate_panel_applet_get_pattern_from_pixmap (applet , pixmap_id , x , y );
1455+ if (!* pattern ) {
1456+ g_warning ("Failed to get pattern %s" , elements [1 ]);
1457+ g_strfreev (elements );
1458+ return PANEL_NO_BACKGROUND ;
1459+ }
14321460
1433- retval = PANEL_PIXMAP_BACKGROUND ;
1461+ retval = PANEL_PIXMAP_BACKGROUND ;
1462+ } else
1463+ #endif
1464+ { // not using X11
1465+ g_warning ("Received pixmap background type, which is only supported on X11" );
1466+ }
14341467 } else
14351468 g_warning ("Unknown background type received" );
14361469
@@ -1852,6 +1885,14 @@ mate_panel_applet_constructor (GType type,
18521885 if (!applet -> priv -> out_of_process )
18531886 return object ;
18541887
1888+ #ifdef HAVE_X11
1889+ if (!GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
1890+ #endif
1891+ { // not using X11
1892+ g_warning ("Requested construction of an out-of-process applet, which is only possible on X11" );
1893+ return object ;
1894+ }
1895+
18551896 applet -> priv -> plug = gtk_plug_new (0 );
18561897
18571898 GdkScreen * screen = gtk_widget_get_screen (GTK_WIDGET (applet -> priv -> plug ));
@@ -2239,6 +2280,7 @@ static void mate_panel_applet_factory_main_finalized(gpointer data, GObject* obj
22392280 }
22402281}
22412282
2283+ #ifdef HAVE_X11
22422284static int (* _x_error_func ) (Display * , XErrorEvent * );
22432285
22442286static int
@@ -2287,6 +2329,7 @@ _mate_panel_applet_setup_x_error_handler (void)
22872329
22882330 _x_error_func = XSetErrorHandler (_x_error_handler );
22892331}
2332+ #endif
22902333
22912334static int
22922335_mate_panel_applet_factory_main_internal (const gchar * factory_id ,
@@ -2303,12 +2346,21 @@ _mate_panel_applet_factory_main_internal (const gchar *factory_id,
23032346 g_return_val_if_fail (callback != NULL , 1 );
23042347 g_assert (g_type_is_a (applet_type , PANEL_TYPE_APPLET ));
23052348
2306- /*Use this both in and out of process as the tray applet always uses GtkSocket
2307- *to handle GtkStatusIcons whether the tray itself is built in or out of process
2308- */
2309-
2310- _mate_panel_applet_setup_x_error_handler ();
23112349
2350+ #ifdef HAVE_X11
2351+ if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) {
2352+ /*Use this both in and out of process as the tray applet always uses GtkSocket
2353+ *to handle GtkStatusIcons whether the tray itself is built in or out of process
2354+ */
2355+ _mate_panel_applet_setup_x_error_handler ();
2356+ } else
2357+ #endif
2358+ { // not using X11
2359+ if (out_process ) {
2360+ g_warning ("Requested out-of-process applet, which is only supported on X11" );
2361+ return 1 ;
2362+ }
2363+ }
23122364
23132365 closure = g_cclosure_new (G_CALLBACK (callback ), user_data , NULL );
23142366 factory = mate_panel_applet_factory_new (factory_id , out_process , applet_type , closure );
@@ -2370,7 +2422,6 @@ mate_panel_applet_factory_setup_in_process (const gchar *factory_i
23702422 callback , user_data );
23712423}
23722424
2373-
23742425/**
23752426 * mate_panel_applet_set_background_widget:
23762427 * @applet: a #PanelApplet.
@@ -2393,13 +2444,18 @@ guint32
23932444mate_panel_applet_get_xid (MatePanelApplet * applet ,
23942445 GdkScreen * screen )
23952446{
2447+ // out_of_process should only be true on X11, so an extra runtime Wayland check is not needed
23962448 if (applet -> priv -> out_of_process == FALSE)
23972449 return 0 ;
23982450
2451+ #ifdef HAVE_X11
23992452 gtk_window_set_screen (GTK_WINDOW (applet -> priv -> plug ), screen );
24002453 gtk_widget_show (applet -> priv -> plug );
24012454
24022455 return gtk_plug_get_id (GTK_PLUG (applet -> priv -> plug ));
2456+ #else
2457+ return 0 ;
2458+ #endif
24032459}
24042460
24052461const gchar *
0 commit comments