diff options
author | lukefromdc <[email protected]> | 2023-06-20 01:35:12 -0400 |
---|---|---|
committer | raveit65 <[email protected]> | 2023-07-17 02:47:28 +0200 |
commit | ce52935ec89bacd417ca6065012986e83a920f48 (patch) | |
tree | 282e8fa40b6589f831c24e9f894d8872d7d3575d /stickynotes | |
parent | 6133a03263321ab85fae9299968a8f069b3dfad5 (diff) | |
download | mate-applets-ce52935ec89bacd417ca6065012986e83a920f48.tar.bz2 mate-applets-ce52935ec89bacd417ca6065012986e83a920f48.tar.xz |
stickynotes: port to in-process for wayland
- Note that functions involving measuring or clicking on the desktop
- Are x11 only as wayland does not allow one app to access another's windows
- Fix warnings on removal of applet
- use wnck only in x11
- Cleanup X11 checks
Diffstat (limited to 'stickynotes')
-rw-r--r-- | stickynotes/Makefile.am | 28 | ||||
-rw-r--r-- | stickynotes/org.mate.applets.StickyNotesApplet.mate-panel-applet.desktop.in.in | 4 | ||||
-rw-r--r-- | stickynotes/org.mate.panel.applet.StickyNotesAppletFactory.service.in | 3 | ||||
-rw-r--r-- | stickynotes/stickynotes.c | 54 | ||||
-rw-r--r-- | stickynotes/stickynotes_applet.c | 20 | ||||
-rw-r--r-- | stickynotes/stickynotes_applet_callbacks.c | 77 | ||||
-rw-r--r-- | stickynotes/stickynotes_applet_callbacks.h | 2 | ||||
-rw-r--r-- | stickynotes/util.c | 9 |
8 files changed, 112 insertions, 85 deletions
diff --git a/stickynotes/Makefile.am b/stickynotes/Makefile.am index 514c92eb..2057f587 100644 --- a/stickynotes/Makefile.am +++ b/stickynotes/Makefile.am @@ -1,5 +1,11 @@ +NULL = + +APPLET_LOCATION = $(libdir)/mate-applets/libmate-stickynotes-applet.so + SUBDIRS = pixmaps docs +mate_stickynotes_applet_libdir= $(pkglibdir) +mate_stickynotes_applet_lib_LTLIBRARIES=libmate-stickynotes-applet.la applet_in_files = org.mate.applets.StickyNotesApplet.mate-panel-applet.desktop.in service_in_files = org.mate.panel.applet.StickyNotesAppletFactory.service.in schemas_in_files = stickynotes.schemas.in @@ -16,9 +22,7 @@ AM_CPPFLAGS = \ ${WARN_CFLAGS} \ $(NULL) -libexec_PROGRAMS = stickynotes-applet - -stickynotes_applet_SOURCES = \ +libmate_stickynotes_applet_la_SOURCES = \ util.h \ util.c \ stickynotes.h \ @@ -33,7 +37,7 @@ stickynotes_applet_SOURCES = \ sticky-notes-resources.h \ $(NULL) -stickynotes_applet_LDADD = \ +libmate_stickynotes_applet_la_LIBADD = \ $(STICKYNOTES_LIBS) \ $(MATE_APPLETS4_LIBS) \ $(LIBWNCK_LIBS) \ @@ -56,25 +60,16 @@ applet_DATA = $(applet_in_files:.mate-panel-applet.desktop.in=.mate-panel-applet $(applet_in_files): $(applet_in_files:=.in) Makefile $(AM_V_GEN)sed \ - -e "s|\@LIBEXECDIR\@|$(libexecdir)|" \ - -e "s|\@VERSION\@|$(PACKAGE_VERSION)|" \ - $< > $@ + -e "s|\@APPLET_LOCATION\@|$(APPLET_LOCATION)|" \ + -e "s|\@VERSION\@|$(PACKAGE_VERSION)|" \ + $< > $@ $(applet_DATA): $(applet_in_files) Makefile $(AM_V_GEN) $(MSGFMT) --desktop --keyword=Name --keyword=Description --template $< -d $(top_srcdir)/po -o $@ -servicedir = $(datadir)/dbus-1/services -service_DATA = $(service_in_files:.service.in=.service) - -org.mate.panel.applet.StickyNotesAppletFactory.service: $(service_in_files) - $(AM_V_GEN)sed \ - -e "s|\@LIBEXECDIR\@|$(libexecdir)|" \ - $< > $@ - CLEANFILES = \ $(applet_DATA) \ $(applet_in_files) \ - $(service_DATA) \ $(gsettings_SCHEMAS) \ sticky-notes-resources.c \ sticky-notes-resources.h \ @@ -85,7 +80,6 @@ endif EXTRA_DIST = \ $(stickynotes_gschema_in_files) \ - $(service_in_files) \ $(applet_in_files:=.in) \ sticky-notes-delete.ui \ sticky-notes-delete-all.ui \ diff --git a/stickynotes/org.mate.applets.StickyNotesApplet.mate-panel-applet.desktop.in.in b/stickynotes/org.mate.applets.StickyNotesApplet.mate-panel-applet.desktop.in.in index 7e0725cf..097a8fdd 100644 --- a/stickynotes/org.mate.applets.StickyNotesApplet.mate-panel-applet.desktop.in.in +++ b/stickynotes/org.mate.applets.StickyNotesApplet.mate-panel-applet.desktop.in.in @@ -1,6 +1,7 @@ [Applet Factory] Id=StickyNotesAppletFactory -Location=@LIBEXECDIR@/stickynotes-applet +Location=@APPLET_LOCATION@ +InProcess=true Name=Sticky Notes Applet Factory Description=Sticky Notes Applet Factory @@ -10,6 +11,7 @@ Description=Create, view, and manage sticky notes on the desktop # Translators: Do NOT translate or transliterate this text (this is an icon file name)! Icon=mate-sticky-notes-applet MateComponentId=OAFIID:MATE_StickyNotesApplet +Platforms=X11;Wayland; X-MATE-Bugzilla-Bugzilla=MATE X-MATE-Bugzilla-Product=mate-applets X-MATE-Bugzilla-Component=stickynotes diff --git a/stickynotes/org.mate.panel.applet.StickyNotesAppletFactory.service.in b/stickynotes/org.mate.panel.applet.StickyNotesAppletFactory.service.in deleted file mode 100644 index 593c29c0..00000000 --- a/stickynotes/org.mate.panel.applet.StickyNotesAppletFactory.service.in +++ /dev/null @@ -1,3 +0,0 @@ -[D-BUS Service] -Name=org.mate.panel.applet.StickyNotesAppletFactory -Exec=@LIBEXECDIR@/stickynotes-applet diff --git a/stickynotes/stickynotes.c b/stickynotes/stickynotes.c index 255fb677..3f5c7985 100644 --- a/stickynotes/stickynotes.c +++ b/stickynotes/stickynotes.c @@ -809,12 +809,10 @@ stickynotes_remove (StickyNote *note) gboolean stickynotes_save_now (void) { - WnckScreen *wnck_screen; const gchar *title; GtkTextBuffer *buffer; GtkTextIter start, end; gchar *body; - gint i; /* Create a new XML document */ @@ -823,14 +821,16 @@ stickynotes_save_now (void) xmlDocSetRootElement (doc, root); xmlNewProp (root, XML_CHAR ("version"), XML_CHAR (VERSION)); - - wnck_screen = wnck_screen_get_default (); - wnck_screen_force_update (wnck_screen); - +#ifdef GDK_WINDOWING_X11 + GdkDisplay *display = gdk_screen_get_display(gdk_screen_get_default()); + if (GDK_IS_X11_DISPLAY(display)) + { + WnckScreen *wnck_screen = wnck_screen_get_default (); + wnck_screen_force_update (wnck_screen); + } +#endif /* For all sticky notes */ for (i = 0; i < g_list_length (stickynotes->notes); i++) { - WnckWindow *wnck_win; - gulong xid = 0; /* Access the current note in the list */ StickyNote *note = g_list_nth_data (stickynotes->notes, i); @@ -842,16 +842,19 @@ stickynotes_save_now (void) /* Retrieve the window position of the note */ gchar *x_str = g_strdup_printf ("%d", note->x); gchar *y_str = g_strdup_printf ("%d", note->y); - - xid = GDK_WINDOW_XID (gtk_widget_get_window (note->w_window)); - wnck_win = wnck_window_get (xid); - - if (!g_settings_get_boolean (stickynotes->settings, "sticky") && wnck_win) - note->workspace = 1 + - wnck_workspace_get_number (wnck_window_get_workspace (wnck_win)); - else - note->workspace = 0; - +#ifdef GDK_WINDOWING_X11 + if (GDK_IS_X11_DISPLAY(display)) + { + gulong xid = GDK_WINDOW_XID (gtk_widget_get_window (note->w_window)); + WnckWindow *wnck_win = wnck_window_get (xid); + + if (!g_settings_get_boolean (stickynotes->settings, "sticky") && wnck_win) + note->workspace = 1 + + wnck_workspace_get_number (wnck_window_get_workspace (wnck_win)); + else + note->workspace = 0; + } +#endif /* Retrieve the title of the note */ title = gtk_label_get_text (GTK_LABEL (note->w_title)); @@ -948,10 +951,12 @@ stickynotes_load (GdkScreen *screen) xmlDocPtr doc = NULL; xmlNodePtr root; xmlNodePtr node; - /* WnckScreen *wnck_screen; */ GList *new_notes, *tmp1; /* Lists of StickyNote*'s */ GList *new_nodes; /* Lists of xmlNodePtr's */ int x, y, w, h; +#ifdef GDK_WINDOWING_X11 + GdkDisplay *display = gdk_screen_get_display(gdk_screen_get_default()); +#endif /* The XML file is $HOME/.config/mate/stickynotes-applet, most probably */ gchar* file = g_build_filename (g_get_user_config_dir (), @@ -1123,11 +1128,14 @@ stickynotes_load (GdkScreen *screen) } tmp1 = new_notes; - /* - wnck_screen = wnck_screen_get_default (); - wnck_screen_force_update (wnck_screen); - */ +#ifdef GDK_WINDOWING_X11 + if (GDK_IS_X11_DISPLAY(display)) + { + WnckScreen *wnck_screen = wnck_screen_get_default (); + wnck_screen_force_update (wnck_screen); + } +#endif while (tmp1) { StickyNote *note = tmp1->data; diff --git a/stickynotes/stickynotes_applet.c b/stickynotes/stickynotes_applet.c index fd903e1e..88785fb3 100644 --- a/stickynotes/stickynotes_applet.c +++ b/stickynotes/stickynotes_applet.c @@ -84,7 +84,7 @@ stickynotes_applet_factory (MatePanelApplet *mate_panel_applet, } /* Sticky Notes applet factory */ -MATE_PANEL_APPLET_OUT_PROCESS_FACTORY ("StickyNotesAppletFactory", +MATE_PANEL_APPLET_IN_PROCESS_FACTORY ("StickyNotesAppletFactory", PANEL_TYPE_APPLET, "stickynotes_applet", stickynotes_applet_factory, @@ -167,6 +167,7 @@ stickynotes_applet_init (MatePanelApplet *mate_panel_applet) cairo_t *cr; gint size, scale; int screen_height; + GdkScreen *screen; stickynotes = g_new (StickyNotes, 1); @@ -177,7 +178,6 @@ stickynotes_applet_init (MatePanelApplet *mate_panel_applet) size = mate_panel_applet_get_size (mate_panel_applet); scale = gtk_widget_get_scale_factor (GTK_WIDGET (mate_panel_applet)); - g_set_application_name (_("Sticky Notes")); gtk_window_set_default_icon_name ("mate-sticky-notes-applet"); stickynotes->icon_normal = @@ -208,14 +208,22 @@ stickynotes_applet_init (MatePanelApplet *mate_panel_applet) g_signal_connect (stickynotes->settings, "changed", G_CALLBACK (preferences_apply_cb), NULL); - /* Max height for large notes*/ - screen_height = HeightOfScreen (gdk_x11_screen_get_xscreen (gdk_screen_get_default ())); + /* Max height for large notes in x11 only + * In wayland we do not have access to global screen dimensions + */ + + screen = gtk_widget_get_screen (GTK_WIDGET (mate_panel_applet)); +#ifdef GDK_WINDOWING_X11 + if (GDK_IS_X11_DISPLAY (gdk_screen_get_display (screen))) + screen_height = HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale; +#endif + stickynotes->max_height = (int) (0.8 * (double) screen_height); /* Load sticky notes */ - stickynotes_load (gtk_widget_get_screen (GTK_WIDGET (mate_panel_applet))); + stickynotes_load (screen); - install_check_click_on_desktop (); + install_check_click_on_desktop (screen); } void diff --git a/stickynotes/stickynotes_applet_callbacks.c b/stickynotes/stickynotes_applet_callbacks.c index d3061a17..80024e4a 100644 --- a/stickynotes/stickynotes_applet_callbacks.c +++ b/stickynotes/stickynotes_applet_callbacks.c @@ -25,34 +25,6 @@ #include <X11/Xatom.h> #include <gdk/gdkx.h> -static gboolean get_desktop_window (Window *window) -{ - Window *desktop_window; - GdkWindow *root_window; - GdkAtom type_returned; - int format_returned; - int length_returned; - - root_window = gdk_screen_get_root_window (gdk_screen_get_default ()); - - if (gdk_property_get (root_window, - gdk_atom_intern ("CAJA_DESKTOP_WINDOW_ID", FALSE), - gdk_x11_xatom_to_atom (XA_WINDOW), - 0, 4, FALSE, - &type_returned, - &format_returned, - &length_returned, - (guchar**) &desktop_window)) { - *window = *desktop_window; - g_free (desktop_window); - return TRUE; - } - else { - *window = 0; - return FALSE; - } -} - static void popup_add_note (StickyNotesApplet *applet, GtkWidget *item) @@ -145,6 +117,35 @@ applet_focus_cb (GtkWidget *widget, return FALSE; } +#ifdef GDK_WINDOWING_X11 +static gboolean get_desktop_window (GdkScreen *screen, Window *window) +{ + Window *desktop_window; + GdkWindow *root_window; + GdkAtom type_returned; + int format_returned; + int length_returned; + + root_window = gdk_screen_get_root_window (screen); + + if (gdk_property_get (root_window, + gdk_atom_intern ("CAJA_DESKTOP_WINDOW_ID", FALSE), + gdk_x11_xatom_to_atom (XA_WINDOW), + 0, 4, FALSE, + &type_returned, + &format_returned, + &length_returned, + (guchar**) &desktop_window)) { + *window = *desktop_window; + g_free (desktop_window); + return TRUE; + } + else { + *window = 0; + return FALSE; + } +} + static GdkFilterReturn desktop_window_event_filter (GdkXEvent *xevent, GdkEvent *event, @@ -159,22 +160,31 @@ desktop_window_event_filter (GdkXEvent *xevent, } return GDK_FILTER_CONTINUE; } +#endif /* GDK_WINDOWING_X11 */ -void install_check_click_on_desktop (void) +void install_check_click_on_desktop (GdkScreen *screen) { +#ifdef GDK_WINDOWING_X11 Window desktop_window; GdkWindow *window; Atom user_time_window; Atom user_time; + GdkDisplay *display; - if (!get_desktop_window (&desktop_window)) { + display = gdk_screen_get_display (screen); + /* All this uses X11-only APIs and features */ + if (!GDK_IS_X11_DISPLAY (display)) + return; + + if (!get_desktop_window (screen, &desktop_window)) { return; } /* Access the desktop window. desktop_window is the root window for the - * default screen, so we know using gdk_display_get_default () is correct. */ - window = gdk_x11_window_foreign_new_for_display (gdk_display_get_default (), - desktop_window); + * default screen, so we know using gdk_display_get_default () is correct. + * This code should not be reached if running in wayland + */ + window = gdk_x11_window_foreign_new_for_display (display, desktop_window); /* Avoid crash if the desktop window ID is set but invalid, e.g. if * Caja has set it but quit since then */ @@ -217,6 +227,7 @@ void install_check_click_on_desktop (void) gdk_window_set_events (window, GDK_PROPERTY_CHANGE_MASK); gdk_window_add_filter (window, desktop_window_event_filter, NULL); +#endif } /* Applet Callback : Change the panel orientation. */ diff --git a/stickynotes/stickynotes_applet_callbacks.h b/stickynotes/stickynotes_applet_callbacks.h index 1ae2768e..a8504578 100644 --- a/stickynotes/stickynotes_applet_callbacks.h +++ b/stickynotes/stickynotes_applet_callbacks.h @@ -41,7 +41,7 @@ applet_focus_cb (GtkWidget *widget, StickyNotesApplet *applet); void -install_check_click_on_desktop (void); +install_check_click_on_desktop (GdkScreen *screen); void applet_change_orient_cb (MatePanelApplet *mate_panel_applet, MatePanelAppletOrient orient, diff --git a/stickynotes/util.c b/stickynotes/util.c index b5faf292..d13f9f41 100644 --- a/stickynotes/util.c +++ b/stickynotes/util.c @@ -57,6 +57,7 @@ xstuff_atom_get (const char *atom_name) int xstuff_get_current_workspace (GtkWindow *window) { +#ifdef GDK_WINDOWING_X11 Window root_window; Atom type = None; gulong nitems; @@ -68,8 +69,11 @@ xstuff_get_current_workspace (GtkWindow *window) GdkDisplay *gdk_display; Display *xdisplay; - root_window = GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (window))); gdk_display = gdk_display_get_default (); + if (!GDK_IS_X11_DISPLAY (gdk_display)) + return -1; + + root_window = GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (window))); xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display); gdk_x11_display_error_trap_push (gdk_display); @@ -93,6 +97,9 @@ xstuff_get_current_workspace (GtkWindow *window) XFree (num); return retval; +#else + return -1; +#endif } void xstuff_change_workspace (GtkWindow *window, |