code cleanup
[psensor.git] / src / ui.c
1 /*
2     Copyright (C) 2010-2011 wpitchoune@gmail.com
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17     02110-1301 USA
18 */
19
20 #include "cfg.h"
21 #include "ui.h"
22
23 static gboolean
24 on_delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
25 {
26
27 #if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
28         gtk_widget_hide(((struct ui_psensor *)data)->main_window);
29 #else
30         ui_psensor_quit();
31 #endif
32
33         return TRUE;
34 }
35
36 void ui_psensor_exit()
37 {
38         gtk_main_quit();
39 }
40
41 GtkWidget *ui_window_create(struct ui_psensor * ui)
42 {
43         GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
44         GdkScreen *screen;
45         GdkColormap *colormap;
46         GdkPixbuf *icon;
47         GtkIconTheme *icon_theme;
48
49         gtk_window_set_default_size(GTK_WINDOW(window), 800, 200);
50
51         gtk_window_set_title(GTK_WINDOW(window),
52                              _("Psensor - Temperature Monitor"));
53         gtk_window_set_role(GTK_WINDOW(window), "psensor");
54
55         screen = gtk_widget_get_screen(window);
56
57         if (ui->config->alpha_channel_enabled
58             && gdk_screen_is_composited(screen)) {
59
60                 colormap = gdk_screen_get_rgba_colormap(screen);
61                 if (colormap)
62                         gtk_widget_set_colormap(window, colormap);
63                 else
64                         ui->config->alpha_channel_enabled = 0;
65         } else {
66                 ui->config->alpha_channel_enabled = 0;
67         }
68
69         icon_theme = gtk_icon_theme_get_default();
70         icon = gtk_icon_theme_load_icon(icon_theme, "psensor", 48, 0, NULL);
71         if (icon)
72                 gtk_window_set_icon(GTK_WINDOW(window), icon);
73         else
74                 fprintf(stderr, _("ERROR: Failed to load psensor icon.\n"));
75
76         g_signal_connect(window,
77                          "delete_event", G_CALLBACK(on_delete_event_cb), ui);
78
79         gtk_window_set_decorated(GTK_WINDOW(window),
80                                  ui->config->window_decoration_enabled);
81
82         gtk_window_set_keep_below(GTK_WINDOW(window),
83                                   ui->config->window_keep_below_enabled);
84
85         return window;
86 }