summaryrefslogtreecommitdiff
path: root/typing-break
diff options
context:
space:
mode:
authorVictor Kareh <[email protected]>2018-08-25 21:35:31 -0400
committerVictor Kareh <[email protected]>2018-08-25 21:35:31 -0400
commit8c4ebefafff7534e452e3e12e74ec8eee96de5fa (patch)
tree5b728a7e7e94e28d14fd768fdb584486723710ab /typing-break
parent19fdb3f9f84b9354c24d1ec58e43ea9d4d575c3f (diff)
downloadmate-control-center-8c4ebefafff7534e452e3e12e74ec8eee96de5fa.tar.bz2
mate-control-center-8c4ebefafff7534e452e3e12e74ec8eee96de5fa.tar.xz
typing-break: Make images larger and load as surface
Diffstat (limited to 'typing-break')
-rw-r--r--typing-break/bar-disabled.pngbin496 -> 6933 bytes
-rw-r--r--typing-break/bar-green.pngbin286 -> 3744 bytes
-rw-r--r--typing-break/bar-red.pngbin277 -> 3422 bytes
-rw-r--r--typing-break/bar.pngbin362 -> 4581 bytes
-rw-r--r--typing-break/drw-break-window.c40
-rw-r--r--typing-break/drw-utils.c11
-rw-r--r--typing-break/drwright.c118
7 files changed, 100 insertions, 69 deletions
diff --git a/typing-break/bar-disabled.png b/typing-break/bar-disabled.png
index 247e976c..df14c2b4 100644
--- a/typing-break/bar-disabled.png
+++ b/typing-break/bar-disabled.png
Binary files differ
diff --git a/typing-break/bar-green.png b/typing-break/bar-green.png
index 8979d10c..cd807031 100644
--- a/typing-break/bar-green.png
+++ b/typing-break/bar-green.png
Binary files differ
diff --git a/typing-break/bar-red.png b/typing-break/bar-red.png
index dd3db767..701834b4 100644
--- a/typing-break/bar-red.png
+++ b/typing-break/bar-red.png
Binary files differ
diff --git a/typing-break/bar.png b/typing-break/bar.png
index 4eead01c..9a935a4f 100644
--- a/typing-break/bar.png
+++ b/typing-break/bar.png
Binary files differ
diff --git a/typing-break/drw-break-window.c b/typing-break/drw-break-window.c
index 22ff0f45..ca8762c9 100644
--- a/typing-break/drw-break-window.c
+++ b/typing-break/drw-break-window.c
@@ -77,8 +77,8 @@ static void postpone_clicked_cb (GtkWidget *button,
static gboolean label_draw_event_cb (GtkLabel *label,
cairo_t *cr,
gpointer user_data);
-static void label_size_request_cb (GtkLabel *label,
- GtkRequisition *requisition,
+static void label_size_allocate_cb (GtkLabel *label,
+ GdkRectangle *allocation,
gpointer user_data);
G_DEFINE_TYPE (DrwBreakWindow, drw_break_window, GTK_TYPE_WINDOW)
@@ -131,6 +131,7 @@ drw_break_window_init (DrwBreakWindow *window)
GdkRectangle monitor;
gint right_padding;
gint bottom_padding;
+ gint scale;
GSettings *settings;
priv = DRW_BREAK_WINDOW_GET_PRIVATE (window);
@@ -143,25 +144,26 @@ drw_break_window_init (DrwBreakWindow *window)
allow_postpone = g_settings_get_boolean (settings, "allow-postpone");
g_object_unref (settings);
- g_object_set (window, "type", GTK_WINDOW_POPUP, NULL);
gtk_window_set_keep_above (GTK_WINDOW (window), TRUE);
gtk_window_fullscreen (GTK_WINDOW (window));
gtk_window_set_modal (GTK_WINDOW (window), TRUE);
screen = gdk_screen_get_default ();
display = gdk_screen_get_display (screen);
+ scale = gtk_widget_get_scale_factor (GTK_WIDGET (window));
+
gdk_monitor_get_geometry (gdk_display_get_monitor (display, root_monitor), &monitor);
gtk_window_set_default_size (GTK_WINDOW (window),
- WidthOfScreen (gdk_x11_screen_get_xscreen (screen)),
- HeightOfScreen (gdk_x11_screen_get_xscreen (screen)));
+ WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale,
+ HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale);
gtk_window_set_decorated (GTK_WINDOW (window), FALSE);
gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
drw_setup_background (GTK_WIDGET (window));
- right_padding = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) - monitor.width - monitor.x;
- bottom_padding = HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) - monitor.height - monitor.y;
+ right_padding = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale - monitor.width - monitor.x;
+ bottom_padding = HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale - monitor.height - monitor.y;
outer_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_hexpand (outer_vbox, TRUE);
@@ -234,8 +236,8 @@ drw_break_window_init (DrwBreakWindow *window)
NULL);
g_signal_connect_after (priv->break_label,
- "size_request",
- G_CALLBACK (label_size_request_cb),
+ "size-allocate",
+ G_CALLBACK (label_size_allocate_cb),
NULL);
str = g_strdup_printf ("<span size=\"xx-large\" foreground=\"white\"><b>%s</b></span>",
@@ -256,8 +258,8 @@ drw_break_window_init (DrwBreakWindow *window)
NULL);
g_signal_connect_after (priv->clock_label,
- "size_request",
- G_CALLBACK (label_size_request_cb),
+ "size-allocate",
+ G_CALLBACK (label_size_allocate_cb),
NULL);
gtk_window_stick (GTK_WINDOW (window));
@@ -540,9 +542,11 @@ get_layout_location (GtkLabel *label,
gint x, y;
gint xpad, ypad;
gint margin_start, margin_end, margin_top, margin_bottom;
+ gint scale;
widget = GTK_WIDGET (label);
+ scale = gtk_widget_get_scale_factor (widget);
xalign = gtk_label_get_xalign (GTK_LABEL (label));
yalign = gtk_label_get_yalign (GTK_LABEL (label));
margin_start = gtk_widget_get_margin_start (widget);
@@ -555,6 +559,10 @@ get_layout_location (GtkLabel *label,
gtk_widget_get_allocation (widget, &widget_allocation);
gtk_widget_get_requisition (widget, &widget_requisition);
+ widget_allocation.x /= scale;
+ widget_allocation.y /= scale;
+ widget_requisition.width /= scale;
+ widget_requisition.height /= scale;
if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
xalign = 1.0 - xalign;
@@ -603,10 +611,10 @@ label_draw_event_cb (GtkLabel *label,
}
static void
-label_size_request_cb (GtkLabel *label,
- GtkRequisition *requisition,
- gpointer user_data)
+label_size_allocate_cb (GtkLabel *label,
+ GdkRectangle *allocation,
+ gpointer user_data)
{
- requisition->width += 1;
- requisition->height += 1;
+ allocation->width += 1;
+ allocation->height += 1;
}
diff --git a/typing-break/drw-utils.c b/typing-break/drw-utils.c
index 8ba53edd..bad0869e 100644
--- a/typing-break/drw-utils.c
+++ b/typing-break/drw-utils.c
@@ -119,14 +119,15 @@ set_pixmap_background (GtkWidget *window)
GdkPixbuf *tmp_pixbuf, *pixbuf, *tile_pixbuf;
GdkRectangle rect;
GdkColor color;
- gint width, height;
+ gint width, height, scale;
cairo_t *cr;
gtk_widget_realize (window);
screen = gtk_widget_get_screen (window);
- width = WidthOfScreen (gdk_x11_screen_get_xscreen (screen));
- height = HeightOfScreen (gdk_x11_screen_get_xscreen (screen));
+ scale = gtk_widget_get_scale_factor (window);
+ width = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
+ height = HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
tmp_pixbuf = gdk_pixbuf_get_from_window (gdk_screen_get_root_window (screen),
0,
@@ -160,8 +161,8 @@ set_pixmap_background (GtkWidget *window)
height,
0,
0,
- 1,
- 1,
+ scale,
+ scale,
GDK_INTERP_NEAREST,
225);
diff --git a/typing-break/drwright.c b/typing-break/drwright.c
index 6fff8f58..00c741c0 100644
--- a/typing-break/drwright.c
+++ b/typing-break/drwright.c
@@ -69,42 +69,42 @@ typedef enum {
struct _DrWright {
/* Widgets. */
- GtkWidget *break_window;
- GList *secondary_break_windows;
+ GtkWidget *break_window;
+ GList *secondary_break_windows;
- DrwMonitor *monitor;
+ DrwMonitor *monitor;
- GtkUIManager *ui_manager;
+ GtkUIManager *ui_manager;
- DrwState state;
- DrwTimer *timer;
- DrwTimer *idle_timer;
+ DrwState state;
+ DrwTimer *timer;
+ DrwTimer *idle_timer;
- gint last_elapsed_time;
- gint save_last_time;
+ gint last_elapsed_time;
+ gint save_last_time;
/* Time settings. */
- gint type_time;
- gint break_time;
- gint warn_time;
+ gint type_time;
+ gint break_time;
+ gint warn_time;
- gboolean enabled;
+ gboolean enabled;
- guint clock_timeout_id;
+ guint clock_timeout_id;
#ifdef HAVE_APP_INDICATOR
- AppIndicator *indicator;
+ AppIndicator *indicator;
#else
- guint blink_timeout_id;
+ guint blink_timeout_id;
- gboolean blink_on;
+ gboolean blink_on;
- GtkStatusIcon *icon;
+ GtkStatusIcon *icon;
- GdkPixbuf *neutral_bar;
- GdkPixbuf *red_bar;
- GdkPixbuf *green_bar;
- GdkPixbuf *disabled_bar;
- GdkPixbuf *composite_bar;
+ cairo_surface_t *neutral_bar;
+ cairo_surface_t *red_bar;
+ cairo_surface_t *green_bar;
+ cairo_surface_t *disabled_bar;
+ GdkPixbuf *composite_bar;
#endif /* HAVE_APP_INDICATOR */
GtkWidget *warn_dialog;
@@ -175,6 +175,21 @@ update_app_indicator (DrWright *dr)
app_indicator_set_status (dr->indicator, new_status);
}
#else
+
+static void
+set_status_icon (GtkStatusIcon *icon, cairo_surface_t *surface)
+{
+ GdkPixbuf *pixbuf;
+
+ pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0,
+ cairo_image_surface_get_width (surface),
+ cairo_image_surface_get_height (surface));
+
+ gtk_status_icon_set_from_pixbuf (icon, pixbuf);
+
+ g_object_unref (pixbuf);
+}
+
static void
update_icon (DrWright *dr)
{
@@ -186,15 +201,16 @@ update_icon (DrWright *dr)
gboolean set_pixbuf;
if (!dr->enabled) {
- gtk_status_icon_set_from_pixbuf (dr->icon,
- dr->disabled_bar);
+ set_status_icon (dr->icon, dr->disabled_bar);
return;
}
- tmp_pixbuf = gdk_pixbuf_copy (dr->neutral_bar);
+ width = cairo_image_surface_get_width (dr->neutral_bar);
+ height = cairo_image_surface_get_height (dr->neutral_bar);
- width = gdk_pixbuf_get_width (tmp_pixbuf);
- height = gdk_pixbuf_get_height (tmp_pixbuf);
+ tmp_pixbuf = gdk_pixbuf_get_from_surface (dr->neutral_bar,
+ 0, 0,
+ width, height);
set_pixbuf = TRUE;
@@ -220,17 +236,17 @@ update_icon (DrWright *dr)
switch (dr->state) {
case STATE_WARN:
- pixbuf = dr->red_bar;
+ pixbuf = gdk_pixbuf_get_from_surface (dr->red_bar, 0, 0, width, height);
set_pixbuf = FALSE;
break;
case STATE_BREAK_SETUP:
case STATE_BREAK:
- pixbuf = dr->red_bar;
+ pixbuf = gdk_pixbuf_get_from_surface (dr->red_bar, 0, 0, width, height);
break;
default:
- pixbuf = dr->green_bar;
+ pixbuf = gdk_pixbuf_get_from_surface (dr->green_bar, 0, 0, width, height);
}
gdk_pixbuf_composite (pixbuf,
@@ -256,6 +272,8 @@ update_icon (DrWright *dr)
}
dr->composite_bar = tmp_pixbuf;
+
+ g_object_unref (pixbuf);
}
static gboolean
@@ -272,11 +290,9 @@ blink_timeout_cb (DrWright *dr)
}
if (dr->blink_on || timeout == 0) {
- gtk_status_icon_set_from_pixbuf (dr->icon,
- dr->composite_bar);
+ gtk_status_icon_set_from_pixbuf (dr->icon, dr->composite_bar);
} else {
- gtk_status_icon_set_from_pixbuf (dr->icon,
- dr->neutral_bar);
+ set_status_icon (dr->icon, dr->neutral_bar);
}
dr->blink_on = !dr->blink_on;
@@ -385,8 +401,7 @@ maybe_change_state (DrWright *dr)
}
#ifndef HAVE_APP_INDICATOR
- gtk_status_icon_set_from_pixbuf (dr->icon,
- dr->neutral_bar);
+ set_status_icon (dr->icon, dr->neutral_bar);
#endif /* HAVE_APP_INDICATOR */
dr->save_last_time = 0;
@@ -426,8 +441,7 @@ maybe_change_state (DrWright *dr)
stop_blinking (dr);
#ifndef HAVE_APP_INDICATOR
- gtk_status_icon_set_from_pixbuf (dr->icon,
- dr->red_bar);
+ set_status_icon (dr->icon, dr->red_bar);
#endif /* HAVE_APP_INDICATOR */
drw_timer_start (dr->timer);
@@ -470,8 +484,7 @@ maybe_change_state (DrWright *dr)
case STATE_BREAK_DONE_SETUP:
stop_blinking (dr);
#ifndef HAVE_APP_INDICATOR
- gtk_status_icon_set_from_pixbuf (dr->icon,
- dr->green_bar);
+ set_status_icon (dr->icon, dr->green_bar);
#endif /* HAVE_APP_INDICATOR */
dr->state = STATE_BREAK_DONE;
@@ -765,7 +778,14 @@ init_app_indicator (DrWright *dr)
static void
init_tray_icon (DrWright *dr)
{
- dr->icon = gtk_status_icon_new_from_pixbuf (dr->neutral_bar);
+ GdkPixbuf *pixbuf;
+
+ pixbuf = gdk_pixbuf_get_from_surface (dr->neutral_bar, 0, 0,
+ cairo_image_surface_get_width (dr->neutral_bar),
+ cairo_image_surface_get_height (dr->neutral_bar));
+
+ dr->icon = gtk_status_icon_new_from_pixbuf (pixbuf);
+ g_object_unref (pixbuf);
update_status (dr);
update_icon (dr);
@@ -784,6 +804,7 @@ create_secondary_break_windows (void)
GdkScreen *screen;
GtkWidget *window;
GList *windows = NULL;
+ gint scale;
display = gdk_display_get_default ();
@@ -795,12 +816,13 @@ create_secondary_break_windows (void)
window = gtk_window_new (GTK_WINDOW_POPUP);
windows = g_list_prepend (windows, window);
+ scale = gtk_widget_get_scale_factor (GTK_WIDGET (window));
gtk_window_set_screen (GTK_WINDOW (window), screen);
gtk_window_set_default_size (GTK_WINDOW (window),
- WidthOfScreen (gdk_x11_screen_get_xscreen (screen)),
- HeightOfScreen (gdk_x11_screen_get_xscreen (screen)));
+ WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale,
+ HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale);
gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
drw_setup_background (GTK_WIDGET (window));
@@ -873,10 +895,10 @@ drwright_new (void)
#ifdef HAVE_APP_INDICATOR
init_app_indicator (dr);
#else
- dr->neutral_bar = gdk_pixbuf_new_from_file (IMAGEDIR "/bar.png", NULL);
- dr->red_bar = gdk_pixbuf_new_from_file (IMAGEDIR "/bar-red.png", NULL);
- dr->green_bar = gdk_pixbuf_new_from_file (IMAGEDIR "/bar-green.png", NULL);
- dr->disabled_bar = gdk_pixbuf_new_from_file (IMAGEDIR "/bar-disabled.png", NULL);
+ dr->neutral_bar = cairo_image_surface_create_from_png (IMAGEDIR "/bar.png");
+ dr->red_bar = cairo_image_surface_create_from_png (IMAGEDIR "/bar-red.png");
+ dr->green_bar = cairo_image_surface_create_from_png (IMAGEDIR "/bar-green.png");
+ dr->disabled_bar = cairo_image_surface_create_from_png (IMAGEDIR "/bar-disabled.png");
init_tray_icon (dr);
#endif /* HAVE_APP_INDICATOR */