Codebase list xapp / 20331be
xapp-status-icon: Add new properties for menu/button state handling and one for metadata (miscellaneous info to help define behavior in the status applets). - Add 'PrimaryMenuIsOpen' and 'SecondaryMenuIsOpen' so button toggle states can be synced properly. - The metadata is used to be able to tell the applet that both menus should be treated as primary as far as button state is concerned (the default behavior is that highlighting only takes place for primary menus). This is just a json string for now, but could be expanded to express other details without having to expand XAppStatusIcon api. Michael Webster 3 years ago
3 changed file(s) with 102 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
2727 <property type='s' name='Label' access='read'/>
2828 <property type='b' name='Visible' access='read'/>
2929 <property type='i' name='IconSize' access='readwrite'/>
30 <property type='b' name='PrimaryMenuIsOpen' access='read'/>
31 <property type='b' name='SecondaryMenuIsOpen' access='read'/>
32 <property type='s' name='Metadata' access='read' />
3033 </interface>
3134 </node>
8383 gchar *label;
8484 gboolean visible;
8585 gint icon_size;
86 gchar *metadata;
8687
8788 guint owner_id;
8889 guint listener_id;
254255 }
255256
256257 static void
258 primary_menu_unmapped (GtkWidget *widget,
259 gpointer user_data)
260 {
261 g_return_if_fail (XAPP_IS_STATUS_ICON (user_data));
262 XAppStatusIcon *icon = XAPP_STATUS_ICON (user_data);
263
264 g_debug ("XAppStatusIcon: Primary menu unmapped");
265
266 if (icon->priv->state == XAPP_STATUS_ICON_STATE_NATIVE)
267 {
268 xapp_status_icon_interface_set_primary_menu_is_open (icon->priv->skeleton, FALSE);
269 }
270
271 g_signal_handlers_disconnect_by_func (widget, primary_menu_unmapped, icon);
272 }
273
274 static void
275 secondary_menu_unmapped (GtkWidget *widget,
276 gpointer user_data)
277 {
278 g_return_if_fail (XAPP_IS_STATUS_ICON (user_data));
279 XAppStatusIcon *icon = XAPP_STATUS_ICON (user_data);
280
281 g_debug ("XAppStatusIcon: Secondary menu unmapped");
282
283 if (icon->priv->state == XAPP_STATUS_ICON_STATE_NATIVE)
284 {
285 xapp_status_icon_interface_set_secondary_menu_is_open (icon->priv->skeleton, FALSE);
286 }
287
288 g_signal_handlers_disconnect_by_func (widget, secondary_menu_unmapped, icon);
289 }
290
291 static void
257292 popup_menu (XAppStatusIcon *self,
258293 GtkMenu *menu,
259294 gint x,
286321 * can use for themes to restore things bit if we want. Just avoid shadows. */
287322 gtk_style_context_remove_class (context, "csd");
288323 gtk_style_context_add_class (context, "xapp-status-icon-menu-window");
324 }
325
326 if (button == GDK_BUTTON_PRIMARY)
327 {
328 if (self->priv->state == XAPP_STATUS_ICON_STATE_NATIVE)
329 {
330 xapp_status_icon_interface_set_primary_menu_is_open (self->priv->skeleton, TRUE);
331 }
332
333 g_signal_connect (gtk_widget_get_toplevel (GTK_WIDGET (menu)),
334 "unmap",
335 G_CALLBACK (primary_menu_unmapped),
336 self);
337 }
338 else
339 if (button == GDK_BUTTON_SECONDARY)
340 {
341 if (self->priv->state == XAPP_STATUS_ICON_STATE_NATIVE)
342 {
343 xapp_status_icon_interface_set_secondary_menu_is_open (self->priv->skeleton, TRUE);
344 }
345
346 g_signal_connect (gtk_widget_get_toplevel (GTK_WIDGET (menu)),
347 "unmap",
348 G_CALLBACK (secondary_menu_unmapped),
349 self);
289350 }
290351
291352 event = synthesize_event (self,
673734 "icon-name", priv->icon_name,
674735 "tooltip-text", priv->tooltip_text,
675736 "visible", priv->visible,
737 "metadata", priv->metadata,
676738 NULL);
677739
678740 g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (priv->skeleton));
17421804 }
17431805
17441806 /**
1807 * xapp_status_icon_set_metadata:
1808 * @icon: an #XAppStatusIcon
1809 * @metadata: (nullable): A json-formatted string of key:values.
1810 *
1811 * Sets metadata to pass to the icon proxy for an applet's use. Right now this is only so
1812 * xapp-sn-watcher can tell the applets when the icon is originating from appindicator so panel
1813 * button 'highlighting' can behave correctly.
1814 *
1815 * Since: 1.8.7
1816 */
1817 void
1818 xapp_status_icon_set_metadata (XAppStatusIcon *icon,
1819 const gchar *metadata)
1820 {
1821 g_return_if_fail (XAPP_IS_STATUS_ICON (icon));
1822 gchar *old_meta;
1823
1824 g_debug ("XAppStatusIcon set_metadata: '%s'", metadata);
1825
1826 if (g_strcmp0 (metadata, icon->priv->metadata) == 0)
1827 {
1828 return;
1829 }
1830
1831 old_meta = icon->priv->metadata;
1832 icon->priv->metadata = g_strdup (metadata);
1833 g_free (old_meta);
1834
1835 if (icon->priv->skeleton)
1836 {
1837 xapp_status_icon_interface_set_metadata (icon->priv->skeleton, metadata);
1838 }
1839 }
1840
1841 /**
17451842 * xapp_status_icon_any_monitors:
17461843 *
17471844 * Looks for the existence of any active #XAppStatusIconMonitors on the bus.
6565 void xapp_status_icon_set_secondary_menu (XAppStatusIcon *icon, GtkMenu *menu);
6666 GtkWidget *xapp_status_icon_get_secondary_menu (XAppStatusIcon *icon);
6767 XAppStatusIconState xapp_status_icon_get_state (XAppStatusIcon *icon);
68 void xapp_status_icon_set_metadata (XAppStatusIcon *icon,
69 const gchar *metadata);
6870
6971 /* static */
7072 gboolean xapp_status_icon_any_monitors (void);