Package: workrave
Version: 1.10.44-7
Severity: important
Tags: patch upstream fixed-upstream
Control: forwarded -1 https://github.com/rcaelers/workrave/issues/281

Dear Maintainer,

If the GNOME extension has been enabled, and then one closes then reopens the
GNOME session, the extension crashes at startup, and all extensions are
then disabled.

This bug has been fixed upstream. I attach a patch that is a backport of the
upstream fix (it is not possible to directly apply the upstream commit on
version 1.10.44, because there has been code reformatting in the meantime, but
my patch is functionally identical).

I really think that this issue should be fixed for bullseye, because it makes
workrave mostly unusable on our default desktop environment. Please let me know
if you plan to fix it yourself, or if you prefer me to NMU.

Thanks for your work,

--
⢀⣴⠾⠻⢶⣦⠀  Sébastien Villemot
⣾⠁⢠⠒⠀⣿⡁  Debian Developer
⢿⡄⠘⠷⠚⠋⠀  https://sebastien.villemot.name
⠈⠳⣄⠀⠀⠀⠀  https://www.debian.org
Description: Fix crash in GNOME Shell extension
Origin: backport, 
https://github.com/rcaelers/workrave/commit/56af818cd3e148069134551aacc7b06043d8541a
Bug: https://github.com/rcaelers/workrave/issues/281
Bug-Debian: TBA
Last-Update: 2021-04-14
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/frontend/applets/common/src/timebar.c
+++ b/frontend/applets/common/src/timebar.c
@@ -25,7 +25,7 @@
 static void workrave_timebar_class_init(WorkraveTimebarClass *klass);
 static void workrave_timebar_init(WorkraveTimebar *self);
 
-static void workrave_timebar_init_ui(WorkraveTimebar *self);
+static void workrave_timebar_init_ui(WorkraveTimebar *self, cairo_t *c);
 static void workrave_timebar_draw_filled_box(WorkraveTimebar *self, cairo_t 
*cr, int x, int y, int width, int height);
 static void workrave_timebar_draw_frame(WorkraveTimebar *self, cairo_t *cr, 
int width, int height);
 static void workrave_timebar_compute_bar_dimensions(WorkraveTimebar *self, int 
*bar_width, int *sbar_width, int *bar_height);
@@ -48,8 +48,6 @@ enum
 
 struct _WorkraveTimebarPrivate
 {
-  gchar *name;
-
   //! Color of the time-bar.
   WorkraveColorId bar_color;
 
@@ -77,9 +75,6 @@ struct _WorkraveTimebarPrivate
   int width;
   int height;
 
-#ifndef USE_GTK2
-  GtkStyleContext *style_context;
-#endif
   PangoContext *pango_context;
   PangoLayout *pango_layout;
 };
@@ -127,8 +122,10 @@ workrave_timebar_init(WorkraveTimebar *s
   priv->secondary_bar_value = 100;
   priv->secondary_bar_max_value = 600;
   priv->bar_text = g_strdup("");
-
-  workrave_timebar_init_ui(self);
+  priv->width = 0;
+  priv->height = 0;
+  priv->pango_context = NULL;
+  priv->pango_layout = NULL;
 }
 
 
@@ -249,80 +246,54 @@ workrave_timebar_draw_text(WorkraveTimeb
 }
 
 
-#ifndef USE_GTK2
-static void
-workrave_timebar_init_ui(WorkraveTimebar *self)
-{
-  WorkraveTimebarPrivate *priv = workrave_timebar_get_instance_private(self);
-
-  priv->style_context = gtk_style_context_new();
-
-  GtkWidgetPath *path = gtk_widget_path_new();
-  gtk_widget_path_append_type(path, GTK_TYPE_BUTTON);
-  gtk_style_context_set_path(priv->style_context, path);
-  gtk_style_context_add_class(priv->style_context, GTK_STYLE_CLASS_TROUGH);
-
-  GdkScreen *screen = gdk_screen_get_default();
-  priv->pango_context = gdk_pango_context_get_for_screen(screen);
-
-  PangoFontDescription *font_desc = NULL;
-  gtk_style_context_get (priv->style_context, GTK_STATE_FLAG_ACTIVE, "font", 
&font_desc, NULL);
-
-  pango_context_set_language(priv->pango_context, gtk_get_default_language());
-  pango_context_set_font_description(priv->pango_context, font_desc);
-
-  priv->pango_layout = pango_layout_new(priv->pango_context);
-  pango_layout_set_text(priv->pango_layout, "-9:59:59", -1);
-
-  pango_layout_get_pixel_size(priv->pango_layout, &priv->width, &priv->height);
-
-  priv->width = MAX(priv->width + 2 * MARGINX, MIN_HORIZONTAL_BAR_WIDTH);
-  priv->height = MAX(priv->height + 2 * MARGINY, MIN_HORIZONTAL_BAR_HEIGHT);
-
-  gtk_widget_path_free(path);
-}
-
-static void
-workrave_timebar_draw_frame(WorkraveTimebar *self, cairo_t *cr,
-                            int width, int height)
+static PangoFontDescription *
+workrave_timebar_get_font(void)
 {
-  WorkraveTimebarPrivate *priv = workrave_timebar_get_instance_private(self);
+  PangoFontDescription *font_desc;
 
-  gtk_style_context_save(priv->style_context);
-  gtk_style_context_set_state(priv->style_context, 
(GtkStateFlags)GTK_STATE_FLAG_ACTIVE);
+#ifndef USE_GTK2
+  if (gdk_screen_get_default())
+    {
+      GtkStyleContext *style = gtk_style_context_new();
+      GtkWidgetPath *path = gtk_widget_path_new();
 
-  gtk_render_frame(priv->style_context, cr, 0, 0, width -1, height -1);
+      gtk_widget_path_append_type(path, GTK_TYPE_BUTTON);
+      gtk_style_context_set_path(style, path);
+      gtk_widget_path_unref(path);
 
-  GdkRGBA color = bar_colors[COLOR_ID_BG];
-  set_color(cr, color);
-  cairo_rectangle(cr, BORDER_SIZE, BORDER_SIZE, width - 2 * BORDER_SIZE , 
height - 2 *BORDER_SIZE);
-  cairo_fill(cr);
+      gtk_style_context_get(style, GTK_STATE_FLAG_NORMAL, 
GTK_STYLE_PROPERTY_FONT, &font_desc, NULL);
+      g_object_unref(style);
+    }
+  else
+#endif
+    {
+      font_desc = pango_font_description_from_string("Sans 10");
+    }
 
-  gtk_style_context_restore(priv->style_context);
+  return font_desc;
 }
 
-#else
-
 static void
-workrave_timebar_init_ui(WorkraveTimebar *self)
+workrave_timebar_init_ui(WorkraveTimebar *self, cairo_t *cr)
 {
   WorkraveTimebarPrivate *priv = workrave_timebar_get_instance_private(self);
 
-  GdkScreen *screen = gdk_screen_get_default();
-  priv->pango_context = gdk_pango_context_get_for_screen(screen);
-
-  const PangoFontDescription *font_desc = 
pango_font_description_from_string("Sans 10");
+  if (priv->pango_layout == NULL)
+    {
+      PangoFontDescription *font_desc = workrave_timebar_get_font();
 
-  pango_context_set_language(priv->pango_context, gtk_get_default_language());
-  pango_context_set_font_description(priv->pango_context, font_desc);
+      priv->pango_layout = pango_cairo_create_layout(cr);
+      priv->pango_context = pango_layout_get_context(priv->pango_layout);
 
-  priv->pango_layout = pango_layout_new(priv->pango_context);
-  pango_layout_set_text(priv->pango_layout, "-9:59:59", -1);
+      pango_context_set_language(priv->pango_context, 
gtk_get_default_language());
+      pango_context_set_font_description(priv->pango_context, font_desc);
 
-  pango_layout_get_pixel_size(priv->pango_layout, &priv->width, &priv->height);
+      pango_layout_set_text(priv->pango_layout, "-9:59:59", -1);
+      pango_layout_get_pixel_size(priv->pango_layout, &priv->width, 
&priv->height);
 
-  priv->width = MAX(priv->width + 2 * MARGINX, MIN_HORIZONTAL_BAR_WIDTH);
-  priv->height = MAX(priv->height + 2 * MARGINY, MIN_HORIZONTAL_BAR_HEIGHT);
+      priv->width = MAX(priv->width + 2 * MARGINX, MIN_HORIZONTAL_BAR_WIDTH);
+      priv->height = MAX(priv->height + 2 * MARGINY, 
MIN_HORIZONTAL_BAR_HEIGHT);
+    }
 }
 
 static void
@@ -353,7 +324,6 @@ workrave_timebar_draw_frame(WorkraveTime
   cairo_rectangle(cr, 2, 2, width - 4 , height - 4);
   cairo_fill(cr);
 }
-#endif
 
 static void
 workrave_timebar_draw_filled_box(WorkraveTimebar *self, cairo_t *cr,
@@ -417,6 +387,8 @@ workrave_timebar_set_text(WorkraveTimeba
 void
 workrave_timebar_draw(WorkraveTimebar *self, cairo_t *cr)
 {
+  workrave_timebar_init_ui(self, cr);
+
   workrave_timebar_draw_bar(self, cr);
   workrave_timebar_draw_text(self, cr);
 }

Reply via email to