| 1 |
/* |
| 2 |
* Copyright (C) Pietro Pilolli 2010 <[email protected]> |
| 3 |
* |
| 4 |
* Curtain is free software: you can redistribute it and/or modify it |
| 5 |
* under the terms of the GNU General Public License as published by the |
| 6 |
* Free Software Foundation, either version 3 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* Curtain is distributed in the hope that it will be useful, but |
| 10 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
* See the GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License along |
| 15 |
* with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
|
| 19 |
#include "curtain.h" |
| 20 |
#include "callbacks.h" |
| 21 |
#include "utils.h" |
| 22 |
|
| 23 |
|
| 24 |
#ifndef _WIN32 |
| 25 |
/* Call the dialog that inform the user to enable a composite manager. */ |
| 26 |
static void |
| 27 |
run_missing_composite_manager_dialog () |
| 28 |
{ |
| 29 |
GtkWidget *msg_dialog; |
| 30 |
msg_dialog = gtk_message_dialog_new (NULL, |
| 31 |
GTK_DIALOG_MODAL, |
| 32 |
GTK_MESSAGE_ERROR, |
| 33 |
GTK_BUTTONS_OK, |
| 34 |
gettext ("In order to run Curtain you need to enable a composite manager")); |
| 35 |
|
| 36 |
gtk_dialog_run (GTK_DIALOG (msg_dialog)); |
| 37 |
|
| 38 |
if (msg_dialog != NULL) |
| 39 |
{ |
| 40 |
gtk_widget_destroy (msg_dialog); |
| 41 |
msg_dialog = NULL; |
| 42 |
} |
| 43 |
|
| 44 |
exit (EXIT_FAILURE); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
/* Check if a composite manager is active. */ |
| 49 |
static void |
| 50 |
check_composite_manager () |
| 51 |
{ |
| 52 |
GdkDisplay *display = gdk_display_get_default (); |
| 53 |
GdkScreen *screen = gdk_display_get_default_screen (display); |
| 54 |
gboolean composite = gdk_screen_is_composited (screen); |
| 55 |
|
| 56 |
if (!composite) |
| 57 |
{ |
| 58 |
/* start the enable composite manager dialog. */ |
| 59 |
run_missing_composite_manager_dialog (); |
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
#endif |
| 65 |
|
| 66 |
|
| 67 |
/* Enable the localization support with gettext. */ |
| 68 |
static void |
| 69 |
enable_localization_support () |
| 70 |
{ |
| 71 |
#ifdef ENABLE_NLS |
| 72 |
setlocale (LC_ALL, ""); |
| 73 |
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); |
| 74 |
textdomain (GETTEXT_PACKAGE); |
| 75 |
#endif |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
/* Create the window. */ |
| 80 |
GtkWidget* |
| 81 |
create_window (void) |
| 82 |
{ |
| 83 |
GtkWidget *window = (GtkWidget *) NULL; |
| 84 |
GtkBuilder *builder = (GtkBuilder *) NULL; |
| 85 |
GError* error = (GError *) NULL; |
| 86 |
|
| 87 |
builder = gtk_builder_new (); |
| 88 |
if (!gtk_builder_add_from_file (builder, UI_FILE, &error)) |
| 89 |
{ |
| 90 |
g_warning ("Couldn't load builder file: %s", error->message); |
| 91 |
g_error_free (error); |
| 92 |
} |
| 93 |
|
| 94 |
window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); |
| 95 |
|
| 96 |
/* This trys to set an alpha channel. */ |
| 97 |
on_window_screen_changed(window, NULL, NULL); |
| 98 |
gint width = gdk_screen_width (); |
| 99 |
gint height = gdk_screen_height (); |
| 100 |
|
| 101 |
/* In the gtk 2.16.6 the gtkbuilder property double-buffered is not parsed from the glade file |
| 102 |
* and then I set this by hands. |
| 103 |
*/ |
| 104 |
gtk_widget_set_double_buffered (window, FALSE); |
| 105 |
gtk_widget_set_size_request (window, width, height); |
| 106 |
gtk_window_fullscreen (GTK_WINDOW (window)); |
| 107 |
|
| 108 |
/* This is important; connect the gtk signals for callbacks. */ |
| 109 |
gtk_builder_connect_signals (builder, NULL); |
| 110 |
|
| 111 |
g_object_unref (builder); |
| 112 |
|
| 113 |
return window; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
/* Main entry of the program. */ |
| 118 |
int |
| 119 |
main (int argc, |
| 120 |
char *argv[]) |
| 121 |
{ |
| 122 |
GtkWidget *window; |
| 123 |
|
| 124 |
/* Enable the localization support with gettext. */ |
| 125 |
enable_localization_support (); |
| 126 |
gtk_init (&argc, &argv); |
| 127 |
|
| 128 |
#ifndef _WIN32 |
| 129 |
check_composite_manager (); |
| 130 |
#endif |
| 131 |
|
| 132 |
window = create_window (); |
| 133 |
gtk_window_set_keep_above(GTK_WINDOW(window), TRUE); |
| 134 |
gtk_widget_show_all (window); |
| 135 |
|
| 136 |
gtk_main (); |
| 137 |
return 0; |
| 138 |
} |
| 139 |
|
| 140 |
|