Bug Summary

File:typing-break/drw-break-window.c
Warning:line 504, column 3
This statement is never executed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name drw-break-window.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/typing-break -resource-dir /usr/lib/llvm-16/lib/clang/16 -D HAVE_CONFIG_H -I . -I .. -D CAFELOCALEDIR="/usr/share/locale" -D IMAGEDIR="/usr/share/cafe-control-center/pixmaps" -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/cafe-desktop-2.0 -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/startup-notification-1.0 -I /usr/include/dconf -D HAVE_KANBERRA_CTK -D _REENTRANT -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/rootdir/typing-break -ferror-limit 19 -fgnuc-version=4.2.1 -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-04-16-092709-112956-1 -x c drw-break-window.c
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*
3 * Copyright (C) 2002 CodeFactory AB
4 * Copyright (C) 2002-2003 Richard Hult <richard@imendio.com>
5
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public
18 * License along with this program; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#include <config.h>
24#include <string.h>
25#include <math.h>
26#include <glib/gi18n.h>
27#include <ctk/ctk.h>
28#include <cdk/cdkx.h>
29#include <cdk/cdkkeysyms.h>
30#include <gio/gio.h>
31
32#ifdef HAVE_KANBERRA_CTK1
33#include <kanberra-ctk.h>
34#endif
35
36#include "drwright.h"
37#include "drw-utils.h"
38#include "drw-break-window.h"
39#include "drw-timer.h"
40
41struct _DrwBreakWindowPrivate {
42 CtkWidget *clock_label;
43 CtkWidget *break_label;
44 CtkWidget *image;
45
46 CtkWidget *postpone_entry;
47 CtkWidget *postpone_button;
48
49 DrwTimer *timer;
50
51 gint break_time;
52 gchar *break_text;
53 guint clock_timeout_id;
54 guint postpone_timeout_id;
55 guint postpone_sensitize_id;
56};
57
58#define POSTPONE_CANCEL30 30
59
60/* Signals */
61enum {
62 DONE,
63 POSTPONE,
64 LAST_SIGNAL
65};
66
67static void drw_break_window_finalize (GObject *object);
68static void drw_break_window_dispose (GObject *object);
69static gboolean postpone_sensitize_cb (DrwBreakWindow *window);
70static gboolean clock_timeout_cb (DrwBreakWindow *window);
71static void postpone_clicked_cb (CtkWidget *button,
72 CtkWidget *window);
73static gboolean label_draw_event_cb (CtkLabel *label,
74 cairo_t *cr,
75 gpointer user_data);
76static void label_size_allocate_cb (CtkLabel *label,
77 CdkRectangle *allocation,
78 gpointer user_data);
79
80G_DEFINE_TYPE_WITH_PRIVATE (DrwBreakWindow, drw_break_window, CTK_TYPE_WINDOW)static void drw_break_window_init (DrwBreakWindow *self); static
void drw_break_window_class_init (DrwBreakWindowClass *klass
); static GType drw_break_window_get_type_once (void); static
gpointer drw_break_window_parent_class = ((void*)0); static gint
DrwBreakWindow_private_offset; static void drw_break_window_class_intern_init
(gpointer klass) { drw_break_window_parent_class = g_type_class_peek_parent
(klass); if (DrwBreakWindow_private_offset != 0) g_type_class_adjust_private_offset
(klass, &DrwBreakWindow_private_offset); drw_break_window_class_init
((DrwBreakWindowClass*) klass); } __attribute__ ((__unused__
)) static inline gpointer drw_break_window_get_instance_private
(DrwBreakWindow *self) { return (((gpointer) ((guint8*) (self
) + (glong) (DrwBreakWindow_private_offset)))); } GType drw_break_window_get_type
(void) { static gsize static_g_define_type_id = 0; if ((__extension__
({ _Static_assert (sizeof *(&static_g_define_type_id) ==
sizeof (gpointer), "Expression evaluates to false"); (void) (
0 ? (gpointer) *(&static_g_define_type_id) : ((void*)0));
(!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(*(&static_g_define_type_id)) gapg_temp_newval; __typeof__
((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id
); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5)
; gapg_temp_newval; })) && g_once_init_enter (&static_g_define_type_id
)); }))) { GType g_define_type_id = drw_break_window_get_type_once
(); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); 0 ?
(void) (*(&static_g_define_type_id) = (g_define_type_id)
) : (void) 0; g_once_init_leave ((&static_g_define_type_id
), (gsize) (g_define_type_id)); })); } return static_g_define_type_id
; } __attribute__ ((__noinline__)) static GType drw_break_window_get_type_once
(void) { GType g_define_type_id = g_type_register_static_simple
((ctk_window_get_type ()), g_intern_static_string ("DrwBreakWindow"
), sizeof (DrwBreakWindowClass), (GClassInitFunc)(void (*)(void
)) drw_break_window_class_intern_init, sizeof (DrwBreakWindow
), (GInstanceInitFunc)(void (*)(void)) drw_break_window_init,
(GTypeFlags) 0); { {{ DrwBreakWindow_private_offset = g_type_add_instance_private
(g_define_type_id, sizeof (DrwBreakWindowPrivate)); };} } return
g_define_type_id; }
81
82static guint signals[LAST_SIGNAL] = { 0 };
83
84static void
85drw_break_window_class_init (DrwBreakWindowClass *klass)
86{
87 GObjectClass *object_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((klass)), (((GType) ((20) << (2))))))))
;
88
89 object_class->finalize = drw_break_window_finalize;
90 object_class->dispose = drw_break_window_dispose;
91
92 signals[POSTPONE] =
93 g_signal_new ("postpone",
94 G_TYPE_FROM_CLASS (klass)(((GTypeClass*) (klass))->g_type),
95 G_SIGNAL_RUN_LAST,
96 0,
97 NULL((void*)0), NULL((void*)0),
98 g_cclosure_marshal_VOID__VOID,
99 G_TYPE_NONE((GType) ((1) << (2))), 0);
100
101 signals[DONE] =
102 g_signal_new ("done",
103 G_TYPE_FROM_CLASS (klass)(((GTypeClass*) (klass))->g_type),
104 G_SIGNAL_RUN_LAST,
105 0,
106 NULL((void*)0), NULL((void*)0),
107 g_cclosure_marshal_VOID__VOID,
108 G_TYPE_NONE((GType) ((1) << (2))), 0);
109}
110
111static void
112drw_break_window_init (DrwBreakWindow *window)
113{
114 DrwBreakWindowPrivate *priv;
115 CtkWidget *vbox;
116 CtkWidget *hbox;
117 gchar *str;
118 CtkWidget *outer_vbox;
119 CtkWidget *button_box;
120 gboolean allow_postpone;
121
122 gint root_monitor = 0;
123 CdkScreen *screen = NULL((void*)0);
124 CdkDisplay *display;
125 CdkRectangle monitor;
126 gint right_padding;
127 gint bottom_padding;
128 gint scale;
129 GSettings *settings;
130
131 priv = drw_break_window_get_instance_private (window);
132 window->priv = priv;
133
134 settings = g_settings_new (TYPING_BREAK_SCHEMA"org.cafe.typing-break");
135
136 priv->break_time = 60 * g_settings_get_int (settings, "break-time");
137
138 allow_postpone = g_settings_get_boolean (settings, "allow-postpone");
139 g_object_unref (settings);
140
141 ctk_window_set_keep_above (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
, TRUE(!(0)));
142 ctk_window_fullscreen (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
143 ctk_window_set_modal (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
, TRUE(!(0)));
144
145 screen = cdk_screen_get_default ();
146 display = cdk_screen_get_display (screen);
147 scale = ctk_widget_get_scale_factor (CTK_WIDGET (window)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_widget_get_type ()))))))
);
148
149 cdk_monitor_get_geometry (cdk_display_get_monitor (display, root_monitor), &monitor);
150
151 ctk_window_set_default_size (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
,
152 WidthOfScreen (cdk_x11_screen_get_xscreen (screen))((cdk_x11_screen_get_xscreen (screen))->width) / scale,
153 HeightOfScreen (cdk_x11_screen_get_xscreen (screen))((cdk_x11_screen_get_xscreen (screen))->height) / scale);
154
155 ctk_window_set_decorated (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
, FALSE(0));
156 ctk_widget_set_app_paintable (CTK_WIDGET (window)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_widget_get_type ()))))))
, TRUE(!(0)));
157 drw_setup_background (CTK_WIDGET (window)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_widget_get_type ()))))))
);
158
159 right_padding = WidthOfScreen (cdk_x11_screen_get_xscreen (screen))((cdk_x11_screen_get_xscreen (screen))->width) / scale - monitor.width - monitor.x;
160 bottom_padding = HeightOfScreen (cdk_x11_screen_get_xscreen (screen))((cdk_x11_screen_get_xscreen (screen))->height) / scale - monitor.height - monitor.y;
161
162 outer_vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0);
163 ctk_widget_set_hexpand (outer_vbox, TRUE(!(0)));
164 ctk_widget_set_vexpand (outer_vbox, TRUE(!(0)));
165 ctk_widget_set_margin_top (outer_vbox, monitor.y);
166 ctk_widget_set_margin_bottom (outer_vbox, bottom_padding);
167 ctk_widget_set_margin_start (outer_vbox, monitor.x);
168 ctk_widget_set_margin_end (outer_vbox, right_padding);
169 ctk_widget_show (outer_vbox);
170
171 ctk_container_add (CTK_CONTAINER (window)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_container_get_type ()))))))
, outer_vbox);
172
173 if (allow_postpone) {
174 button_box = ctk_box_new (CTK_ORIENTATION_HORIZONTAL, 0);
175 ctk_widget_show (button_box);
176
177 ctk_container_set_border_width (CTK_CONTAINER (button_box)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((button_box)), ((ctk_container_get_type ()))))))
, 12);
178
179 priv->postpone_button = ctk_button_new_with_mnemonic (_("_Postpone Break")gettext ("_Postpone Break"));
180 ctk_widget_show (priv->postpone_button);
181
182 ctk_widget_set_sensitive (priv->postpone_button, FALSE(0));
183
184 if (priv->postpone_sensitize_id) {
185 g_source_remove (priv->postpone_sensitize_id);
186 }
187
188 priv->postpone_sensitize_id = g_timeout_add_seconds (5,
189 (GSourceFunc) postpone_sensitize_cb,
190 window);
191
192 g_signal_connect (priv->postpone_button,g_signal_connect_data ((priv->postpone_button), ("clicked"
), (((GCallback) (postpone_clicked_cb))), (window), ((void*)0
), (GConnectFlags) 0)
193 "clicked",g_signal_connect_data ((priv->postpone_button), ("clicked"
), (((GCallback) (postpone_clicked_cb))), (window), ((void*)0
), (GConnectFlags) 0)
194 G_CALLBACK (postpone_clicked_cb),g_signal_connect_data ((priv->postpone_button), ("clicked"
), (((GCallback) (postpone_clicked_cb))), (window), ((void*)0
), (GConnectFlags) 0)
195 window)g_signal_connect_data ((priv->postpone_button), ("clicked"
), (((GCallback) (postpone_clicked_cb))), (window), ((void*)0
), (GConnectFlags) 0)
;
196
197 ctk_box_pack_end (CTK_BOX (button_box)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((button_box)), ((ctk_box_get_type ()))))))
, priv->postpone_button, FALSE(0), TRUE(!(0)), 0);
198
199 priv->postpone_entry = ctk_entry_new ();
200 ctk_entry_set_has_frame (CTK_ENTRY (priv->postpone_entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((priv->postpone_entry)), ((ctk_entry_get_type ()))))))
, FALSE(0));
201
202 ctk_box_pack_end (CTK_BOX (button_box)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((button_box)), ((ctk_box_get_type ()))))))
, priv->postpone_entry, FALSE(0), TRUE(!(0)), 4);
203
204 ctk_box_pack_end (CTK_BOX (outer_vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((outer_vbox)), ((ctk_box_get_type ()))))))
, button_box, FALSE(0), TRUE(!(0)), 0);
205 }
206
207 vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0);
208 ctk_widget_set_halign (vbox, CTK_ALIGN_CENTER);
209 ctk_widget_set_valign (vbox, CTK_ALIGN_CENTER);
210 ctk_widget_show (vbox);
211
212 ctk_box_pack_start (CTK_BOX (outer_vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((outer_vbox)), ((ctk_box_get_type ()))))))
, vbox, TRUE(!(0)), TRUE(!(0)), 0);
213
214 hbox = ctk_box_new (CTK_ORIENTATION_HORIZONTAL, 0);
215 ctk_widget_show (hbox);
216 ctk_box_pack_start (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((vbox)), ((ctk_box_get_type ()))))))
, hbox, TRUE(!(0)), FALSE(0), 0);
217
218 priv->image = ctk_image_new_from_icon_name ("process-stop", CTK_ICON_SIZE_DIALOG);
219 ctk_widget_set_halign (priv->image, CTK_ALIGN_END);
220 ctk_widget_set_valign (priv->image, CTK_ALIGN_CENTER);
221 ctk_widget_show (priv->image);
222 ctk_box_pack_start (CTK_BOX (hbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((hbox)), ((ctk_box_get_type ()))))))
, priv->image, TRUE(!(0)), TRUE(!(0)), 8);
223
224 priv->break_label = ctk_label_new (NULL((void*)0));
225 ctk_widget_show (priv->break_label);
226
227 g_signal_connect (priv->break_label,g_signal_connect_data ((priv->break_label), ("draw"), (((GCallback
) (label_draw_event_cb))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
228 "draw",g_signal_connect_data ((priv->break_label), ("draw"), (((GCallback
) (label_draw_event_cb))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
229 G_CALLBACK (label_draw_event_cb),g_signal_connect_data ((priv->break_label), ("draw"), (((GCallback
) (label_draw_event_cb))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
230 NULL)g_signal_connect_data ((priv->break_label), ("draw"), (((GCallback
) (label_draw_event_cb))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
;
231
232 g_signal_connect_after (priv->break_label,g_signal_connect_data ((priv->break_label), ("size-allocate"
), (((GCallback) (label_size_allocate_cb))), (((void*)0)), ((
void*)0), G_CONNECT_AFTER)
233 "size-allocate",g_signal_connect_data ((priv->break_label), ("size-allocate"
), (((GCallback) (label_size_allocate_cb))), (((void*)0)), ((
void*)0), G_CONNECT_AFTER)
234 G_CALLBACK (label_size_allocate_cb),g_signal_connect_data ((priv->break_label), ("size-allocate"
), (((GCallback) (label_size_allocate_cb))), (((void*)0)), ((
void*)0), G_CONNECT_AFTER)
235 NULL)g_signal_connect_data ((priv->break_label), ("size-allocate"
), (((GCallback) (label_size_allocate_cb))), (((void*)0)), ((
void*)0), G_CONNECT_AFTER)
;
236
237 str = g_strdup_printf ("<span size=\"xx-large\" foreground=\"white\"><b>%s</b></span>",
238 _("Take a break!")gettext ("Take a break!"));
239 ctk_label_set_markup (CTK_LABEL (priv->break_label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((priv->break_label)), ((ctk_label_get_type ()))))))
, str);
240 g_free (str);
241
242 ctk_box_pack_start (CTK_BOX (hbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((hbox)), ((ctk_box_get_type ()))))))
, priv->break_label, FALSE(0), FALSE(0), 12);
243
244
245 priv->clock_label = ctk_label_new (NULL((void*)0));
246 ctk_widget_show (priv->clock_label);
247 ctk_box_pack_start (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((vbox)), ((ctk_box_get_type ()))))))
, priv->clock_label, TRUE(!(0)), TRUE(!(0)), 8);
248
249 g_signal_connect (priv->clock_label,g_signal_connect_data ((priv->clock_label), ("draw"), (((GCallback
) (label_draw_event_cb))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
250 "draw",g_signal_connect_data ((priv->clock_label), ("draw"), (((GCallback
) (label_draw_event_cb))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
251 G_CALLBACK (label_draw_event_cb),g_signal_connect_data ((priv->clock_label), ("draw"), (((GCallback
) (label_draw_event_cb))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
252 NULL)g_signal_connect_data ((priv->clock_label), ("draw"), (((GCallback
) (label_draw_event_cb))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
;
253
254 g_signal_connect_after (priv->clock_label,g_signal_connect_data ((priv->clock_label), ("size-allocate"
), (((GCallback) (label_size_allocate_cb))), (((void*)0)), ((
void*)0), G_CONNECT_AFTER)
255 "size-allocate",g_signal_connect_data ((priv->clock_label), ("size-allocate"
), (((GCallback) (label_size_allocate_cb))), (((void*)0)), ((
void*)0), G_CONNECT_AFTER)
256 G_CALLBACK (label_size_allocate_cb),g_signal_connect_data ((priv->clock_label), ("size-allocate"
), (((GCallback) (label_size_allocate_cb))), (((void*)0)), ((
void*)0), G_CONNECT_AFTER)
257 NULL)g_signal_connect_data ((priv->clock_label), ("size-allocate"
), (((GCallback) (label_size_allocate_cb))), (((void*)0)), ((
void*)0), G_CONNECT_AFTER)
;
258
259 ctk_window_stick (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
260
261 priv->timer = drw_timer_new ();
262
263 /* Make sure we have a valid time label from the start. */
264 clock_timeout_cb (window);
265
266 priv->clock_timeout_id = g_timeout_add (1000,
267 (GSourceFunc) clock_timeout_cb,
268 window);
269#ifdef HAVE_KANBERRA_CTK1
270 ka_context_play (ka_ctk_context_get (), 0, KA_PROP_EVENT_ID"event.id", "desktop-screen-lock", NULL((void*)0));
271#endif
272}
273
274static void
275drw_break_window_finalize (GObject *object)
276{
277 DrwBreakWindow *window = DRW_BREAK_WINDOW (object)((((DrwBreakWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((object)), ((drw_break_window_get_type ()))))))
;
278 DrwBreakWindowPrivate *priv;
279
280 priv = window->priv;
281
282 if (priv->clock_timeout_id != 0) {
283 g_source_remove (priv->clock_timeout_id);
284 }
285
286 if (priv->postpone_timeout_id != 0) {
287 g_source_remove (priv->postpone_timeout_id);
288 }
289
290 if (priv->postpone_sensitize_id != 0) {
291 g_source_remove (priv->postpone_sensitize_id);
292 }
293
294 window->priv = NULL((void*)0);
295
296 if (G_OBJECT_CLASS (drw_break_window_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((drw_break_window_parent_class)), (((GType) ((20) <<
(2))))))))
->finalize) {
297 (* G_OBJECT_CLASS (drw_break_window_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((drw_break_window_parent_class)), (((GType) ((20) <<
(2))))))))
->finalize) (object);
298 }
299}
300
301static void
302drw_break_window_dispose (GObject *object)
303{
304 DrwBreakWindow *window = DRW_BREAK_WINDOW (object)((((DrwBreakWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((object)), ((drw_break_window_get_type ()))))))
;
305 DrwBreakWindowPrivate *priv;
306
307 priv = window->priv;
308
309 if (priv->timer) {
310 drw_timer_destroy (priv->timer);
311 priv->timer = NULL((void*)0);
312 }
313
314 if (priv->clock_timeout_id != 0) {
315 g_source_remove (priv->clock_timeout_id);
316 priv->clock_timeout_id = 0;
317 }
318
319 if (priv->postpone_timeout_id != 0) {
320 g_source_remove (priv->postpone_timeout_id);
321 priv->postpone_timeout_id = 0;
322 }
323
324 if (priv->postpone_sensitize_id != 0) {
325 g_source_remove (priv->postpone_sensitize_id);
326 }
327
328 if (G_OBJECT_CLASS (drw_break_window_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((drw_break_window_parent_class)), (((GType) ((20) <<
(2))))))))
->dispose) {
329 (* G_OBJECT_CLASS (drw_break_window_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((drw_break_window_parent_class)), (((GType) ((20) <<
(2))))))))
->dispose) (object);
330 }
331}
332
333CtkWidget *
334drw_break_window_new (void)
335{
336 GObject *object;
337
338 object = g_object_new (DRW_TYPE_BREAK_WINDOW(drw_break_window_get_type ()),
339 "type", CTK_WINDOW_POPUP,
340 "skip-taskbar-hint", TRUE(!(0)),
341 "skip-pager-hint", TRUE(!(0)),
342 "focus-on-map", TRUE(!(0)),
343 NULL((void*)0));
344
345 return CTK_WIDGET (object)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((object)), ((ctk_widget_get_type ()))))))
;
346}
347
348static gboolean
349postpone_sensitize_cb (DrwBreakWindow *window)
350{
351 DrwBreakWindowPrivate *priv;
352
353 priv = window->priv;
354
355 ctk_widget_set_sensitive (priv->postpone_button, TRUE(!(0)));
356
357 priv->postpone_sensitize_id = 0;
358 return FALSE(0);
359}
360
361static gboolean
362clock_timeout_cb (DrwBreakWindow *window)
363{
364 DrwBreakWindowPrivate *priv;
365 gchar *txt;
366 gint minutes;
367 gint seconds;
368
369 g_return_val_if_fail (DRW_IS_BREAK_WINDOW (window), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((window)); GType __t = ((drw_break_window_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; })))))) { }
else { g_return_if_fail_warning (((gchar*) 0), ((const char*
) (__func__)), "DRW_IS_BREAK_WINDOW (window)"); return ((0));
} } while (0)
;
370
371 priv = window->priv;
372
373 seconds = 1 + priv->break_time - drw_timer_elapsed (priv->timer);
374 seconds = MAX (0, seconds)(((0)>(seconds))?(0):(seconds));
375
376 if (seconds == 0) {
377 /* Zero this out so the finalizer doesn't try to remove the
378 * source, which would be done in the timeout callback ==
379 * no-no.
380 */
381 priv->clock_timeout_id = 0;
382
383#ifdef HAVE_KANBERRA_CTK1
384 ka_context_play (ka_ctk_context_get (), 0, KA_PROP_EVENT_ID"event.id", "alarm-clock-elapsed", NULL((void*)0));
385#endif
386 g_signal_emit (window, signals[DONE], 0, NULL((void*)0));
387
388 return FALSE(0);
389 }
390
391 minutes = seconds / 60;
392 seconds -= minutes * 60;
393
394 txt = g_strdup_printf ("<span size=\"25000\" foreground=\"white\"><b>%d:%02d</b></span>",
395 minutes,
396 seconds);
397 ctk_label_set_markup (CTK_LABEL (priv->clock_label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((priv->clock_label)), ((ctk_label_get_type ()))))))
, txt);
398 g_free (txt);
399
400 return TRUE(!(0));
401}
402
403static void
404postpone_entry_activate_cb (CtkWidget *entry,
405 DrwBreakWindow *window)
406{
407 const gchar *str;
408 gchar *phrase;
409 GSettings *settings = g_settings_new (TYPING_BREAK_SCHEMA"org.cafe.typing-break");
410
411 str = ctk_entry_get_text (CTK_ENTRY (entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((entry)), ((ctk_entry_get_type ()))))))
);
412
413 phrase = g_settings_get_string (settings, "unlock-phrase");
414 g_object_unref (settings);
415
416 if (!strcmp (str, phrase)) {
417 g_signal_emit (window, signals[POSTPONE], 0, NULL((void*)0));
418 g_free (phrase);
419 return;
420 }
421
422 g_free (phrase);
423 ctk_entry_set_text (CTK_ENTRY (entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((entry)), ((ctk_entry_get_type ()))))))
, "");
424}
425
426static gboolean
427grab_on_window (CdkWindow *window,
428 guint32 activate_time)
429{
430 CdkDisplay *display;
431 CdkSeat *seat;
432
433 display = cdk_window_get_display (window);
434 seat = cdk_display_get_default_seat (display);
435
436 return (cdk_seat_grab (seat,
437 window,
438 CDK_SEAT_CAPABILITY_ALL,
439 TRUE(!(0)),
440 NULL((void*)0),
441 NULL((void*)0),
442 NULL((void*)0),
443 NULL((void*)0)) == CDK_GRAB_SUCCESS);
444}
445
446static gboolean
447postpone_cancel_cb (DrwBreakWindow *window)
448{
449 DrwBreakWindowPrivate *priv;
450
451 priv = window->priv;
452
453 ctk_entry_set_text (CTK_ENTRY (priv->postpone_entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((priv->postpone_entry)), ((ctk_entry_get_type ()))))))
, "");
454 ctk_widget_hide (priv->postpone_entry);
455
456 priv->postpone_timeout_id = 0;
457
458 return FALSE(0);
459}
460
461static gboolean
462postpone_entry_key_press_event_cb (CtkEntry *entry,
463 CdkEventKey *event,
464 DrwBreakWindow *window)
465{
466 DrwBreakWindowPrivate *priv;
467
468 priv = window->priv;
469
470 if (event->keyval == CDK_KEY_Escape0xff1b) {
471 if (priv->postpone_timeout_id) {
472 g_source_remove (priv->postpone_timeout_id);
473 }
474
475 postpone_cancel_cb (window);
476
477 return TRUE(!(0));
478 }
479
480 g_source_remove (priv->postpone_timeout_id);
481
482 priv->postpone_timeout_id = g_timeout_add_seconds (POSTPONE_CANCEL30, (GSourceFunc) postpone_cancel_cb, window);
483
484 return FALSE(0);
485}
486
487static void
488postpone_clicked_cb (CtkWidget *button,
489 CtkWidget *window)
490{
491 DrwBreakWindow *bw = DRW_BREAK_WINDOW (window)((((DrwBreakWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((drw_break_window_get_type ()))))))
;
492 DrwBreakWindowPrivate *priv = bw->priv;
493 gchar *phrase;
494
495 /* Disable the phrase for now. */
496 phrase = NULL((void*)0); /*g_settings_get_string (settings, "unlock-phrase");*/
497
498 if (!phrase || !phrase[0]) {
499 g_signal_emit (window, signals[POSTPONE], 0, NULL((void*)0));
500 return;
501 }
502
503 if (ctk_widget_get_visible (priv->postpone_entry)) {
504 ctk_widget_activate (priv->postpone_entry);
This statement is never executed
505 return;
506 }
507
508 ctk_widget_show (priv->postpone_entry);
509
510 priv->postpone_timeout_id = g_timeout_add_seconds (POSTPONE_CANCEL30, (GSourceFunc) postpone_cancel_cb, bw);
511
512 grab_on_window (ctk_widget_get_window (priv->postpone_entry), ctk_get_current_event_time ());
513
514 ctk_widget_grab_focus (priv->postpone_entry);
515
516 g_signal_connect (priv->postpone_entry,g_signal_connect_data ((priv->postpone_entry), ("activate"
), (((GCallback) (postpone_entry_activate_cb))), (bw), ((void
*)0), (GConnectFlags) 0)
517 "activate",g_signal_connect_data ((priv->postpone_entry), ("activate"
), (((GCallback) (postpone_entry_activate_cb))), (bw), ((void
*)0), (GConnectFlags) 0)
518 G_CALLBACK (postpone_entry_activate_cb),g_signal_connect_data ((priv->postpone_entry), ("activate"
), (((GCallback) (postpone_entry_activate_cb))), (bw), ((void
*)0), (GConnectFlags) 0)
519 bw)g_signal_connect_data ((priv->postpone_entry), ("activate"
), (((GCallback) (postpone_entry_activate_cb))), (bw), ((void
*)0), (GConnectFlags) 0)
;
520
521 g_signal_connect (priv->postpone_entry,g_signal_connect_data ((priv->postpone_entry), ("key_press_event"
), (((GCallback) (postpone_entry_key_press_event_cb))), (bw),
((void*)0), (GConnectFlags) 0)
522 "key_press_event",g_signal_connect_data ((priv->postpone_entry), ("key_press_event"
), (((GCallback) (postpone_entry_key_press_event_cb))), (bw),
((void*)0), (GConnectFlags) 0)
523 G_CALLBACK (postpone_entry_key_press_event_cb),g_signal_connect_data ((priv->postpone_entry), ("key_press_event"
), (((GCallback) (postpone_entry_key_press_event_cb))), (bw),
((void*)0), (GConnectFlags) 0)
524 bw)g_signal_connect_data ((priv->postpone_entry), ("key_press_event"
), (((GCallback) (postpone_entry_key_press_event_cb))), (bw),
((void*)0), (GConnectFlags) 0)
;
525}
526
527static void
528get_layout_location (CtkLabel *label,
529 gint *xp,
530 gint *yp)
531{
532 CtkWidget *widget;
533 CtkAllocation widget_allocation;
534 CtkRequisition widget_requisition;
535 gfloat xalign, yalign;
536 gint x, y;
537 gint xpad, ypad;
538 gint margin_start, margin_end, margin_top, margin_bottom;
539 gint scale;
540
541 widget = CTK_WIDGET (label)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((label)), ((ctk_widget_get_type ()))))))
;
542
543 scale = ctk_widget_get_scale_factor (widget);
544 xalign = ctk_label_get_xalign (CTK_LABEL (label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((label)), ((ctk_label_get_type ()))))))
);
545 yalign = ctk_label_get_yalign (CTK_LABEL (label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((label)), ((ctk_label_get_type ()))))))
);
546 margin_start = ctk_widget_get_margin_start (widget);
547 margin_end = ctk_widget_get_margin_end (widget);
548 margin_top = ctk_widget_get_margin_top (widget);
549 margin_bottom = ctk_widget_get_margin_bottom (widget);
550
551 xpad = margin_start + margin_end;
552 ypad = margin_top + margin_bottom;
553
554 ctk_widget_get_allocation (widget, &widget_allocation);
555 ctk_widget_get_preferred_size (widget, &widget_requisition, NULL((void*)0));
556 widget_allocation.x /= scale;
557 widget_allocation.y /= scale;
558 widget_requisition.width /= scale;
559 widget_requisition.height /= scale;
560
561 if (ctk_widget_get_direction (widget) != CTK_TEXT_DIR_LTR)
562 xalign = 1.0 - xalign;
563
564 x = floor (widget_allocation.x + (int)xpad
565 + ((widget_allocation.width - widget_requisition.width - 1) * xalign)
566 + 0.5);
567
568 y = floor (widget_allocation.y + (int)ypad
569 + ((widget_allocation.height - widget_requisition.height - 1) * yalign)
570 + 0.5);
571
572 if (xp) {
573 *xp = x;
574 }
575
576 if (yp) {
577 *yp = y;
578 }
579}
580
581static gboolean
582label_draw_event_cb (CtkLabel *label,
583 cairo_t *cr,
584 gpointer user_data)
585{
586 gint x, y;
587 CtkWidget *widget;
588
589 get_layout_location (label, &x, &y);
590
591 widget = CTK_WIDGET (label)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((label)), ((ctk_widget_get_type ()))))))
;
592
593 pango_cairo_show_layout (cr, ctk_label_get_layout (label));
594
595 ctk_paint_layout (ctk_widget_get_style (widget),
596 cr,
597 ctk_widget_get_state (widget),
598 FALSE(0),
599 widget,
600 "label",
601 x, y,
602 ctk_label_get_layout (label));
603
604 return TRUE(!(0));
605}
606
607static void
608label_size_allocate_cb (CtkLabel *label,
609 CdkRectangle *allocation,
610 gpointer user_data)
611{
612 allocation->width += 1;
613 allocation->height += 1;
614}