diff --git a/CPPLINT.cfg b/CPPLINT.cfg new file mode 100644 index 0000000000000000000000000000000000000000..b1e51b79c2924edc480ecea0c457d62d328850d8 --- /dev/null +++ b/CPPLINT.cfg @@ -0,0 +1,3 @@ +filter=-whitespace/parens,-whitespace/braces,-readability/casting,-runtime/int,-build/include_what_you_use +linelength=120 +extensions=c,h diff --git a/savers/floaters.c b/savers/floaters.c index a99e3dd019d9c6af4e4917f50d4016bcd2147272..e2e300af863ef5ba31a466950c08cc5559301076 100644 --- a/savers/floaters.c +++ b/savers/floaters.c @@ -26,7 +26,7 @@ * Sean Davis <bluesabre@xfce.org> */ -#include "config.h" +#include <config.h> #include <math.h> #include <stdlib.h> @@ -34,13 +34,12 @@ #include <time.h> #include <glib.h> - #include <gdk/gdk.h> #include <gtk/gtk.h> #include <libxfce4util/libxfce4util.h> -#include "gs-theme-window.h" +#include "savers/gs-theme-window.h" #ifndef trunc #define trunc(x) (((x) > 0.0) ? floor((x)) : -floor(-(x))) @@ -84,8 +83,7 @@ static gint max_floater_count = FLOATER_DEFAULT_COUNT; static gchar *geometry = NULL; static gchar **filenames = NULL; -static GOptionEntry options[] = -{ +static GOptionEntry options[] = { { "show-paths", 'p', 0, G_OPTION_ARG_NONE, &should_show_paths, N_("Show paths that images follow"), NULL @@ -127,13 +125,11 @@ typedef struct _ScreenSaverFloater ScreenSaverFloater; typedef struct _CachedSource CachedSource; typedef struct _ScreenSaver ScreenSaver; -struct _Point -{ +struct _Point { gdouble x, y; }; -struct _Path -{ +struct _Path { Point start_point; Point start_control_point; Point end_control_point; @@ -151,20 +147,17 @@ struct _Path gdouble duration; }; -struct _CachedSource -{ +struct _CachedSource { cairo_pattern_t *pattern; gint width, height; }; -struct _Rectangle -{ +struct _Rectangle { Point top_left_point; Point bottom_right_point; }; -struct _ScreenSaverFloater -{ +struct _ScreenSaverFloater { GdkRectangle bounds; Point start_position; @@ -182,8 +175,7 @@ struct _ScreenSaverFloater gdouble angle_increment; }; -struct _ScreenSaver -{ +struct _ScreenSaver { GtkWidget *drawing_area; Rectangle canvas_rectangle; GHashTable *cached_sources; @@ -293,8 +285,7 @@ static GdkPixbuf *gamma_correct (const GdkPixbuf *input_pixbuf); static CachedSource* cached_source_new (cairo_pattern_t *pattern, gint width, - gint height) -{ + gint height) { CachedSource *source; source = g_new (CachedSource, 1); @@ -306,8 +297,7 @@ cached_source_new (cairo_pattern_t *pattern, } static void -cached_source_free (CachedSource *source) -{ +cached_source_free (CachedSource *source) { if (source == NULL) return; @@ -321,8 +311,7 @@ path_new (Point *start_point, Point *start_control_point, Point *end_control_point, Point *end_point, - gdouble duration) -{ + gdouble duration) { Path *path; path = g_new (Path, 1); @@ -356,16 +345,14 @@ path_new (Point *start_point, } static void -path_free (Path *path) -{ +path_free (Path *path) { g_free (path); } static ScreenSaverFloater* screen_saver_floater_new (ScreenSaver *screen_saver, Point *position, - gdouble scale) -{ + gdouble scale) { ScreenSaverFloater *floater; floater = g_new (ScreenSaverFloater, 1); @@ -387,8 +374,7 @@ screen_saver_floater_new (ScreenSaver *screen_saver, void screen_saver_floater_free (ScreenSaver *screen_saver, - ScreenSaverFloater *floater) -{ + ScreenSaverFloater *floater) { if (floater == NULL) return; @@ -399,8 +385,7 @@ screen_saver_floater_free (ScreenSaver *screen_saver, static gboolean screen_saver_floater_is_off_canvas (ScreenSaver *screen_saver, - ScreenSaverFloater *floater) -{ + ScreenSaverFloater *floater) { if ((floater->position.x < screen_saver->canvas_rectangle.top_left_point.x) || (floater->position.x > screen_saver->canvas_rectangle.bottom_right_point.x) || (floater->position.y < screen_saver->canvas_rectangle.top_left_point.y) || @@ -414,14 +399,12 @@ static gboolean screen_saver_floater_should_come_on_screen (ScreenSaver *screen_saver, ScreenSaverFloater *floater, gdouble performance_ratio, - gdouble *duration) -{ + gdouble *duration) { if (!screen_saver_floater_is_off_canvas (screen_saver, floater)) return FALSE; if ((fabs (performance_ratio - .5) >= G_MINDOUBLE) && - (g_random_double () > .5)) - { + (g_random_double () > .5)) { if (duration) *duration = g_random_double_range (3.0, 7.0); @@ -435,18 +418,15 @@ static gboolean screen_saver_floater_should_bubble_up (ScreenSaver *screen_saver, ScreenSaverFloater *floater, gdouble performance_ratio, - gdouble *duration) -{ - if ((performance_ratio < .5) && (g_random_double () > .5)) - { + gdouble *duration) { + if ((performance_ratio < .5) && (g_random_double () > .5)) { if (duration) *duration = performance_ratio * 30.0; return TRUE; } - if ((floater->scale < .3) && (g_random_double () > .6)) - { + if ((floater->scale < .3) && (g_random_double () > .6)) { if (duration) *duration = 30.0; @@ -459,8 +439,7 @@ screen_saver_floater_should_bubble_up (ScreenSaver *screen_saver, static Point screen_saver_floater_get_position_from_time (ScreenSaver *screen_saver, ScreenSaverFloater *floater, - gdouble time) -{ + gdouble time) { Point point; time = time / floater->path->duration; @@ -480,8 +459,7 @@ screen_saver_floater_get_position_from_time (ScreenSaver *screen_saver, static gdouble screen_saver_floater_get_scale_from_time (ScreenSaver *screen_saver, ScreenSaverFloater *floater, - gdouble time) -{ + gdouble time) { gdouble completion_ratio, total_scale_growth, new_scale; completion_ratio = time / floater->path->duration; @@ -494,8 +472,7 @@ screen_saver_floater_get_scale_from_time (ScreenSaver *screen_saver, static gdouble screen_saver_floater_get_angle_from_time (ScreenSaver *screen_saver, ScreenSaverFloater *floater, - gdouble time) -{ + gdouble time) { gdouble completion_ratio; gdouble total_rotation; @@ -508,8 +485,7 @@ screen_saver_floater_get_angle_from_time (ScreenSaver *screen_saver, static Path * screen_saver_floater_create_path_to_on_screen (ScreenSaver *screen_saver, ScreenSaverFloater *floater, - gdouble duration) -{ + gdouble duration) { Point start_position, end_position, start_control_point, end_control_point; start_position = floater->position; @@ -533,8 +509,7 @@ screen_saver_floater_create_path_to_on_screen (ScreenSaver *screen_saver, static Path * screen_saver_floater_create_path_to_bubble_up (ScreenSaver *screen_saver, ScreenSaverFloater *floater, - gdouble duration) -{ + gdouble duration) { Point start_position, end_position, start_control_point, end_control_point; start_position = floater->position; @@ -552,8 +527,7 @@ screen_saver_floater_create_path_to_bubble_up (ScreenSaver *screen_saver, static Path * screen_saver_floater_create_path_to_random_point (ScreenSaver *screen_saver, ScreenSaverFloater *floater, - gdouble duration) -{ + gdouble duration) { Point start_position, end_position, start_control_point, end_control_point; start_position = floater->position; @@ -575,8 +549,7 @@ screen_saver_floater_create_path_to_random_point (ScreenSaver *screen_sav static Path * screen_saver_floater_create_path (ScreenSaver *screen_saver, - ScreenSaverFloater *floater) -{ + ScreenSaverFloater *floater) { gdouble performance_ratio; gdouble duration; @@ -599,15 +572,13 @@ screen_saver_floater_create_path (ScreenSaver *screen_saver, static void screen_saver_floater_update_state (ScreenSaver *screen_saver, ScreenSaverFloater *floater, - gdouble time) -{ + gdouble time) { gdouble performance_ratio; performance_ratio = screen_saver_get_frames_per_second (screen_saver) / OPTIMAL_FRAME_RATE; - if (floater->path == NULL) - { + if (floater->path == NULL) { floater->path = screen_saver_floater_create_path (screen_saver, floater); floater->path_start_time = time; @@ -618,8 +589,7 @@ screen_saver_floater_update_state (ScreenSaver *screen_saver, /* poor man's distribution */ if (screen_saver->should_do_rotations && - (g_random_double () < .75 * performance_ratio)) - { + (g_random_double () < .75 * performance_ratio)) { gint r; r = g_random_int_range (0, 100); @@ -632,8 +602,7 @@ screen_saver_floater_update_state (ScreenSaver *screen_saver, } } - if (time < (floater->path_start_time + floater->path->duration)) - { + if (time < (floater->path_start_time + floater->path->duration)) { gdouble path_time; path_time = time - floater->path_start_time; @@ -648,9 +617,7 @@ screen_saver_floater_update_state (ScreenSaver *screen_saver, screen_saver_floater_get_angle_from_time (screen_saver, floater, path_time); floater->opacity = pow (floater->scale, 1.0 / GAMMA); - } - else - { + } else { path_free (floater->path); floater->path = NULL; @@ -659,8 +626,7 @@ screen_saver_floater_update_state (ScreenSaver *screen_saver, } static GdkPixbuf * -gamma_correct (const GdkPixbuf *input_pixbuf) -{ +gamma_correct (const GdkPixbuf *input_pixbuf) { gint x, y, width, height, rowstride; GdkPixbuf *output_pixbuf; guchar *pixels; @@ -673,8 +639,7 @@ gamma_correct (const GdkPixbuf *input_pixbuf) rowstride = gdk_pixbuf_get_rowstride (output_pixbuf); for (y = 0; y < height; y++) - for (x = 0; x < width; x++) - { + for (x = 0; x < width; x++) { guchar *alpha_channel; guchar opacity; @@ -690,8 +655,7 @@ gamma_correct (const GdkPixbuf *input_pixbuf) static gboolean screen_saver_floater_do_draw (ScreenSaver *screen_saver, ScreenSaverFloater *floater, - cairo_t *context) -{ + cairo_t *context) { gint size; CachedSource *source; @@ -700,8 +664,7 @@ screen_saver_floater_do_draw (ScreenSaver *screen_saver, source = g_hash_table_lookup (screen_saver->cached_sources, GINT_TO_POINTER (size)); - if (source == NULL) - { + if (source == NULL) { GdkPixbuf *pixbuf; GError *error; @@ -710,8 +673,7 @@ screen_saver_floater_do_draw (ScreenSaver *screen_saver, pixbuf = gdk_pixbuf_new_from_file_at_size (screen_saver->filename, size, -1, &error); - if (pixbuf == NULL) - { + if (pixbuf == NULL) { g_assert (error != NULL); g_printerr ("%s", _(error->message)); g_error_free (error); @@ -733,8 +695,7 @@ screen_saver_floater_do_draw (ScreenSaver *screen_saver, cairo_save (context); - if (screen_saver->should_do_rotations && (fabs (floater->angle) > G_MINDOUBLE)) - { + if (screen_saver->should_do_rotations && (fabs (floater->angle) > G_MINDOUBLE)) { floater->bounds.width = G_SQRT2 * source->width + 2; floater->bounds.height = G_SQRT2 * source->height + 2; floater->bounds.x = (int) (floater->position.x - .5 * G_SQRT2 * source->width) - 1; @@ -747,9 +708,7 @@ screen_saver_floater_do_draw (ScreenSaver *screen_saver, cairo_translate (context, -trunc (floater->position.x), -trunc (floater->position.y)); - } - else - { + } else { floater->bounds.width = source->width + 2; floater->bounds.height = source->height + 2; floater->bounds.x = (int) (floater->position.x - .5 * source->width) - 1; @@ -771,8 +730,7 @@ screen_saver_floater_do_draw (ScreenSaver *screen_saver, cairo_paint_with_alpha (context, floater->opacity); cairo_restore (context); - if (screen_saver->should_show_paths && (floater->path != NULL)) - { + if (screen_saver->should_show_paths && (floater->path != NULL)) { gdouble dash_pattern[] = { 5.0 }; cairo_save (context); @@ -839,8 +797,7 @@ screen_saver_new (GtkWidget *drawing_area, const gchar *filename, gint max_floater_count, gboolean should_do_rotations, - gboolean should_show_paths) -{ + gboolean should_show_paths) { ScreenSaver *screen_saver; screen_saver = g_new (ScreenSaver, 1); @@ -885,8 +842,7 @@ screen_saver_new (GtkWidget *drawing_area, } static void -screen_saver_free (ScreenSaver *screen_saver) -{ +screen_saver_free (ScreenSaver *screen_saver) { if (screen_saver == NULL) return; @@ -910,8 +866,7 @@ screen_saver_free (ScreenSaver *screen_saver) } static gdouble -screen_saver_get_timestamp (ScreenSaver *screen_saver) -{ +screen_saver_get_timestamp (ScreenSaver *screen_saver) { const gdouble microseconds_per_second = (gdouble ) G_USEC_PER_SEC; gdouble timestamp; GTimeVal now = { 0L, /* zero-filled */ }; @@ -924,12 +879,10 @@ screen_saver_get_timestamp (ScreenSaver *screen_saver) } static void -screen_saver_create_floaters (ScreenSaver *screen_saver) -{ +screen_saver_create_floaters (ScreenSaver *screen_saver) { gint i; - for (i = 0; i < screen_saver->max_floater_count; i++) - { + for (i = 0; i < screen_saver->max_floater_count; i++) { ScreenSaverFloater *floater; Point position; gdouble scale; @@ -949,28 +902,24 @@ screen_saver_create_floaters (ScreenSaver *screen_saver) } static gdouble -screen_saver_get_updates_per_second (ScreenSaver *screen_saver) -{ +screen_saver_get_updates_per_second (ScreenSaver *screen_saver) { return screen_saver->updates_per_second; } static gdouble -screen_saver_get_frames_per_second (ScreenSaver *screen_saver) -{ +screen_saver_get_frames_per_second (ScreenSaver *screen_saver) { return screen_saver->frames_per_second; } static gdouble -screen_saver_get_image_cache_usage (ScreenSaver *screen_saver) -{ +screen_saver_get_image_cache_usage (ScreenSaver *screen_saver) { static const gdouble cache_capacity = (FLOATER_MAX_SIZE - FLOATER_MIN_SIZE + 1); return g_hash_table_size (screen_saver->cached_sources) / cache_capacity; } static void -screen_saver_destroy_floaters (ScreenSaver *screen_saver) -{ +screen_saver_destroy_floaters (ScreenSaver *screen_saver) { if (screen_saver->floaters == NULL) return; @@ -983,8 +932,7 @@ screen_saver_destroy_floaters (ScreenSaver *screen_saver) static void screen_saver_on_size_allocate (ScreenSaver *screen_saver, - GtkAllocation *allocation) -{ + GtkAllocation *allocation) { Rectangle canvas_rectangle; canvas_rectangle.top_left_point.x = allocation->x - .1 * allocation->width; @@ -998,8 +946,7 @@ screen_saver_on_size_allocate (ScreenSaver *screen_saver, static gint compare_floaters (ScreenSaverFloater *a, - ScreenSaverFloater *b) -{ + ScreenSaverFloater *b) { if (a->scale > b->scale) return 1; else if (fabs (a->scale - b->scale) <= G_MINDOUBLE) @@ -1010,8 +957,7 @@ compare_floaters (ScreenSaverFloater *a, static void screen_saver_on_draw (ScreenSaver *screen_saver, - cairo_t *context) -{ + cairo_t *context) { GList *tmp; if (screen_saver->floaters == NULL) @@ -1020,14 +966,12 @@ screen_saver_on_draw (ScreenSaver *screen_saver, screen_saver->floaters = g_list_sort (screen_saver->floaters, (GCompareFunc)compare_floaters); - for (tmp = screen_saver->floaters; tmp != NULL; tmp = tmp->next) - { + for (tmp = screen_saver->floaters; tmp != NULL; tmp = tmp->next) { ScreenSaverFloater *floater; floater = (ScreenSaverFloater *) tmp->data; - if (!screen_saver_floater_do_draw (screen_saver, floater, context)) - { + if (!screen_saver_floater_do_draw (screen_saver, floater, context)) { gtk_main_quit (); break; } @@ -1039,22 +983,19 @@ screen_saver_on_draw (ScreenSaver *screen_saver, static void screen_saver_update_state (ScreenSaver *screen_saver, - gdouble time) -{ + gdouble time) { GList *tmp; tmp = screen_saver->floaters; - while (tmp != NULL) - { + while (tmp != NULL) { ScreenSaverFloater *floater; floater = (ScreenSaverFloater *) tmp->data; screen_saver_floater_update_state (screen_saver, floater, time); if (screen_saver->drawing_area != NULL && - gtk_widget_get_realized (screen_saver->drawing_area) && - (floater->bounds.width > 0) && (floater->bounds.height > 0)) - { + gtk_widget_get_realized (screen_saver->drawing_area) && + (floater->bounds.width > 0) && (floater->bounds.height > 0)) { gint size; size = CLAMP ((int) (FLOATER_MAX_SIZE * floater->scale), FLOATER_MIN_SIZE, FLOATER_MAX_SIZE); @@ -1093,23 +1034,20 @@ screen_saver_update_state (ScreenSaver *screen_saver, } static void -screen_saver_get_initial_state (ScreenSaver *screen_saver) -{ +screen_saver_get_initial_state (ScreenSaver *screen_saver) { screen_saver->first_update_time = screen_saver_get_timestamp (screen_saver); screen_saver_update_state (screen_saver, 0.0); } static gboolean -screen_saver_do_update_state (ScreenSaver *screen_saver) -{ +screen_saver_do_update_state (ScreenSaver *screen_saver) { gdouble current_update_time; /* flush pending requests to the X server and block for * replies before proceeding to help prevent the X server from * getting overrun with requests */ - if (screen_saver->draw_ops_pending) - { + if (screen_saver->draw_ops_pending) { GdkDisplay *display; display = gtk_widget_get_display (GTK_WIDGET(screen_saver->drawing_area)); @@ -1125,8 +1063,7 @@ screen_saver_do_update_state (ScreenSaver *screen_saver) } static gboolean -screen_saver_do_update_stats (ScreenSaver *screen_saver) -{ +screen_saver_do_update_stats (ScreenSaver *screen_saver) { gdouble last_calculated_stats_time, seconds_since_last_stats_update; last_calculated_stats_time = screen_saver->current_calculated_stats_time; @@ -1152,9 +1089,7 @@ screen_saver_do_update_stats (ScreenSaver *screen_saver) } static gboolean -do_print_screen_saver_stats (ScreenSaver *screen_saver) -{ - +do_print_screen_saver_stats (ScreenSaver *screen_saver) { g_print ("updates per second: %.2f, frames per second: %.2f, " "image cache %.0f%% full\n", screen_saver_get_updates_per_second (screen_saver), @@ -1166,8 +1101,7 @@ do_print_screen_saver_stats (ScreenSaver *screen_saver) int main (int argc, - char *argv[]) -{ + char *argv[]) { ScreenSaver *screen_saver; GtkWidget *window; GtkWidget *drawing_area; @@ -1186,9 +1120,7 @@ main (int argc, _("image - floats images around the screen"), options, GETTEXT_PACKAGE, &error); - - if (error != NULL) - { + if (error != NULL) { g_printerr (_("%s. See --help for usage information.\n"), _(error->message)); g_error_free (error); @@ -1196,8 +1128,7 @@ main (int argc, } if ((filenames == NULL) || (filenames[0] == NULL) || - (filenames[1] != NULL)) - { + (filenames[1] != NULL)) { g_printerr (_("You must specify one image. See --help for usage " "information.\n")); return EX_USAGE; diff --git a/savers/gs-theme-engine.c b/savers/gs-theme-engine.c index b826ebcbcef584c9ab708bbaad14655b901d5f97..1e73d68b042cabcd58e33ddf9b2255045fc97a5d 100644 --- a/savers/gs-theme-engine.c +++ b/savers/gs-theme-engine.c @@ -20,7 +20,7 @@ * */ -#include "config.h" +#include <config.h> #include <stdio.h> #include <stdlib.h> @@ -29,15 +29,14 @@ #include <glib.h> #include <gtk/gtk.h> -#include "gs-theme-engine.h" -#include "gs-theme-engine-marshal.h" +#include "savers/gs-theme-engine.h" +#include "savers/gs-theme-engine-marshal.h" static void gs_theme_engine_class_init (GSThemeEngineClass *klass); static void gs_theme_engine_init (GSThemeEngine *engine); static void gs_theme_engine_finalize (GObject *object); -struct GSThemeEnginePrivate -{ +struct GSThemeEnginePrivate { gpointer reserved; }; @@ -49,8 +48,7 @@ void _gs_theme_engine_profile_log (const char *func, const char *note, const char *format, - ...) -{ + ...) { va_list args; char *str; char *formatted; @@ -59,12 +57,9 @@ _gs_theme_engine_profile_log (const char *func, formatted = g_strdup_vprintf (format, args); va_end (args); - if (func != NULL) - { + if (func != NULL) { str = g_strdup_printf ("MARK: %s %s: %s %s", g_get_prgname(), func, note ? note : "", formatted); - } - else - { + } else { str = g_strdup_printf ("MARK: %s: %s %s", g_get_prgname(), note ? note : "", formatted); } @@ -78,12 +73,10 @@ static void gs_theme_engine_set_property (GObject *object, guint prop_id, const GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GS_THEME_ENGINE (object); - switch (prop_id) - { + switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -94,12 +87,10 @@ static void gs_theme_engine_get_property (GObject *object, guint prop_id, GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GS_THEME_ENGINE (object); - switch (prop_id) - { + switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -108,8 +99,7 @@ gs_theme_engine_get_property (GObject *object, static gboolean gs_theme_engine_real_draw (GtkWidget *widget, - cairo_t *cr) -{ + cairo_t *cr) { cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgb (cr, 0, 0, 0); cairo_paint (cr); @@ -118,8 +108,7 @@ gs_theme_engine_real_draw (GtkWidget *widget, } static void -gs_theme_engine_class_init (GSThemeEngineClass *klass) -{ +gs_theme_engine_class_init (GSThemeEngineClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); @@ -133,14 +122,12 @@ gs_theme_engine_class_init (GSThemeEngineClass *klass) } static void -gs_theme_engine_init (GSThemeEngine *engine) -{ +gs_theme_engine_init (GSThemeEngine *engine) { engine->priv = gs_theme_engine_get_instance_private (engine); } static void -gs_theme_engine_finalize (GObject *object) -{ +gs_theme_engine_finalize (GObject *object) { GSThemeEngine *engine; g_return_if_fail (object != NULL); @@ -156,21 +143,17 @@ gs_theme_engine_finalize (GObject *object) void gs_theme_engine_get_window_size (GSThemeEngine *engine, int *width, - int *height) -{ - if (width != NULL) - { + int *height) { + if (width != NULL) { *width = 0; } - if (height != NULL) - { + if (height != NULL) { *height = 0; } g_return_if_fail (GS_IS_THEME_ENGINE (engine)); - if (! gtk_widget_get_visible (GTK_WIDGET (engine))) - { + if (!gtk_widget_get_visible (GTK_WIDGET (engine))) { return; } @@ -182,8 +165,7 @@ gs_theme_engine_get_window_size (GSThemeEngine *engine, } GdkWindow * -gs_theme_engine_get_window (GSThemeEngine *engine) -{ +gs_theme_engine_get_window (GSThemeEngine *engine) { g_return_val_if_fail (GS_IS_THEME_ENGINE (engine), NULL); return gtk_widget_get_window (GTK_WIDGET (engine)); diff --git a/savers/gs-theme-window.c b/savers/gs-theme-window.c index 3b735d3586cba18f83a5d363a83ce4ed17b6d688..9c488e5020db760f45216a158969e71a3133bc74 100644 --- a/savers/gs-theme-window.c +++ b/savers/gs-theme-window.c @@ -24,18 +24,17 @@ * Originally written by: Ray Strode <rstrode@redhat.com> */ -#include "config.h" +#include <config.h> #include <errno.h> #include <stdlib.h> #include <glib.h> #include <glib-object.h> - #include <gdk/gdkx.h> #include <gtk/gtk.h> -#include "gs-theme-window.h" +#include "savers/gs-theme-window.h" static void gs_theme_window_finalize (GObject *object); static void gs_theme_window_real_realize (GtkWidget *widget); @@ -47,8 +46,7 @@ G_DEFINE_TYPE (GSThemeWindow, gs_theme_window, GTK_TYPE_WINDOW) #define MIN_SIZE 10 static void -gs_theme_window_class_init (GSThemeWindowClass *klass) -{ +gs_theme_window_class_init (GSThemeWindowClass *klass) { GObjectClass *object_class; GtkWidgetClass *widget_class; @@ -63,14 +61,12 @@ gs_theme_window_class_init (GSThemeWindowClass *klass) } static void -gs_theme_window_init (GSThemeWindow *window) -{ +gs_theme_window_init (GSThemeWindow *window) { gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE); } static void -gs_theme_window_finalize (GObject *object) -{ +gs_theme_window_finalize (GObject *object) { GObjectClass *parent_class; GS_THEME_WINDOW (object); @@ -82,8 +78,7 @@ gs_theme_window_finalize (GObject *object) } static void -gs_theme_window_real_realize (GtkWidget *widget) -{ +gs_theme_window_real_realize (GtkWidget *widget) { GdkWindow *window; Window remote_xwindow; GtkRequisition requisition; @@ -99,19 +94,16 @@ gs_theme_window_real_realize (GtkWidget *widget) window = NULL; preview_xid = g_getenv ("XSCREENSAVER_WINDOW"); - if (preview_xid != NULL) - { + if (preview_xid != NULL) { char *end; remote_xwindow = (Window) strtoul (preview_xid, &end, 0); if ((remote_xwindow != 0) && (end != NULL) && ((*end == ' ') || (*end == '\0')) && - ((remote_xwindow < G_MAXULONG) || (errno != ERANGE))) - { + ((remote_xwindow < G_MAXULONG) || (errno != ERANGE))) { window = gdk_x11_window_foreign_new_for_display (gdk_display_get_default (), remote_xwindow); - if (window != NULL) - { + if (window != NULL) { /* This is a kludge; we need to set the same * flags gs-window-x11.c does, to ensure they * don't get unset by gtk_window_map() later. @@ -131,8 +123,7 @@ gs_theme_window_real_realize (GtkWidget *widget) } } - if (window == NULL) - { + if (window == NULL) { GtkWidgetClass *parent_class; parent_class = GTK_WIDGET_CLASS (gs_theme_window_parent_class); @@ -156,8 +147,7 @@ gs_theme_window_real_realize (GtkWidget *widget) gdk_window_get_geometry (window, &x, &y, &width, &height); - if (width < MIN_SIZE || height < MIN_SIZE) - { + if (width < MIN_SIZE || height < MIN_SIZE) { g_critical ("This window is way too small to use"); exit (1); } @@ -172,8 +162,7 @@ gs_theme_window_real_realize (GtkWidget *widget) } GtkWidget * -gs_theme_window_new (void) -{ +gs_theme_window_new (void) { GSThemeWindow *window; window = g_object_new (GS_TYPE_THEME_WINDOW, diff --git a/savers/gste-popsquares.c b/savers/gste-popsquares.c index e1adaf0d889ca3cff7e628427214bc66a18dc4b5..f363a5df7d64d23a1b93b5c71cffadc90f71ea7e 100644 --- a/savers/gste-popsquares.c +++ b/savers/gste-popsquares.c @@ -20,18 +20,18 @@ * */ -#include "config.h" +#include <config.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> +#include <unistd.h> #include <glib.h> #include <gtk/gtk.h> -#include "gs-theme-engine.h" -#include "gste-popsquares.h" +#include "savers/gs-theme-engine.h" +#include "savers/gste-popsquares.h" static void gste_popsquares_class_init (GSTEPopsquaresClass *klass); static void gste_popsquares_init (GSTEPopsquares *engine); @@ -39,14 +39,12 @@ static void gste_popsquares_finalize (GObject *object); static void draw_frame (GSTEPopsquares *pop, cairo_t *cr); -typedef struct _square -{ +typedef struct _square { int x, y, w, h; int color; } square; -struct GSTEPopsquaresPrivate -{ +struct GSTEPopsquaresPrivate { guint timeout_id; int ncolors; @@ -66,27 +64,22 @@ hsv_to_rgb (int h, double v, double *r, double *g, - double *b) -{ + double *b) { double H, S, V, R, G, B; double p1, p2, p3; double f; int i; - if (s < 0) - { + if (s < 0) { s = 0; } - if (v < 0) - { + if (v < 0) { v = 0; } - if (s > 1) - { + if (s > 1) { s = 1; } - if (v > 1) - { + if (v > 1) { v = 1; } @@ -99,38 +92,27 @@ hsv_to_rgb (int h, p2 = V * (1 - (S * f)); p3 = V * (1 - (S * (1 - f))); - if (i == 0) - { + if (i == 0) { R = V; G = p3; B = p1; - } - else if (i == 1) - { + } else if (i == 1) { R = p2; G = V; B = p1; - } - else if (i == 2) - { + } else if (i == 2) { R = p1; G = V; B = p3; - } - else if (i == 3) - { + } else if (i == 3) { R = p1; G = p2; B = V; - } - else if (i == 4) - { + } else if (i == 4) { R = p3; G = p1; B = V; - } - else - { + } else { R = V; G = p1; B = p2; @@ -147,8 +129,7 @@ rgb_to_hsv (double r, double b, int *h, double *s, - double *v) -{ + double *v) { double R, G, B, H, S, V; double cmax, cmin; double cmm; @@ -161,48 +142,36 @@ rgb_to_hsv (double r, cmin = G; imax = 1; - if (cmax < G) - { + if (cmax < G) { cmax = G; cmin = R; imax = 2; } - if (cmax < B) - { + if (cmax < B) { cmax = B; imax = 3; } - if (cmin > B) - { + if (cmin > B) { cmin = B; } cmm = cmax - cmin; V = cmax; - if (cmm == 0) - { + if (cmm == 0) { S = H = 0; - } - else - { + } else { S = cmm / cmax; - if (imax == 1) - { + if (imax == 1) { H = (G - B) / cmm; - } - else if (imax == 2) - { + } else if (imax == 2) { H = 2.0 + (B - R) / cmm; - } - else - { + } else { /*if (imax == 3)*/ H = 4.0 + (R - G) / cmm; } - if (H < 0) - { + if (H < 0) { H += 6.0; } } @@ -221,16 +190,14 @@ make_color_ramp (int h1, double v2, GdkRGBA *colors, int n_colors, - gboolean closed) -{ + gboolean closed) { double dh, ds, dv; /* deltas */ int i; int ncolors, wanted; int total_ncolors = n_colors; wanted = total_ncolors; - if (closed) - { + if (closed) { wanted = (wanted / 2) + 1; } @@ -238,8 +205,7 @@ make_color_ramp (int h1, memset (colors, 0, n_colors * sizeof (*colors)); - if (closed) - { + if (closed) { ncolors = (ncolors / 2) + 1; } @@ -252,39 +218,33 @@ make_color_ramp (int h1, ds = (s2 - s1) / ncolors; dv = (v2 - v1) / ncolors; - for (i = 0; i < ncolors; i++) - { + for (i = 0; i < ncolors; i++) { hsv_to_rgb ((int) (h1 + (i * dh)), (s1 + (i * ds)), (v1 + (i * dv)), - &colors [i].red, - &colors [i].green, - &colors [i].blue); - colors [i].alpha = 1.0; + &colors[i].red, + &colors[i].green, + &colors[i].blue); + colors[i].alpha = 1.0; } - if (closed) - { - for (i = ncolors; i < n_colors; i++) - { - colors [i] = colors [n_colors - i]; + if (closed) { + for (i = ncolors; i < n_colors; i++) { + colors[i] = colors[n_colors - i]; } } - } static void randomize_square_colors (square *squares, int nsquares, - int ncolors) -{ + int ncolors) { int i; square *s; s = squares; - for (i = 0; i < nsquares; i++) - { + for (i = 0; i < nsquares; i++) { s[i].color = g_random_int_range (0, ncolors); } } @@ -292,8 +252,7 @@ randomize_square_colors (square *squares, static void set_colors (GtkWidget *widget, GdkRGBA *fg, - GdkRGBA *bg) -{ + GdkRGBA *bg) { GtkStyleContext *style; style = gtk_widget_get_style_context (widget); @@ -305,8 +264,7 @@ set_colors (GtkWidget *widget, gtk_style_context_get_state (style), bg); G_GNUC_END_IGNORE_DEPRECATIONS - if (bg->alpha == 0.0) - { + if (bg->alpha == 0.0) { gtk_style_context_add_class (style, GTK_STYLE_CLASS_VIEW); G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* GTK 3.16 */ gtk_style_context_get_background_color (style, @@ -326,12 +284,10 @@ static void gste_popsquares_set_property (GObject *object, guint prop_id, const GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GSTE_POPSQUARES (object); - switch (prop_id) - { + switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -342,12 +298,10 @@ static void gste_popsquares_get_property (GObject *object, guint prop_id, GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GSTE_POPSQUARES (object); - switch (prop_id) - { + switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -355,8 +309,7 @@ gste_popsquares_get_property (GObject *object, } static void -setup_squares (GSTEPopsquares *pop) -{ +setup_squares (GSTEPopsquares *pop) { int window_width; int window_height; int nsquares; @@ -366,8 +319,7 @@ setup_squares (GSTEPopsquares *pop) window = gs_theme_engine_get_window (GS_THEME_ENGINE (pop)); - if (window == NULL) - { + if (window == NULL) { return; } @@ -380,17 +332,14 @@ setup_squares (GSTEPopsquares *pop) gh = pop->priv->subdivision; nsquares = gw * gh; - if (pop->priv->squares) - { + if (pop->priv->squares) { g_free (pop->priv->squares); } pop->priv->squares = g_new0 (square, nsquares); - for (y = 0; y < gh; y++) - { - for (x = 0; x < gw; x++) - { - square *s = (square *) &pop->priv->squares [gw * y + x]; + for (y = 0; y < gh; y++) { + for (x = 0; x < gw; x++) { + square *s = (square *) &pop->priv->squares[gw * y + x]; s->w = sw; s->h = sh; s->x = x * sw; @@ -400,8 +349,7 @@ setup_squares (GSTEPopsquares *pop) } static void -setup_colors (GSTEPopsquares *pop) -{ +setup_colors (GSTEPopsquares *pop) { double s1, v1, s2, v2 = 0; int h1, h2 = 0; int nsquares; @@ -411,15 +359,13 @@ setup_colors (GSTEPopsquares *pop) window = gs_theme_engine_get_window (GS_THEME_ENGINE (pop)); - if (window == NULL) - { + if (window == NULL) { return; } set_colors (GTK_WIDGET (pop), &fg, &bg); - if (pop->priv->colors) - { + if (pop->priv->colors) { g_free (pop->priv->colors); } pop->priv->colors = g_new0 (GdkRGBA, pop->priv->ncolors); @@ -439,24 +385,21 @@ setup_colors (GSTEPopsquares *pop) } static void -gste_popsquares_real_show (GtkWidget *widget) -{ +gste_popsquares_real_show (GtkWidget *widget) { GSTEPopsquares *pop = GSTE_POPSQUARES (widget); /* start */ setup_squares (pop); setup_colors (pop); - if (GTK_WIDGET_CLASS (parent_class)->show) - { + if (GTK_WIDGET_CLASS (parent_class)->show) { GTK_WIDGET_CLASS (parent_class)->show (widget); } } static gboolean gste_popsquares_real_draw (GtkWidget *widget, - cairo_t *cr) -{ + cairo_t *cr) { if (GTK_WIDGET_CLASS (parent_class)->draw) { GTK_WIDGET_CLASS (parent_class)->draw (widget, cr); } @@ -468,8 +411,7 @@ gste_popsquares_real_draw (GtkWidget *widget, static gboolean gste_popsquares_real_configure (GtkWidget *widget, - GdkEventConfigure *event) -{ + GdkEventConfigure *event) { GSTEPopsquares *pop = GSTE_POPSQUARES (widget); gboolean handled = FALSE; @@ -482,8 +424,7 @@ gste_popsquares_real_configure (GtkWidget *widget, /* schedule a redraw */ gtk_widget_queue_draw (widget); - if (GTK_WIDGET_CLASS (parent_class)->configure_event) - { + if (GTK_WIDGET_CLASS (parent_class)->configure_event) { handled = GTK_WIDGET_CLASS (parent_class)->configure_event (widget, event); } @@ -491,8 +432,7 @@ gste_popsquares_real_configure (GtkWidget *widget, } static void -gste_popsquares_class_init (GSTEPopsquaresClass *klass) -{ +gste_popsquares_class_init (GSTEPopsquaresClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); @@ -509,8 +449,7 @@ gste_popsquares_class_init (GSTEPopsquaresClass *klass) static void draw_frame (GSTEPopsquares *pop, - cairo_t *cr) -{ + cairo_t *cr) { int border = 1; gboolean twitch = FALSE; int x, y; @@ -522,8 +461,7 @@ draw_frame (GSTEPopsquares *pop, window = gs_theme_engine_get_window (GS_THEME_ENGINE (pop)); - if (window == NULL) - { + if (window == NULL) { return; } @@ -535,27 +473,21 @@ draw_frame (GSTEPopsquares *pop, gh = pop->priv->subdivision; nsquares = gw * gh; - for (y = 0; y < gh; y++) - { - for (x = 0; x < gw; x++) - { - square *s = (square *) &pop->priv->squares [gw * y + x]; + for (y = 0; y < gh; y++) { + for (x = 0; x < gw; x++) { + square *s = (square *) &pop->priv->squares[gw * y + x]; - gdk_cairo_set_source_rgba (cr, &(pop->priv->colors [s->color])); + gdk_cairo_set_source_rgba (cr, &(pop->priv->colors[s->color])); cairo_rectangle (cr, s->x, s->y, border ? s->w - border : s->w, border ? s->h - border : s->h); cairo_fill (cr); s->color++; - if (s->color == pop->priv->ncolors) - { - if (twitch && ((g_random_int_range (0, 4)) == 0)) - { + if (s->color == pop->priv->ncolors) { + if (twitch && ((g_random_int_range (0, 4)) == 0)) { randomize_square_colors (pop->priv->squares, nsquares, pop->priv->ncolors); - } - else - { + } else { s->color = g_random_int_range (0, pop->priv->ncolors); } } @@ -564,15 +496,13 @@ draw_frame (GSTEPopsquares *pop, } static gboolean -draw_iter (GSTEPopsquares *pop) -{ +draw_iter (GSTEPopsquares *pop) { gtk_widget_queue_draw (GTK_WIDGET (pop)); return TRUE; } static void -gste_popsquares_init (GSTEPopsquares *pop) -{ +gste_popsquares_init (GSTEPopsquares *pop) { int delay; pop->priv = gste_popsquares_get_instance_private (pop); @@ -585,8 +515,7 @@ gste_popsquares_init (GSTEPopsquares *pop) } static void -gste_popsquares_finalize (GObject *object) -{ +gste_popsquares_finalize (GObject *object) { GSTEPopsquares *pop; g_return_if_fail (object != NULL); @@ -596,8 +525,7 @@ gste_popsquares_finalize (GObject *object) g_return_if_fail (pop->priv != NULL); - if (pop->priv->timeout_id > 0) - { + if (pop->priv->timeout_id > 0) { g_source_remove (pop->priv->timeout_id); pop->priv->timeout_id = 0; } diff --git a/savers/gste-slideshow.c b/savers/gste-slideshow.c index 313646c7678e64770b6ae5fb8fe3e8db6b2654d5..d3fb863b00b9ceace10555457adc4989c2c5689f 100644 --- a/savers/gste-slideshow.c +++ b/savers/gste-slideshow.c @@ -20,25 +20,24 @@ * */ -#include "config.h" +#include <config.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> +#include <unistd.h> #include <glib.h> #include <gtk/gtk.h> -#include "gs-theme-engine.h" -#include "gste-slideshow.h" +#include "savers/gs-theme-engine.h" +#include "savers/gste-slideshow.h" static void gste_slideshow_class_init (GSTESlideshowClass *klass); static void gste_slideshow_init (GSTESlideshow *engine); static void gste_slideshow_finalize (GObject *object); -struct GSTESlideshowPrivate -{ +struct GSTESlideshowPrivate { /* Image at full opacity */ cairo_pattern_t *pat1; /* Image at partial opacity */ @@ -79,8 +78,7 @@ struct GSTESlideshowPrivate gboolean fade_disabled; }; -enum -{ +enum { PROP_0, PROP_IMAGES_LOCATION, PROP_SORT_IMAGES, @@ -97,20 +95,17 @@ G_DEFINE_TYPE_WITH_PRIVATE (GSTESlideshow, gste_slideshow, GS_TYPE_THEME_ENGINE) #define DEFAULT_IMAGES_LOCATION DATADIR "/pixmaps/backgrounds" #define IMAGE_LOAD_TIMEOUT 10000 -typedef struct _Op -{ +typedef struct _Op { char *location; GSTESlideshow *slideshow; } Op; -typedef struct _OpResult -{ +typedef struct _OpResult { GdkPixbuf *pixbuf; } OpResult; static gboolean -push_load_image_func (GSTESlideshow *show) -{ +push_load_image_func (GSTESlideshow *show) { Op *op; gs_theme_engine_profile_msg ("Starting a new image load"); @@ -129,13 +124,11 @@ push_load_image_func (GSTESlideshow *show) static void start_new_load (GSTESlideshow *show, - guint timeout) -{ + guint timeout) { gs_theme_engine_profile_msg ("Scheduling a new image load"); /* queue a new load */ - if (show->priv->update_image_id <= 0) - { + if (show->priv->update_image_id <= 0) { show->priv->update_image_id = g_timeout_add_full (G_PRIORITY_LOW, timeout, (GSourceFunc)push_load_image_func, show, NULL); @@ -144,8 +137,7 @@ start_new_load (GSTESlideshow *show, static void start_fade (GSTESlideshow *show, - GdkPixbuf *pixbuf) -{ + GdkPixbuf *pixbuf) { int pw; int ph; int x; @@ -159,8 +151,7 @@ start_fade (GSTESlideshow *show, window_width = show->priv->window_width; window_height = show->priv->window_height; - if (show->priv->pat2 != NULL) - { + if (show->priv->pat2 != NULL) { cairo_pattern_destroy (show->priv->pat2); } @@ -169,8 +160,7 @@ start_fade (GSTESlideshow *show, x = (window_width - pw) / 2; y = (window_height - ph) / 2; - if (gdk_pixbuf_get_has_alpha (pixbuf) && show->priv->background_color) - { + if (gdk_pixbuf_get_has_alpha (pixbuf) && show->priv->background_color) { GdkPixbuf *colored; guint32 color; @@ -212,12 +202,10 @@ start_fade (GSTESlideshow *show, } static void -finish_fade (GSTESlideshow *show) -{ +finish_fade (GSTESlideshow *show) { gs_theme_engine_profile_start ("start"); - if (show->priv->pat1 != NULL) - { + if (show->priv->pat1 != NULL) { cairo_pattern_destroy (show->priv->pat1); } @@ -230,8 +218,7 @@ finish_fade (GSTESlideshow *show) } static void -update_display (GSTESlideshow *show) -{ +update_display (GSTESlideshow *show) { int window_width; int window_height; cairo_t *cr; @@ -244,19 +231,15 @@ update_display (GSTESlideshow *show) &window_width, &window_height); - if (show->priv->pat2 != NULL) - { + if (show->priv->pat2 != NULL) { /* fade out areas not covered by the new image */ /* top */ cairo_rectangle (cr, 0, 0, window_width, show->priv->pat2top); - if (show->priv->background_color) - { + if (show->priv->background_color) { cairo_set_source_rgba (cr, show->priv->background_color->red / 65535.0, show->priv->background_color->green / 65535.0, show->priv->background_color->blue / 65535.0, show->priv->alpha2); - } - else - { + } else { cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, show->priv->alpha2); } cairo_fill (cr); @@ -264,28 +247,22 @@ update_display (GSTESlideshow *show) cairo_rectangle (cr, 0, show->priv->pat2top, show->priv->pat2left, show->priv->pat2bottom - show->priv->pat2top); - if (show->priv->background_color) - { + if (show->priv->background_color) { cairo_set_source_rgba (cr, show->priv->background_color->red / 65535.0, show->priv->background_color->green / 65535.0, show->priv->background_color->blue / 65535.0, show->priv->alpha2); - } - else - { + } else { cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, show->priv->alpha2); } cairo_fill (cr); /* bottom */ cairo_rectangle (cr, 0, show->priv->pat2bottom, window_width, window_height - show->priv->pat2bottom); - if (show->priv->background_color) - { + if (show->priv->background_color) { cairo_set_source_rgba (cr, show->priv->background_color->red / 65535.0, show->priv->background_color->green / 65535.0, show->priv->background_color->blue / 65535.0, show->priv->alpha2); - } - else - { + } else { cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, show->priv->alpha2); } cairo_fill (cr); @@ -294,14 +271,11 @@ update_display (GSTESlideshow *show) show->priv->pat2top, window_width - show->priv->pat2right, show->priv->pat2bottom - show->priv->pat2top); - if (show->priv->background_color) - { + if (show->priv->background_color) { cairo_set_source_rgba (cr, show->priv->background_color->red / 65535.0, show->priv->background_color->green / 65535.0, show->priv->background_color->blue / 65535.0, show->priv->alpha2); - } - else - { + } else { cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, show->priv->alpha2); } cairo_fill (cr); @@ -311,11 +285,8 @@ update_display (GSTESlideshow *show) cairo_paint_with_alpha (cr, show->priv->alpha2); gs_theme_engine_profile_end ("paint pattern to surface"); - } - else - { - if (show->priv->pat1 != NULL) - { + } else { + if (show->priv->pat1 != NULL) { cairo_set_source (cr, show->priv->pat1); cairo_paint (cr); } @@ -327,18 +298,15 @@ update_display (GSTESlideshow *show) } static gboolean -draw_iter (GSTESlideshow *show) -{ +draw_iter (GSTESlideshow *show) { double old_opacity; double new_opacity; - if (show->priv->pat2 != NULL) - { + if (show->priv->pat2 != NULL) { gdouble fps; gdouble elapsed; - if (show->priv->fade_disabled) - { + if (show->priv->fade_disabled) { show->priv->alpha2 = 1.0; update_display (show); finish_fade (show); @@ -374,15 +342,13 @@ draw_iter (GSTESlideshow *show) elapsed = g_timer_elapsed (show->priv->timer, NULL); fps = (gdouble)show->priv->fade_ticks / elapsed; - if (fps < MINIMUM_FPS) - { + if (fps < MINIMUM_FPS) { g_warning ("Getting less than %.2f frames per second, disabling fade", MINIMUM_FPS); show->priv->fade_ticks = N_FADE_TICKS - 1; show->priv->fade_disabled = TRUE; } - if (show->priv->fade_ticks >= N_FADE_TICKS) - { + if (show->priv->fade_ticks >= N_FADE_TICKS) { finish_fade (show); } } @@ -392,30 +358,23 @@ draw_iter (GSTESlideshow *show) static void process_new_pixbuf (GSTESlideshow *show, - GdkPixbuf *pixbuf) -{ + GdkPixbuf *pixbuf) { gs_theme_engine_profile_msg ("Processing a new image"); - if (pixbuf != NULL) - { + if (pixbuf != NULL) { start_fade (show, pixbuf); - } - else - { + } else { start_new_load (show, 10); } } static void -op_result_free (OpResult *result) -{ - if (result == NULL) - { +op_result_free (OpResult *result) { + if (result == NULL) { return; } - if (result->pixbuf != NULL) - { + if (result->pixbuf != NULL) { g_object_unref (result->pixbuf); } @@ -423,8 +382,7 @@ op_result_free (OpResult *result) } static gboolean -results_pull_func (GSTESlideshow *show) -{ +results_pull_func (GSTESlideshow *show) { OpResult *result; g_async_queue_lock (show->priv->results_q); @@ -432,8 +390,7 @@ results_pull_func (GSTESlideshow *show) result = g_async_queue_try_pop_unlocked (show->priv->results_q); g_assert (result); - while (result != NULL) - { + while (result != NULL) { process_new_pixbuf (show, result->pixbuf); op_result_free (result); @@ -451,8 +408,7 @@ static GdkPixbuf * scale_pixbuf (GdkPixbuf *pixbuf, int max_width, int max_height, - gboolean no_stretch_hint) -{ + gboolean no_stretch_hint) { int pw; int ph; float scale_factor_x = 1.0; @@ -464,8 +420,7 @@ scale_pixbuf (GdkPixbuf *pixbuf, /* If the image is less than 256 wide or high then it is probably a thumbnail and we should ignore it */ - if (pw < 256 || ph < 256) - { + if (pw < 256 || ph < 256) { return NULL; } @@ -473,18 +428,14 @@ scale_pixbuf (GdkPixbuf *pixbuf, scale_factor_x = (float) max_width / (float) pw; scale_factor_y = (float) max_height / (float) ph; - if (scale_factor_x > scale_factor_y) - { + if (scale_factor_x > scale_factor_y) { scale_factor = scale_factor_y; - } - else - { + } else { scale_factor = scale_factor_x; } /* always scale down, allow to disable scaling up */ - if (scale_factor < 1.0 || !no_stretch_hint) - { + if (scale_factor < 1.0 || !no_stretch_hint) { int scale_x; int scale_y; @@ -494,45 +445,36 @@ scale_pixbuf (GdkPixbuf *pixbuf, scale_x, scale_y, GDK_INTERP_BILINEAR); - } - else - { + } else { return g_object_ref (pixbuf); } } static void add_files_to_list (GSList **list, - const char *base) -{ + const char *base) { GDir *d; const char *d_name; d = g_dir_open (base, 0, NULL); - if (d == NULL) - { + if (d == NULL) { g_warning ("Could not open directory: %s", base); return; } - while ((d_name = g_dir_read_name (d)) != NULL) - { + while ((d_name = g_dir_read_name (d)) != NULL) { char *path; /* skip hidden files */ - if (d_name[0] == '.') - { + if (d_name[0] == '.') { continue; } path = g_build_filename (base, d_name, NULL); - if (g_file_test (path, G_FILE_TEST_IS_DIR)) - { + if (g_file_test (path, G_FILE_TEST_IS_DIR)) { add_files_to_list (list, path); g_free (path); - } - else - { + } else { *list = g_slist_prepend (*list, path); } } @@ -541,8 +483,7 @@ add_files_to_list (GSList **list, } static GSList * -build_filename_list_local_dir (const char *base) -{ +build_filename_list_local_dir (const char *base) { GSList *list = NULL; add_files_to_list (&list, base); @@ -552,8 +493,7 @@ build_filename_list_local_dir (const char *base) static int gste_strcmp_compare_func (gconstpointer string_a, - gconstpointer string_b) -{ + gconstpointer string_b) { return strcmp (string_a == NULL ? "" : string_a, string_b == NULL ? "" : string_b); } @@ -561,52 +501,40 @@ gste_strcmp_compare_func (gconstpointer string_a, static GdkPixbuf * get_pixbuf_from_local_dir (GSTESlideshow *show, - const char *location) -{ + const char *location) { GdkPixbuf *pixbuf, *transformed_pixbuf; char *filename; int i; GSList *l; /* rebuild the cache */ - if (show->priv->filename_list == NULL) - { + if (show->priv->filename_list == NULL) { show->priv->filename_list = build_filename_list_local_dir (location); } - if (show->priv->filename_list == NULL) - { + if (show->priv->filename_list == NULL) { return NULL; - } - else - { - if (show->priv->sort_images) - { + } else { + if (show->priv->sort_images) { show->priv->filename_list = g_slist_sort (show->priv->filename_list, gste_strcmp_compare_func); } } /* get a random filename if needed */ - if (! show->priv->sort_images) - { + if (!show->priv->sort_images) { i = g_random_int_range (0, g_slist_length (show->priv->filename_list)); l = g_slist_nth (show->priv->filename_list, i); - } - else - { + } else { l = show->priv->filename_list; } filename = l->data; pixbuf = gdk_pixbuf_new_from_file (filename, NULL); - if (pixbuf != NULL) - { + if (pixbuf != NULL) { transformed_pixbuf = gdk_pixbuf_apply_embedded_orientation (pixbuf); g_object_unref (pixbuf); - } - else - { + } else { transformed_pixbuf = NULL; } @@ -618,20 +546,17 @@ get_pixbuf_from_local_dir (GSTESlideshow *show, static GdkPixbuf * get_pixbuf_from_location (GSTESlideshow *show, - const char *location) -{ + const char *location) { GdkPixbuf *pixbuf = NULL; gboolean is_dir; - if (location == NULL) - { + if (location == NULL) { return NULL; } is_dir = g_file_test (location, G_FILE_TEST_IS_DIR); - if (is_dir) - { + if (is_dir) { pixbuf = get_pixbuf_from_local_dir (show, location); } @@ -642,20 +567,17 @@ static GdkPixbuf * get_pixbuf (GSTESlideshow *show, const char *location, int width, - int height) -{ + int height) { GdkPixbuf *pixbuf; GdkPixbuf *scaled = NULL; - if (location == NULL) - { + if (location == NULL) { return NULL; } pixbuf = get_pixbuf_from_location (show, location); - if (pixbuf != NULL) - { + if (pixbuf != NULL) { scaled = scale_pixbuf (pixbuf, width, height, show->priv->no_stretch_hint); g_object_unref (pixbuf); } @@ -665,8 +587,7 @@ get_pixbuf (GSTESlideshow *show, static void op_load_image (GSTESlideshow *show, - const char *location) -{ + const char *location) { OpResult *op_result; int window_width; int window_height; @@ -684,8 +605,7 @@ op_load_image (GSTESlideshow *show, g_async_queue_lock (show->priv->results_q); g_async_queue_push_unlocked (show->priv->results_q, op_result); - if (show->priv->results_pull_id == 0) - { + if (show->priv->results_pull_id == 0) { show->priv->results_pull_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE, (GSourceFunc)results_pull_func, show, NULL); @@ -695,18 +615,15 @@ op_load_image (GSTESlideshow *show, } static gpointer -load_threadfunc (GAsyncQueue *op_q) -{ +load_threadfunc (GAsyncQueue *op_q) { Op *op; op = g_async_queue_pop (op_q); - while (op) - { + while (op) { op_load_image (op->slideshow, op->location); - if (op->slideshow != NULL) - { + if (op->slideshow != NULL) { g_object_unref (op->slideshow); } g_free (op->location); @@ -720,8 +637,7 @@ load_threadfunc (GAsyncQueue *op_q) void gste_slideshow_set_images_location (GSTESlideshow *show, - const char *location) -{ + const char *location) { g_return_if_fail (GSTE_IS_SLIDESHOW (show)); g_free (show->priv->images_location); @@ -731,8 +647,7 @@ gste_slideshow_set_images_location (GSTESlideshow *show, void gste_slideshow_set_sort_images (GSTESlideshow *show, - gboolean sort_images) -{ + gboolean sort_images) { g_return_if_fail (GSTE_IS_SLIDESHOW (show)); show->priv->sort_images = sort_images; @@ -740,8 +655,7 @@ gste_slideshow_set_sort_images (GSTESlideshow *show, void gste_slideshow_set_no_stretch_hint (GSTESlideshow *show, - gboolean no_stretch_hint) -{ + gboolean no_stretch_hint) { g_return_if_fail (GSTE_IS_SLIDESHOW (show)); show->priv->no_stretch_hint = no_stretch_hint; @@ -749,22 +663,18 @@ gste_slideshow_set_no_stretch_hint (GSTESlideshow *show, void gste_slideshow_set_background_color (GSTESlideshow *show, - const char *background_color) -{ + const char *background_color) { g_return_if_fail (GSTE_IS_SLIDESHOW (show)); - if (show->priv->background_color != NULL) - { + if (show->priv->background_color != NULL) { g_slice_free (PangoColor, show->priv->background_color); show->priv->background_color = NULL; } - if (background_color != NULL) - { + if (background_color != NULL) { show->priv->background_color = g_slice_new (PangoColor); - if (pango_color_parse (show->priv->background_color, background_color) == FALSE) - { + if (pango_color_parse (show->priv->background_color, background_color) == FALSE) { g_slice_free (PangoColor, show->priv->background_color); show->priv->background_color = NULL; } @@ -775,14 +685,12 @@ static void gste_slideshow_set_property (GObject *object, guint prop_id, const GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GSTESlideshow *self; self = GSTE_SLIDESHOW (object); - switch (prop_id) - { + switch (prop_id) { case PROP_IMAGES_LOCATION: gste_slideshow_set_images_location (self, g_value_get_string (value)); break; @@ -805,14 +713,12 @@ static void gste_slideshow_get_property (GObject *object, guint prop_id, GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GSTESlideshow *self; self = GSTE_SLIDESHOW (object); - switch (prop_id) - { + switch (prop_id) { case PROP_IMAGES_LOCATION: g_value_set_string (value, self->priv->images_location); break; @@ -837,13 +743,11 @@ gste_slideshow_get_property (GObject *object, } static void -gste_slideshow_real_show (GtkWidget *widget) -{ +gste_slideshow_real_show (GtkWidget *widget) { GSTESlideshow *show = GSTE_SLIDESHOW (widget); int delay; - if (GTK_WIDGET_CLASS (parent_class)->show) - { + if (GTK_WIDGET_CLASS (parent_class)->show) { GTK_WIDGET_CLASS (parent_class)->show (widget); } @@ -852,8 +756,7 @@ gste_slideshow_real_show (GtkWidget *widget) delay = 25; show->priv->timeout_id = g_timeout_add (delay, (GSourceFunc)draw_iter, show); - if (show->priv->timer != NULL) - { + if (show->priv->timer != NULL) { g_timer_destroy (show->priv->timer); } show->priv->timer = g_timer_new (); @@ -861,8 +764,7 @@ gste_slideshow_real_show (GtkWidget *widget) static gboolean gste_slideshow_real_draw (GtkWidget *widget, - cairo_t *cr) -{ + cairo_t *cr) { GSTESlideshow *show = GSTE_SLIDESHOW (widget); if (GTK_WIDGET_CLASS (parent_class)->draw) { @@ -880,8 +782,7 @@ gste_slideshow_real_draw (GtkWidget *widget, static gboolean gste_slideshow_real_configure (GtkWidget *widget, - GdkEventConfigure *event) -{ + GdkEventConfigure *event) { GSTESlideshow *show = GSTE_SLIDESHOW (widget); gboolean handled = FALSE; cairo_t *cr; @@ -895,8 +796,7 @@ gste_slideshow_real_configure (GtkWidget *widget, show->priv->window_width, show->priv->window_height); - if (show->priv->surf != NULL) - { + if (show->priv->surf != NULL) { cairo_surface_destroy (show->priv->surf); } @@ -912,8 +812,7 @@ gste_slideshow_real_configure (GtkWidget *widget, /* schedule a redraw */ gtk_widget_queue_draw (widget); - if (GTK_WIDGET_CLASS (parent_class)->configure_event) - { + if (GTK_WIDGET_CLASS (parent_class)->configure_event) { handled = GTK_WIDGET_CLASS (parent_class)->configure_event (widget, event); } @@ -921,8 +820,7 @@ gste_slideshow_real_configure (GtkWidget *widget, } static void -gste_slideshow_class_init (GSTESlideshowClass *klass) -{ +gste_slideshow_class_init (GSTESlideshowClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); @@ -967,15 +865,13 @@ gste_slideshow_class_init (GSTESlideshowClass *klass) } static void -set_visual (GtkWidget *widget) -{ +set_visual (GtkWidget *widget) { GdkScreen *screen; GdkVisual *visual; screen = gtk_widget_get_screen (widget); visual = gdk_screen_get_rgba_visual (screen); - if (visual == NULL) - { + if (visual == NULL) { visual = gdk_screen_get_system_visual (screen); } @@ -983,8 +879,7 @@ set_visual (GtkWidget *widget) } static void -gste_slideshow_init (GSTESlideshow *show) -{ +gste_slideshow_init (GSTESlideshow *show) { show->priv = gste_slideshow_get_instance_private (show); show->priv->images_location = g_strdup (DEFAULT_IMAGES_LOCATION); @@ -998,8 +893,7 @@ gste_slideshow_init (GSTESlideshow *show) } static void -gste_slideshow_finalize (GObject *object) -{ +gste_slideshow_finalize (GObject *object) { GSTESlideshow *show; gpointer result; @@ -1010,29 +904,24 @@ gste_slideshow_finalize (GObject *object) g_return_if_fail (show->priv != NULL); - if (show->priv->surf) - { + if (show->priv->surf) { cairo_surface_destroy (show->priv->surf); } - if (show->priv->timeout_id > 0) - { + if (show->priv->timeout_id > 0) { g_source_remove (show->priv->timeout_id); show->priv->timeout_id = 0; } - if (show->priv->results_pull_id > 0) - { + if (show->priv->results_pull_id > 0) { g_source_remove (show->priv->results_pull_id); show->priv->results_pull_id = 0; } - if (show->priv->results_q != NULL) - { + if (show->priv->results_q != NULL) { result = g_async_queue_try_pop (show->priv->results_q); - while (result) - { + while (result) { result = g_async_queue_try_pop (show->priv->results_q); } g_async_queue_unref (show->priv->results_q); @@ -1041,14 +930,12 @@ gste_slideshow_finalize (GObject *object) g_free (show->priv->images_location); show->priv->images_location = NULL; - if (show->priv->background_color) - { + if (show->priv->background_color) { g_slice_free (PangoColor, show->priv->background_color); show->priv->background_color = NULL; } - if (show->priv->timer != NULL) - { + if (show->priv->timer != NULL) { g_timer_destroy (show->priv->timer); } diff --git a/savers/popsquares.c b/savers/popsquares.c index b62c6e5bb02f54f17931b25b7596ececb40a3eba..7ab1826ac3cb6b20d92ba4f87b358f572569848f 100644 --- a/savers/popsquares.c +++ b/savers/popsquares.c @@ -19,22 +19,22 @@ * */ -#include "config.h" +#include <config.h> #include <stdlib.h> #include <string.h> + #include <gtk/gtk.h> #include <libxfce4util/libxfce4util.h> -#include "gs-theme-window.h" -#include "gs-theme-engine.h" -#include "gste-popsquares.h" +#include "savers/gs-theme-window.h" +#include "savers/gs-theme-engine.h" +#include "savers/gste-popsquares.h" int main (int argc, - char **argv) -{ + char **argv) { GSThemeEngine *engine; GtkWidget *window; GError *error; @@ -45,8 +45,7 @@ main (int argc, error = NULL; - if (!gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) - { + if (!gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) { g_printerr (_("%s. See --help for usage information.\n"), error->message); g_error_free (error); diff --git a/savers/slideshow.c b/savers/slideshow.c index 93da2f02a4b88bea48c0c0dae3eab1a3d963cffa..9f88d4a153f736c3269e50230c0b72e43ba5ec3e 100644 --- a/savers/slideshow.c +++ b/savers/slideshow.c @@ -19,7 +19,7 @@ * */ -#include "config.h" +#include <config.h> #include <stdio.h> #include <stdlib.h> @@ -27,19 +27,18 @@ #include <unistd.h> #include <glib.h> -#include <libxfce4util/libxfce4util.h> #include <glib/gstdio.h> #include <gtk/gtk.h> -#include "gs-theme-window.h" -#include "gs-theme-engine.h" -#include "gste-slideshow.h" +#include <libxfce4util/libxfce4util.h> -#include "xdg-user-dir-lookup.h" +#include "savers/gs-theme-window.h" +#include "savers/gs-theme-engine.h" +#include "savers/gste-slideshow.h" +#include "savers/xdg-user-dir-lookup.h" int -main (int argc, char **argv) -{ +main (int argc, char **argv) { GSThemeEngine *engine; GtkWidget *window; GError *error; @@ -48,8 +47,7 @@ main (int argc, char **argv) char *background_color = NULL; gboolean sort_images = FALSE; gboolean no_stretch = FALSE; - GOptionEntry entries [] = - { + GOptionEntry entries[] = { { "location", 0, 0, G_OPTION_ARG_STRING, &location, N_("Location to get images from"), N_("PATH") @@ -80,8 +78,7 @@ main (int argc, char **argv) entries, NULL, &error); - if (! ret) - { + if (!ret) { g_message ("%s", error->message); g_error_free (error); exit (1); @@ -97,35 +94,29 @@ main (int argc, char **argv) engine = g_object_new (GSTE_TYPE_SLIDESHOW, NULL); - if (location == NULL) - { + if (location == NULL) { location = xdg_user_dir_lookup ("PICTURES"); if (location == NULL || strcmp (location, "/tmp") == 0 || - strcmp (location, g_get_home_dir ()) == 0) - { + strcmp (location, g_get_home_dir ()) == 0) { free (location); location = g_build_filename (g_get_home_dir (), "Pictures", NULL); } } - if (location != NULL) - { + if (location != NULL) { g_object_set (engine, "images-location", location, NULL); } - if (sort_images) - { + if (sort_images) { g_object_set (engine, "sort-images", sort_images, NULL); } - if (background_color != NULL) - { + if (background_color != NULL) { g_object_set (engine, "background-color", background_color, NULL); } - if (no_stretch) - { + if (no_stretch) { g_object_set (engine, "no-stretch", no_stretch, NULL); } diff --git a/savers/xdg-user-dir-lookup.c b/savers/xdg-user-dir-lookup.c index 6ac1d5c8e094ed1d9f8203903bb24601018b5780..1e5ce5934755a8e43068e9d100c6be91f5326bab 100644 --- a/savers/xdg-user-dir-lookup.c +++ b/savers/xdg-user-dir-lookup.c @@ -29,7 +29,7 @@ #include <stdlib.h> #include <string.h> -#include "xdg-user-dir-lookup.h" +#include "savers/xdg-user-dir-lookup.h" char * xdg_user_dir_lookup (const char *type) @@ -48,14 +48,11 @@ xdg_user_dir_lookup (const char *type) return strdup ("/tmp"); config_home = getenv ("XDG_CONFIG_HOME"); - if (config_home == NULL || config_home[0] == 0) - { + if (config_home == NULL || config_home[0] == 0) { config_file = malloc (strlen (home_dir) + strlen ("/.config/user-dirs.dirs") + 1); strcpy (config_file, home_dir); strcat (config_file, "/.config/user-dirs.dirs"); - } - else - { + } else { config_file = malloc (strlen (config_home) + strlen ("/user-dirs.dirs") + 1); strcpy (config_file, config_home); strcat (config_file, "/user-dirs.dirs"); @@ -103,22 +100,18 @@ xdg_user_dir_lookup (const char *type) p++; relative = 0; - if (strncmp (p, "$HOME/", 6) == 0) - { + if (strncmp (p, "$HOME/", 6) == 0) { p += 6; relative = 1; - } - else if (*p != '/') + } else if (*p != '/') { continue; + } - if (relative) - { + if (relative) { user_dir = malloc (strlen (home_dir) + 1 + strlen (p) + 1); strcpy (user_dir, home_dir); strcat (user_dir, "/"); - } - else - { + } else { user_dir = malloc (strlen (p) + 1); *user_dir = 0; } @@ -139,15 +132,14 @@ xdg_user_dir_lookup (const char *type) error: /* Special case desktop for historical compatibility */ - if (strcmp (type, "DESKTOP") == 0) - { + if (strcmp (type, "DESKTOP") == 0) { user_dir = malloc (strlen (home_dir) + strlen ("/Desktop") + 1); strcpy (user_dir, home_dir); strcat (user_dir, "/Desktop"); return user_dir; - } - else + } else { return strdup (home_dir); + } } #ifdef STANDALONE @@ -155,8 +147,7 @@ error: int main (int argc, char *argv[]) { - if (argc != 2) - { + if (argc != 2) { fprintf (stderr, "Usage %s <dir-type>\n", argv[0]); exit (1); } diff --git a/src/copy-theme-dialog.c b/src/copy-theme-dialog.c index 376383786179748e8f455007dc96cff6fc668e0f..1c6092ea41285473d360c2d5a9cf8bd849dfea35 100644 --- a/src/copy-theme-dialog.c +++ b/src/copy-theme-dialog.c @@ -19,19 +19,20 @@ * 02110-1301, USA. **/ -#include "config.h" +#include <config.h> #include <limits.h> #include <string.h> #include <sys/stat.h> +#include <gio/gio.h> #include <glib.h> #include <glib/gstdio.h> -#include <libxfce4util/libxfce4util.h> #include <gtk/gtk.h> -#include <gio/gio.h> -#include "copy-theme-dialog.h" +#include <libxfce4util/libxfce4util.h> + +#include "src/copy-theme-dialog.h" static void copy_theme_dialog_class_init (CopyThemeDialogClass *klass); @@ -65,15 +66,13 @@ create_titled_label (GtkGrid *grid, static GObjectClass *parent_class = NULL; -enum -{ +enum { CANCELLED = 0, COMPLETE, SIGNAL_COUNT }; -struct _CopyThemeDialogPrivate -{ +struct _CopyThemeDialogPrivate { GtkWidget *progress; GtkWidget *status; GtkWidget *current; @@ -91,14 +90,11 @@ struct _CopyThemeDialogPrivate guint signals[SIGNAL_COUNT] = {0, 0}; GType -copy_theme_dialog_get_type (void) -{ +copy_theme_dialog_get_type (void) { static GType copy_theme_dialog_type = 0; - if (!copy_theme_dialog_type) - { - static GTypeInfo copy_theme_dialog_info = - { + if (!copy_theme_dialog_type) { + static GTypeInfo copy_theme_dialog_info = { sizeof (CopyThemeDialogClass), NULL, /* GBaseInitFunc */ NULL, /* GBaseFinalizeFunc */ @@ -121,8 +117,7 @@ copy_theme_dialog_get_type (void) } static void -copy_theme_dialog_class_init (CopyThemeDialogClass *klass) -{ +copy_theme_dialog_class_init (CopyThemeDialogClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* GObject 2.58 */ @@ -154,8 +149,7 @@ copy_theme_dialog_class_init (CopyThemeDialogClass *klass) } GtkWidget* -copy_theme_dialog_new (GList *files) -{ +copy_theme_dialog_new (GList *files) { GtkWidget *dialog; CopyThemeDialogPrivate *priv; @@ -175,15 +169,13 @@ copy_theme_dialog_new (GList *files) } static gboolean -copy_finished (CopyThemeDialog *dialog) -{ +copy_finished (CopyThemeDialog *dialog) { return (g_cancellable_is_cancelled (dialog->priv->cancellable) || dialog->priv->file == NULL); } static void -copy_theme_dialog_init (CopyThemeDialog *dlg) -{ +copy_theme_dialog_init (CopyThemeDialog *dlg) { GtkWidget *vbox; GtkWidget *hbox; GtkWidget *progress_vbox; @@ -271,8 +263,7 @@ copy_theme_dialog_init (CopyThemeDialog *dlg) static void add_file_to_dialog (gpointer data, - gpointer user_data) -{ + gpointer user_data) { CopyThemeDialogPrivate *priv; GFile *file; gchar *basename = NULL, *raw_basename; @@ -281,8 +272,7 @@ add_file_to_dialog (gpointer data, file = G_FILE (data); raw_basename = g_file_get_basename (file); - if (g_str_has_suffix (raw_basename, ".desktop")) - { + if (g_str_has_suffix (raw_basename, ".desktop")) { /* FIXME: validate key file? */ basename = g_strndup (raw_basename, /* 8 = strlen (".desktop") */ @@ -290,16 +280,12 @@ add_file_to_dialog (gpointer data, } g_free (raw_basename); - if (basename) - { + if (basename) { g_object_ref (file); priv->all_files = g_slist_append (priv->all_files, file); priv->all_basenames = g_slist_append (priv->all_basenames, basename); priv->total_files++; - } - - else - { + } else { GtkWidget *dialog; gchar *uri; @@ -324,24 +310,18 @@ add_file_to_dialog (gpointer data, static void single_copy_complete (GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ + gpointer user_data) { GError *error = NULL; gboolean should_continue = FALSE; CopyThemeDialog *dialog = COPY_THEME_DIALOG (user_data); - if (g_file_copy_finish (G_FILE (source_object), res, &error)) - { + if (g_file_copy_finish (G_FILE (source_object), res, &error)) { should_continue = TRUE; - } - - else - { + } else { /* If the file already exists, generate a new random name * and try again. **/ - if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) - { + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) { GFile *file, *destination; gchar *basename, *full_basename; g_error_free (error); @@ -364,21 +344,14 @@ single_copy_complete (GObject *source_object, dialog->priv->cancellable, NULL, NULL, single_copy_complete, dialog); - } - - else - { + } else { if (g_error_matches (error, G_IO_ERROR, - G_IO_ERROR_CANCELLED)) - { + G_IO_ERROR_CANCELLED)) { /* User has cancelled the theme copy */ g_signal_emit (G_OBJECT (dialog), signals[CANCELLED], 0, NULL); - } - - else - { + } else { /* Some other error occurred, ignore and * try to copy remaining files **/ @@ -392,8 +365,7 @@ single_copy_complete (GObject *source_object, /* Update informational widgets and, if needed, signal * copy completion. **/ - if (should_continue) - { + if (should_continue) { dialog->priv->index++; dialog->priv->file = dialog->priv->file->next; dialog->priv->basename = dialog->priv->basename->next; @@ -408,13 +380,11 @@ single_copy_complete (GObject *source_object, * appended to the filename. **/ static void -copy_theme_dialog_copy_next (CopyThemeDialog *dialog) -{ +copy_theme_dialog_copy_next (CopyThemeDialog *dialog) { GFile *file, *destination; gchar *basename, *full_basename; - if (copy_finished (dialog)) - { + if (copy_finished (dialog)) { g_signal_emit (G_OBJECT (dialog), signals[COMPLETE], 0, NULL); return; @@ -436,13 +406,10 @@ copy_theme_dialog_copy_next (CopyThemeDialog *dialog) } static gboolean -timeout_display_dialog (gpointer data) -{ - if (IS_COPY_THEME_DIALOG (data)) - { +timeout_display_dialog (gpointer data) { + if (IS_COPY_THEME_DIALOG (data)) { CopyThemeDialog *dialog = COPY_THEME_DIALOG (data); - if (!copy_finished (dialog)) - { + if (!copy_finished (dialog)) { gtk_widget_show (GTK_WIDGET (dialog)); g_signal_connect (dialog, "response", @@ -454,8 +421,7 @@ timeout_display_dialog (gpointer data) } void -copy_theme_dialog_begin (CopyThemeDialog *dialog) -{ +copy_theme_dialog_begin (CopyThemeDialog *dialog) { gtk_widget_hide (GTK_WIDGET (dialog)); /* If the copy operation takes more than half a second to @@ -467,14 +433,12 @@ copy_theme_dialog_begin (CopyThemeDialog *dialog) } static void -copy_theme_dialog_cancel (CopyThemeDialog *dialog) -{ +copy_theme_dialog_cancel (CopyThemeDialog *dialog) { g_cancellable_cancel (dialog->priv->cancellable); } static void -copy_theme_dialog_finalize (GObject *obj) -{ +copy_theme_dialog_finalize (GObject *obj) { CopyThemeDialog *dlg = COPY_THEME_DIALOG (obj); g_object_unref (dlg->priv->theme_dir); @@ -489,8 +453,7 @@ copy_theme_dialog_finalize (GObject *obj) } static void -copy_theme_dialog_update_num_files (CopyThemeDialog *dlg) -{ +copy_theme_dialog_update_num_files (CopyThemeDialog *dlg) { gchar *str = g_strdup_printf (_("Copying file: %u of %u"), dlg->priv->index, dlg->priv->total_files); gtk_progress_bar_set_text (GTK_PROGRESS_BAR (dlg->priv->progress), str); @@ -498,8 +461,7 @@ copy_theme_dialog_update_num_files (CopyThemeDialog *dlg) } static void -copy_theme_dialog_response (GtkDialog *dialog, gint response_id) -{ +copy_theme_dialog_response (GtkDialog *dialog, gint response_id) { g_cancellable_cancel (COPY_THEME_DIALOG (dialog)->priv->cancellable); } @@ -510,8 +472,7 @@ copy_theme_dialog_response (GtkDialog *dialog, gint response_id) * @label: The label. **/ static void -eel_gtk_label_make_bold (GtkLabel *label) -{ +eel_gtk_label_make_bold (GtkLabel *label) { PangoFontDescription *font_desc; PangoAttrList *attrlist; PangoAttribute *attr; @@ -539,8 +500,7 @@ static void create_titled_label (GtkGrid *grid, int row, GtkWidget **title_widget, - GtkWidget **label_text_widget) -{ + GtkWidget **label_text_widget) { *title_widget = gtk_label_new (""); eel_gtk_label_make_bold (GTK_LABEL (*title_widget)); gtk_widget_set_halign (*title_widget, GTK_ALIGN_END); diff --git a/src/gs-auth-bsdauth.c b/src/gs-auth-bsdauth.c index 3085c931d5ea8edd0503efff178a47d2a1a8153c..b723ade8ce33a25bb560ebf601c08955f23a7016 100644 --- a/src/gs-auth-bsdauth.c +++ b/src/gs-auth-bsdauth.c @@ -19,31 +19,31 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "config.h" +#include <config.h> -#include <stdio.h> +#include <pwd.h> #include <signal.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/types.h> + #ifdef HAVE_UNISTD_H #include <unistd.h> #endif -#include <pwd.h> -#include <sys/types.h> #include <login_cap.h> #include <bsd_auth.h> -#include "gs-auth.h" -#include "subprocs.h" +#include "src/gs-auth.h" +#include "src/subprocs.h" static gboolean verbose_enabled = FALSE; GQuark -gs_auth_error_quark (void) -{ +gs_auth_error_quark (void) { static GQuark quark = 0; - if (! quark) { + if (!quark) { quark = g_quark_from_static_string ("gs_auth_error"); } @@ -51,14 +51,12 @@ gs_auth_error_quark (void) } void -gs_auth_set_verbose (gboolean enabled) -{ +gs_auth_set_verbose (gboolean enabled) { verbose_enabled = enabled; } gboolean -gs_auth_get_verbose (void) -{ +gs_auth_get_verbose (void) { return verbose_enabled; } @@ -67,8 +65,7 @@ gs_auth_verify_user (const char *username, const char *display, GSAuthMessageFunc func, gpointer data, - GError **error) -{ + GError **error) { int res; char *password; @@ -91,13 +88,11 @@ gs_auth_verify_user (const char *username, } gboolean -gs_auth_init (void) -{ +gs_auth_init (void) { return TRUE; } gboolean -gs_auth_priv_init (void) -{ +gs_auth_priv_init (void) { return TRUE; } diff --git a/src/gs-auth-helper.c b/src/gs-auth-helper.c index c69972627b45470007fbb161a17a29072e62a0e0..f021679caf795af938cb2e0dbf3e73b15ed366d8 100644 --- a/src/gs-auth-helper.c +++ b/src/gs-auth-helper.c @@ -30,34 +30,32 @@ * -- Olaf Kirch <okir@suse.de>, 16-Dec-2003 */ -#include "config.h" +#include <config.h> -#include <stdlib.h> #ifdef HAVE_UNISTD_H # include <unistd.h> #endif +#include <errno.h> +#include <pwd.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <sys/types.h> -#include <pwd.h> -#include <errno.h> #include <sys/wait.h> #include <glib.h> #include <glib/gstdio.h> -#include "gs-auth.h" -#include "subprocs.h" +#include "src/gs-auth.h" +#include "src/subprocs.h" static gboolean verbose_enabled = FALSE; GQuark -gs_auth_error_quark (void) -{ +gs_auth_error_quark (void) { static GQuark quark = 0; - if (! quark) - { + if (!quark) { quark = g_quark_from_static_string ("gs_auth_error"); } @@ -65,82 +63,69 @@ gs_auth_error_quark (void) } void -gs_auth_set_verbose (gboolean enabled) -{ +gs_auth_set_verbose (gboolean enabled) { verbose_enabled = enabled; } gboolean -gs_auth_get_verbose (void) -{ +gs_auth_get_verbose (void) { return verbose_enabled; } static gboolean ext_run (const char *user, const char *typed_passwd, - gboolean verbose) -{ + gboolean verbose) { int pfd[2], status; pid_t pid; - if (pipe (pfd) < 0) - { + if (pipe (pfd) < 0) { return 0; } - if (verbose) - { + if (verbose) { g_message ("ext_run (%s, %s)", PASSWD_HELPER_PROGRAM, user); } block_sigchld (); - if ((pid = fork ()) < 0) - { - close (pfd [0]); - close (pfd [1]); + if ((pid = fork ()) < 0) { + close (pfd[0]); + close (pfd[1]); return FALSE; } - if (pid == 0) - { - close (pfd [1]); - if (pfd [0] != 0) - { - dup2 (pfd [0], 0); + if (pid == 0) { + close (pfd[1]); + if (pfd[0] != 0) { + dup2 (pfd[0], 0); } /* Helper is invoked as helper service-name [user] */ execlp (PASSWD_HELPER_PROGRAM, PASSWD_HELPER_PROGRAM, "xfce4-screensaver", user, NULL); - if (verbose) - { + if (verbose) { g_message ("%s: %s", PASSWD_HELPER_PROGRAM, g_strerror (errno)); } exit (1); } - close (pfd [0]); + close (pfd[0]); /* Write out password to helper process */ - if (!typed_passwd) - { + if (!typed_passwd) { typed_passwd = ""; } - write (pfd [1], typed_passwd, strlen (typed_passwd)); - close (pfd [1]); + write (pfd[1], typed_passwd, strlen (typed_passwd)); + close (pfd[1]); - while (waitpid (pid, &status, 0) < 0) - { - if (errno == EINTR) - { + while (waitpid (pid, &status, 0) < 0) { + if (errno == EINTR) { continue; } - if (verbose) - { + if (verbose) { g_message ("ext_run: waitpid failed: %s\n", g_strerror (errno)); } @@ -151,8 +136,7 @@ ext_run (const char *user, unblock_sigchld (); - if (! WIFEXITED (status) || WEXITSTATUS (status) != 0) - { + if (!WIFEXITED (status) || WEXITSTATUS (status) != 0) { return FALSE; } @@ -164,24 +148,21 @@ gs_auth_verify_user (const char *username, const char *display, GSAuthMessageFunc func, gpointer data, - GError **error) -{ + GError **error) { gboolean res = FALSE; char *password; password = NULL; /* ask for the password for user */ - if (func != NULL) - { + if (func != NULL) { func (GS_AUTH_MESSAGE_PROMPT_ECHO_OFF, "Password: ", &password, data); } - if (password == NULL) - { + if (password == NULL) { return FALSE; } @@ -191,17 +172,14 @@ gs_auth_verify_user (const char *username, } gboolean -gs_auth_init (void) -{ +gs_auth_init (void) { return TRUE; } gboolean -gs_auth_priv_init (void) -{ +gs_auth_priv_init (void) { /* Make sure the passwd helper exists */ - if (g_access (PASSWD_HELPER_PROGRAM, X_OK) < 0) - { + if (g_access (PASSWD_HELPER_PROGRAM, X_OK) < 0) { g_warning ("%s does not exist. " "password authentication via " "external helper will not work.", diff --git a/src/gs-auth-pam.c b/src/gs-auth-pam.c index 56ca51e95ababdbe9bd8bedd6ef5517d828e6e86..46edf8d28af06f5657ce79bdd415eb054ad216e4 100644 --- a/src/gs-auth-pam.c +++ b/src/gs-auth-pam.c @@ -23,31 +23,32 @@ * */ -#include "config.h" - -#include <stdlib.h> -#ifdef HAVE_UNISTD_H -# include <unistd.h> -#endif +#include <config.h> +#include <errno.h> #include <fcntl.h> +#include <grp.h> +#include <pwd.h> +#include <signal.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <sys/types.h> -#include <pwd.h> -#include <grp.h> + #include <security/pam_appl.h> -#include <signal.h> -#include <errno.h> #include <glib.h> #include <glib/gstdio.h> -#include <libxfce4util/libxfce4util.h> #include <gtk/gtk.h> -#include "gs-auth.h" +#include <libxfce4util/libxfce4util.h> -#include "subprocs.h" +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif + +#include "src/gs-auth.h" +#include "src/subprocs.h" /* Some time between Red Hat 4.2 and 7.0, the words were transposed in the various PAM_x_CRED macro names. Yay! @@ -81,8 +82,7 @@ static gboolean verbose_enabled = FALSE; static pam_handle_t *pam_handle = NULL; static gboolean did_we_ask_for_password = FALSE; -struct pam_closure -{ +struct pam_closure { const char *username; GSAuthMessageFunc cb_func; gpointer cb_data; @@ -90,8 +90,7 @@ struct pam_closure int result; }; -typedef struct -{ +typedef struct { struct pam_closure *closure; GSAuthMessageStyle style; const char *msg; @@ -103,11 +102,9 @@ static GCond message_handled_condition; static GMutex message_handler_mutex; GQuark -gs_auth_error_quark (void) -{ +gs_auth_error_quark (void) { static GQuark quark = 0; - if (! quark) - { + if (!quark) { quark = g_quark_from_static_string ("gs_auth_error"); } @@ -115,24 +112,20 @@ gs_auth_error_quark (void) } void -gs_auth_set_verbose (gboolean enabled) -{ +gs_auth_set_verbose (gboolean enabled) { verbose_enabled = enabled; } gboolean -gs_auth_get_verbose (void) -{ +gs_auth_get_verbose (void) { return verbose_enabled; } static GSAuthMessageStyle -pam_style_to_gs_style (int pam_style) -{ +pam_style_to_gs_style (int pam_style) { GSAuthMessageStyle style; - switch (pam_style) - { + switch (pam_style) { case PAM_PROMPT_ECHO_ON: style = GS_AUTH_MESSAGE_PROMPT_ECHO_ON; break; @@ -157,48 +150,42 @@ static gboolean auth_message_handler (GSAuthMessageStyle style, const char *msg, char **response, - gpointer data) -{ + gpointer data) { gboolean ret; ret = TRUE; *response = NULL; - switch (style) - { - case GS_AUTH_MESSAGE_PROMPT_ECHO_ON: - break; - case GS_AUTH_MESSAGE_PROMPT_ECHO_OFF: - if (msg != NULL && g_str_has_prefix (msg, _("Password:"))) - { - did_we_ask_for_password = TRUE; - } - break; - case GS_AUTH_MESSAGE_ERROR_MSG: - break; - case GS_AUTH_MESSAGE_TEXT_INFO: - break; - default: - g_assert_not_reached (); + switch (style) { + case GS_AUTH_MESSAGE_PROMPT_ECHO_ON: + break; + case GS_AUTH_MESSAGE_PROMPT_ECHO_OFF: + if (msg != NULL && g_str_has_prefix (msg, _("Password:"))) { + did_we_ask_for_password = TRUE; + } + break; + case GS_AUTH_MESSAGE_ERROR_MSG: + break; + case GS_AUTH_MESSAGE_TEXT_INFO: + break; + default: + g_assert_not_reached (); } return ret; } static gboolean -gs_auth_queued_message_handler (GsAuthMessageHandlerData *data) -{ +gs_auth_queued_message_handler (GsAuthMessageHandlerData *data) { gboolean res; - if (gs_auth_get_verbose ()) - { + if (gs_auth_get_verbose ()) { g_message ("Waiting for lock"); } g_mutex_lock (&message_handler_mutex); - if (gs_auth_get_verbose ()) - { + if (gs_auth_get_verbose ()) { g_message ("Waiting for response"); } @@ -212,8 +199,7 @@ gs_auth_queued_message_handler (GsAuthMessageHandlerData *data) g_cond_signal (&message_handled_condition); g_mutex_unlock (&message_handler_mutex); - if (gs_auth_get_verbose ()) - { + if (gs_auth_get_verbose ()) { g_message ("Got response"); } @@ -224,8 +210,7 @@ static gboolean gs_auth_run_message_handler (struct pam_closure *c, GSAuthMessageStyle style, const char *msg, - char **resp) -{ + char **resp) { GsAuthMessageHandlerData data; data.closure = c; @@ -240,8 +225,7 @@ gs_auth_run_message_handler (struct pam_closure *c, */ g_idle_add ((GSourceFunc) gs_auth_queued_message_handler, &data); - if (gs_auth_get_verbose ()) - { + if (gs_auth_get_verbose ()) { g_message ("Waiting for respose to message style %d: '%s'", style, msg); } @@ -251,8 +235,7 @@ gs_auth_run_message_handler (struct pam_closure *c, &message_handler_mutex); g_mutex_unlock (&message_handler_mutex); - if (gs_auth_get_verbose ()) - { + if (gs_auth_get_verbose ()) { g_message ("Got respose to message style %d: interrupt:%d", style, data.should_interrupt_stack); } @@ -263,8 +246,7 @@ static int pam_conversation (int nmsgs, const struct pam_message **msg, struct pam_response **resp, - void *closure) -{ + void *closure) { int replies = 0; struct pam_response *reply = NULL; struct pam_closure *c = (struct pam_closure *) closure; @@ -273,22 +255,20 @@ pam_conversation (int nmsgs, reply = (struct pam_response *) calloc (nmsgs, sizeof (*reply)); - if (reply == NULL) - { + if (reply == NULL) { return PAM_CONV_ERR; } res = TRUE; ret = PAM_SUCCESS; - for (replies = 0; replies < nmsgs && ret == PAM_SUCCESS; replies++) - { + for (replies = 0; replies < nmsgs && ret == PAM_SUCCESS; replies++) { GSAuthMessageStyle style; char *utf8_msg; - style = pam_style_to_gs_style (msg [replies]->msg_style); + style = pam_style_to_gs_style (msg[replies]->msg_style); - utf8_msg = g_locale_to_utf8 (msg [replies]->msg, + utf8_msg = g_locale_to_utf8 (msg[replies]->msg, -1, NULL, NULL, @@ -296,16 +276,14 @@ pam_conversation (int nmsgs, /* if we couldn't convert text from locale then * assume utf-8 and hope for the best */ - if (utf8_msg == NULL) - { + if (utf8_msg == NULL) { char *p; char *q; - utf8_msg = g_strdup (msg [replies]->msg); + utf8_msg = g_strdup (msg[replies]->msg); p = utf8_msg; - while (*p != '\0' && !g_utf8_validate ((const char *)p, -1, (const char **)&q)) - { + while (*p != '\0' && !g_utf8_validate ((const char *)p, -1, (const char **)&q)) { *q = '?'; p = q + 1; } @@ -314,13 +292,11 @@ pam_conversation (int nmsgs, /* handle message locally first */ auth_message_handler (style, utf8_msg, - &reply [replies].resp, + &reply[replies].resp, NULL); - if (c->cb_func != NULL) - { - if (gs_auth_get_verbose ()) - { + if (c->cb_func != NULL) { + if (gs_auth_get_verbose ()) { g_message ("Handling message style %d: '%s'", style, utf8_msg); } @@ -329,24 +305,19 @@ pam_conversation (int nmsgs, res = gs_auth_run_message_handler (c, style, utf8_msg, - &reply [replies].resp); + &reply[replies].resp); - if (gs_auth_get_verbose ()) - { + if (gs_auth_get_verbose ()) { g_message ("Msg handler returned %d", res); } /* If the handler returns FALSE - interrupt the PAM stack */ - if (res) - { - reply [replies].resp_retcode = PAM_SUCCESS; - } - else - { + if (res) { + reply[replies].resp_retcode = PAM_SUCCESS; + } else { int i; - for (i = 0; i <= replies; i++) - { - free (reply [i].resp); + for (i = 0; i <= replies; i++) { + free (reply[i].resp); } free (reply); reply = NULL; @@ -363,18 +334,14 @@ pam_conversation (int nmsgs, } static gboolean -close_pam_handle (int status) -{ - - if (pam_handle != NULL) - { +close_pam_handle (int status) { + if (pam_handle != NULL) { int status2; status2 = pam_end (pam_handle, status); pam_handle = NULL; - if (gs_auth_get_verbose ()) - { + if (gs_auth_get_verbose ()) { g_message (" pam_end (...) ==> %d (%s)", status2, (status2 == PAM_SUCCESS ? "Success" : "Failure")); @@ -388,15 +355,13 @@ static gboolean create_pam_handle (const char *username, const char *display, struct pam_conv *conv, - int *status_code) -{ + int *status_code) { int status; const char *service = PAM_SERVICE_NAME; char *disp; gboolean ret; - if (pam_handle != NULL) - { + if (pam_handle != NULL) { g_warning ("create_pam_handle: Stale pam handle around, cleaning up"); close_pam_handle (PAM_SUCCESS); } @@ -408,15 +373,13 @@ create_pam_handle (const char *username, ret = TRUE; /* Initialize a PAM session for the user */ - if ((status = pam_start (service, username, conv, &pam_handle)) != PAM_SUCCESS) - { + if ((status = pam_start (service, username, conv, &pam_handle)) != PAM_SUCCESS) { pam_handle = NULL; g_warning (_("Unable to establish service %s: %s\n"), service, PAM_STRERROR (NULL, status)); - if (status_code != NULL) - { + if (status_code != NULL) { *status_code = status; } @@ -424,8 +387,7 @@ create_pam_handle (const char *username, goto out; } - if (gs_auth_get_verbose ()) - { + if (gs_auth_get_verbose ()) { g_message ("pam_start (\"%s\", \"%s\", ...) ==> %d (%s)", service, username, @@ -434,17 +396,14 @@ create_pam_handle (const char *username, } disp = g_strdup (display); - if (disp == NULL) - { + if (disp == NULL) { disp = g_strdup (":0.0"); } - if ((status = pam_set_item (pam_handle, PAM_TTY, disp)) != PAM_SUCCESS) - { + if ((status = pam_set_item (pam_handle, PAM_TTY, disp)) != PAM_SUCCESS) { g_warning (_("Can't set PAM_TTY=%s"), display); - if (status_code != NULL) - { + if (status_code != NULL) { *status_code = status; } @@ -457,8 +416,7 @@ create_pam_handle (const char *username, g_mutex_init (&message_handler_mutex); out: - if (status_code != NULL) - { + if (status_code != NULL) { *status_code = status; } @@ -469,18 +427,13 @@ out: static void set_pam_error (GError **error, - int status) -{ - if (status == PAM_AUTH_ERR || status == PAM_USER_UNKNOWN) - { + int status) { + if (status == PAM_AUTH_ERR || status == PAM_USER_UNKNOWN) { char *msg; - if (did_we_ask_for_password) - { + if (did_we_ask_for_password) { msg = g_strdup (_("Incorrect password.")); - } - else - { + } else { msg = g_strdup (_("Authentication failed.")); } @@ -490,29 +443,23 @@ set_pam_error (GError **error, "%s", msg); g_free (msg); - } - else if (status == PAM_PERM_DENIED) - { + } else if (status == PAM_PERM_DENIED) { g_set_error (error, GS_AUTH_ERROR, GS_AUTH_ERROR_AUTH_DENIED, "%s", _("Not permitted to gain access at this time.")); - } - else if (status == PAM_ACCT_EXPIRED) - { + } else if (status == PAM_ACCT_EXPIRED) { g_set_error (error, GS_AUTH_ERROR, GS_AUTH_ERROR_AUTH_DENIED, "%s", _("No longer permitted to access the system.")); } - } static int -gs_auth_thread_func (int auth_operation_fd) -{ +gs_auth_thread_func (int auth_operation_fd) { static const int flags = 0; int status; int status2; @@ -530,20 +477,17 @@ gs_auth_thread_func (int auth_operation_fd) sigtimedwait (&set, NULL, &timeout); unblock_sigchld (); - if (gs_auth_get_verbose ()) - { + if (gs_auth_get_verbose ()) { g_message (" pam_authenticate (...) ==> %d (%s)", status, PAM_STRERROR (pam_handle, status)); } - if (status != PAM_SUCCESS) - { + if (status != PAM_SUCCESS) { goto done; } - if ((status = pam_get_item (pam_handle, PAM_USER, &p)) != PAM_SUCCESS) - { + if ((status = pam_get_item (pam_handle, PAM_USER, &p)) != PAM_SUCCESS) { /* is not really an auth problem, but it will pretty much look as such, it shouldn't really happen */ @@ -556,16 +500,14 @@ gs_auth_thread_func (int auth_operation_fd) */ status2 = pam_acct_mgmt (pam_handle, 0); - if (gs_auth_get_verbose ()) - { + if (gs_auth_get_verbose ()) { g_message ("pam_acct_mgmt (...) ==> %d (%s)\n", status2, PAM_STRERROR (pam_handle, status2)); } /* FIXME: should we handle these? */ - switch (status2) - { + switch (status2) { case PAM_SUCCESS: break; case PAM_NEW_AUTHTOK_REQD: @@ -590,8 +532,7 @@ gs_auth_thread_func (int auth_operation_fd) credentials when using PAM_REINITIALIZE_CRED. */ status2 = pam_setcred (pam_handle, PAM_REINITIALIZE_CRED); - if (gs_auth_get_verbose ()) - { + if (gs_auth_get_verbose ()) { g_message (" pam_setcred (...) ==> %d (%s)", status2, PAM_STRERROR (pam_handle, status2)); @@ -609,8 +550,7 @@ done: static gboolean gs_auth_loop_quit (GIOChannel *source, GIOCondition condition, - gboolean *thread_done) -{ + gboolean *thread_done) { *thread_done = TRUE; gtk_main_quit (); return FALSE; @@ -618,8 +558,7 @@ gs_auth_loop_quit (GIOChannel *source, static gboolean gs_auth_pam_verify_user (pam_handle_t *handle, - int *status) -{ + int *status) { GThread *auth_thread; GIOChannel *channel; guint watch_id; @@ -635,20 +574,17 @@ gs_auth_pam_verify_user (pam_handle_t *handle, * the event loop to be notified when our helper thread * is ready to be reaped. */ - if (pipe (auth_operation_fds) < 0) - { + if (pipe (auth_operation_fds) < 0) { goto out; } - if (fcntl (auth_operation_fds[0], F_SETFD, FD_CLOEXEC) < 0) - { + if (fcntl (auth_operation_fds[0], F_SETFD, FD_CLOEXEC) < 0) { close (auth_operation_fds[0]); close (auth_operation_fds[1]); goto out; } - if (fcntl (auth_operation_fds[1], F_SETFD, FD_CLOEXEC) < 0) - { + if (fcntl (auth_operation_fds[1], F_SETFD, FD_CLOEXEC) < 0) { close (auth_operation_fds[0]); close (auth_operation_fds[1]); goto out; @@ -668,8 +604,7 @@ gs_auth_pam_verify_user (pam_handle_t *handle, (GThreadFunc) gs_auth_thread_func, GINT_TO_POINTER (auth_operation_fds[1])); - if (auth_thread == NULL) - { + if (auth_thread == NULL) { goto out; } @@ -684,27 +619,23 @@ gs_auth_pam_verify_user (pam_handle_t *handle, * so we can just exit. An alternative option would be to switch to * using pthreads directly and calling pthread_cancel. */ - if (!thread_done) - { + if (!thread_done) { raise (SIGTERM); } auth_status = GPOINTER_TO_INT (g_thread_join (auth_thread)); out: - if (watch_id != 0) - { - //g_source_remove (watch_id); + if (watch_id != 0) { + // g_source_remove (watch_id); watch_id = 0; } - if (channel != NULL) - { + if (channel != NULL) { g_io_channel_unref (channel); } - if (status) - { + if (status) { *status = auth_status; } @@ -716,16 +647,14 @@ gs_auth_verify_user (const char *username, const char *display, GSAuthMessageFunc func, gpointer data, - GError **error) -{ + GError **error) { int status = -1; struct pam_conv conv; struct pam_closure c; struct passwd *pwent; pwent = getpwnam (username); - if (pwent == NULL) - { + if (pwent == NULL) { return FALSE; } @@ -738,8 +667,7 @@ gs_auth_verify_user (const char *username, /* Initialize PAM. */ create_pam_handle (username, display, &conv, &status); - if (status != PAM_SUCCESS) - { + if (status != PAM_SUCCESS) { goto done; } @@ -748,14 +676,12 @@ gs_auth_verify_user (const char *username, PAM_NO_DELAY(pam_handle); did_we_ask_for_password = FALSE; - if (! gs_auth_pam_verify_user (pam_handle, &status)) - { + if (!gs_auth_pam_verify_user (pam_handle, &status)) { goto done; } done: - if (status != PAM_SUCCESS) - { + if (status != PAM_SUCCESS) { set_pam_error (error, status); } @@ -765,14 +691,12 @@ done: } gboolean -gs_auth_init (void) -{ +gs_auth_init (void) { return TRUE; } gboolean -gs_auth_priv_init (void) -{ +gs_auth_priv_init (void) { /* We have nothing to do at init-time. However, we might as well do some error checking. If "/etc/pam.d" exists and is a directory, but "/etc/pam.d/xlock" @@ -781,48 +705,38 @@ gs_auth_priv_init (void) This is a priv-init instead of a non-priv init in case the directory is unreadable or something (don't know if that actually happens.) */ - const char dir [] = "/etc/pam.d"; - const char file [] = "/etc/pam.d/" PAM_SERVICE_NAME; - const char file2 [] = "/etc/pam.conf"; + const char dir[] = "/etc/pam.d"; + const char file[] = "/etc/pam.d/" PAM_SERVICE_NAME; + const char file2[] = "/etc/pam.conf"; struct stat st; - if (g_stat (dir, &st) == 0 && st.st_mode & S_IFDIR) - { - if (g_stat (file, &st) != 0) - { + if (g_stat (dir, &st) == 0 && st.st_mode & S_IFDIR) { + if (g_stat (file, &st) != 0) { g_warning ("%s does not exist.\n" "Authentication via PAM is unlikely to work.", file); } - } - else if (g_stat (file2, &st) == 0) - { + } else if (g_stat (file2, &st) == 0) { FILE *f = g_fopen (file2, "r"); - if (f) - { + if (f) { gboolean ok = FALSE; char buf[255]; - while (fgets (buf, sizeof(buf), f)) - { - if (strstr (buf, PAM_SERVICE_NAME)) - { + while (fgets (buf, sizeof(buf), f)) { + if (strstr (buf, PAM_SERVICE_NAME)) { ok = TRUE; break; } } fclose (f); - if (!ok) - { + if (!ok) { g_warning ("%s does not list the `%s' service.\n" "Authentication via PAM is unlikely to work.", file2, PAM_SERVICE_NAME); } } /* else warn about file2 existing but being unreadable? */ - } - else - { + } else { g_warning ("Neither %s nor %s exist.\n" "Authentication via PAM is unlikely to work.", file2, file); diff --git a/src/gs-auth-pwent.c b/src/gs-auth-pwent.c index 64d616bd1a660a5364ee2e66c1faf389ebf33841..62bd9382fbe73b9ee5a30115eaedf0b0cbb9c025 100644 --- a/src/gs-auth-pwent.c +++ b/src/gs-auth-pwent.c @@ -20,9 +20,19 @@ * */ -#include "config.h" +#include <config.h> +#include <grp.h> +#include <pwd.h> +#include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <sys/types.h> + +#include <glib.h> + +#include <libxfce4util/libxfce4util.h> + #ifdef HAVE_UNISTD_H # include <unistd.h> #endif @@ -31,12 +41,6 @@ # include <crypt.h> #endif -#include <stdio.h> -#include <string.h> -#include <sys/types.h> -#include <pwd.h> -#include <grp.h> - #ifdef __bsdi__ # include <sys/param.h> # if _BSDI_VERSION >= 199608 @@ -44,9 +48,6 @@ # endif #endif /* __bsdi__ */ -#include <glib.h> -#include <libxfce4util/libxfce4util.h> - #if defined(HAVE_SHADOW_PASSWD) /* passwds live in /etc/shadow */ # include <shadow.h> @@ -86,18 +87,16 @@ #endif -#include "gs-auth.h" +#include "src/gs-auth.h" static gboolean verbose_enabled = FALSE; static char *encrypted_user_passwd = NULL; GQuark -gs_auth_error_quark (void) -{ +gs_auth_error_quark (void) { static GQuark quark = 0; - if (! quark) - { + if (!quark) { quark = g_quark_from_static_string ("gs_auth_error"); } @@ -105,48 +104,40 @@ gs_auth_error_quark (void) } void -gs_auth_set_verbose (gboolean enabled) -{ +gs_auth_set_verbose (gboolean enabled) { verbose_enabled = enabled; } gboolean -gs_auth_get_verbose (void) -{ +gs_auth_get_verbose (void) { return verbose_enabled; } static gboolean -passwd_known (const char *pw) -{ +passwd_known (const char *pw) { return (pw && pw[0] != '*' && /* This would be sensible... */ strlen (pw) > 4); /* ...but this is what Solaris does. */ } static char * -get_encrypted_passwd (const char *user) -{ +get_encrypted_passwd (const char *user) { char *result = NULL; #ifdef PWTYPE - if (user && *user && !result) - { + if (user && *user && !result) { /* First check the shadow passwords. */ PWTYPE p = GETPW ((char *) user); - if (p && passwd_known (p->PWPSLOT)) - { + if (p && passwd_known (p->PWPSLOT)) { result = g_strdup (p->PWPSLOT); } } #endif /* PWTYPE */ - if (user && *user && !result) - { + if (user && *user && !result) { /* Check non-shadow passwords too. */ struct passwd *p = getpwnam (user); - if (p && passwd_known (p->pw_passwd)) - { + if (p && passwd_known (p->pw_passwd)) { result = g_strdup (p->pw_passwd); } } @@ -162,11 +153,9 @@ get_encrypted_passwd (const char *user) it might have trailing junk. So, if there is a comma in the string, and that comma is beyond position 13, terminate the string before the comma. */ - if (result && strlen (result) > 13) - { + if (result && strlen (result) > 13) { char *s = strchr (result + 13, ','); - if (s) - { + if (s) { *s = 0; } } @@ -176,8 +165,7 @@ get_encrypted_passwd (const char *user) or bsd_auth(3). If we're using PAM, it's not unheard of that normal pwent passwords would be unavailable. */ - if (!result) - { + if (!result) { g_warning ("Couldn't get password of \"%s\"", (user ? user : "(null)")); } @@ -194,47 +182,37 @@ get_encrypted_passwd (const char *user) */ gboolean -gs_auth_priv_init (void) -{ +gs_auth_priv_init (void) { const char *u; u = g_get_user_name (); encrypted_user_passwd = get_encrypted_passwd (u); - if (encrypted_user_passwd != NULL) - { + if (encrypted_user_passwd != NULL) { return TRUE; - } - else - { + } else { return FALSE; } } gboolean -gs_auth_init (void) -{ - if (encrypted_user_passwd != NULL) - { +gs_auth_init (void) { + if (encrypted_user_passwd != NULL) { return TRUE; - } - else - { + } else { return FALSE; } } static gboolean passwds_match (const char *cleartext, - const char *ciphertext) -{ + const char *ciphertext) { char *s = NULL; /* note that on some systems, crypt() may return null */ s = (char *) crypt (cleartext, ciphertext); - if (s && !strcmp (s, ciphertext)) - { + if (s && !strcmp (s, ciphertext)) { return TRUE; } @@ -245,8 +223,7 @@ passwds_match (const char *cleartext, one works. */ s = (char *) bigcrypt (cleartext, ciphertext); - if (s && !strcmp (s, ciphertext)) - { + if (s && !strcmp (s, ciphertext)) { return TRUE; } @@ -260,32 +237,26 @@ gs_auth_verify_user (const char *username, const char *display, GSAuthMessageFunc func, gpointer data, - GError **error) -{ + GError **error) { char *password; password = NULL; /* ask for the password for user */ - if (func != NULL) - { + if (func != NULL) { func (GS_AUTH_MESSAGE_PROMPT_ECHO_OFF, "Password: ", &password, data); } - if (password == NULL) - { + if (password == NULL) { return FALSE; } - if (encrypted_user_passwd && passwds_match (password, encrypted_user_passwd)) - { + if (encrypted_user_passwd && passwds_match (password, encrypted_user_passwd)) { return TRUE; - } - else - { + } else { return FALSE; } } diff --git a/src/gs-debug.c b/src/gs-debug.c index a4a0f5afd4c3e58eb46248dc36340f016d8f17e8..2e9b23172e36faf3a3cac828ac1f3a55845be0bf 100644 --- a/src/gs-debug.c +++ b/src/gs-debug.c @@ -20,19 +20,19 @@ * */ -#include "config.h" +#include <config.h> +#include <signal.h> +#include <stdarg.h> #include <stdio.h> #include <string.h> -#include <stdarg.h> -#include <signal.h> #include <time.h> #include <unistd.h> #include <glib.h> #include <glib/gstdio.h> -#include "gs-debug.h" +#include "src/gs-debug.h" static gboolean debugging = FALSE; static FILE *debug_out = NULL; @@ -45,10 +45,9 @@ void gs_debug_real (const char *func, const char *file, const int line, - const char *format, ...) -{ + const char *format, ...) { va_list args; - char buffer [1025]; + char buffer[1025]; char *str_time; time_t the_time; @@ -57,7 +56,7 @@ gs_debug_real (const char *func, va_start (args, format); - g_vsnprintf (buffer, 1024, format, args); + g_vsnprintf (buffer, sizeof(buffer), format, args); va_end (args); @@ -76,32 +75,27 @@ gs_debug_real (const char *func, } gboolean -gs_debug_enabled (void) -{ +gs_debug_enabled (void) { return debugging; } void gs_debug_init (gboolean debug, - gboolean to_file) -{ + gboolean to_file) { /* return if already initialized */ - if (debugging == TRUE) - { + if (debugging == TRUE) { return; } debugging = debug; - if (debug && to_file) - { - const char path [50] = "xfce4_screensaver_debug_XXXXXX"; + if (debug && to_file) { + const char path[50] = "xfce4_screensaver_debug_XXXXXX"; int fd; fd = g_file_open_tmp (path, NULL, NULL); - if (fd >= 0) - { + if (fd >= 0) { debug_out = fdopen (fd, "a"); } } @@ -110,17 +104,15 @@ gs_debug_init (gboolean debug, } void -gs_debug_shutdown (void) -{ - if (! debugging) +gs_debug_shutdown (void) { + if (!debugging) return; gs_debug ("Shutting down debugging"); debugging = FALSE; - if (debug_out != NULL) - { + if (debug_out != NULL) { fclose (debug_out); debug_out = NULL; } @@ -130,29 +122,22 @@ void _gs_profile_log (const char *func, const char *note, const char *format, - ...) -{ + ...) { va_list args; char *str; char *formatted; - if (format == NULL) - { + if (format == NULL) { formatted = g_strdup (""); - } - else - { + } else { va_start (args, format); formatted = g_strdup_vprintf (format, args); va_end (args); } - if (func != NULL) - { + if (func != NULL) { str = g_strdup_printf ("MARK: %s %s: %s %s", g_get_prgname(), func, note ? note : "", formatted); - } - else - { + } else { str = g_strdup_printf ("MARK: %s: %s %s", g_get_prgname(), note ? note : "", formatted); } diff --git a/src/gs-fade.c b/src/gs-fade.c index a91a22d210b09ea30f99b0cf8752fceeb935807a..e62762bc953a91414f027ba3619a8755f01d6c5b 100644 --- a/src/gs-fade.c +++ b/src/gs-fade.c @@ -22,32 +22,28 @@ * */ -#include "config.h" +#include <config.h> -#include <stdlib.h> -#include <stdio.h> -#include <time.h> #include <errno.h> - +#include <stdio.h> +#include <stdlib.h> #include <string.h> #include <sys/time.h> #include <sys/types.h> -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif /* HAVE_UNISTD_H */ +#include <time.h> #include <gdk/gdkx.h> #include <gtk/gtk.h> -#include "gs-fade.h" -#include "gs-debug.h" - +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif /* HAVE_UNISTD_H */ -#include "xfce-rr.h" +#include "src/gs-fade.h" +#include "src/gs-debug.h" +#include "src/xfce-rr.h" /* XFree86 4.x+ Gamma fading */ - - #ifdef HAVE_XF86VMODE_GAMMA #include <X11/extensions/xf86vmode.h> @@ -60,16 +56,14 @@ static void gs_fade_class_init (GSFadeClass *klass); static void gs_fade_init (GSFade *fade); static void gs_fade_finalize (GObject *object); -struct GSGammaInfo -{ +struct GSGammaInfo { int size; unsigned short *r; unsigned short *g; unsigned short *b; }; -struct GSFadeScreenPrivate -{ +struct GSFadeScreenPrivate { int fade_type; int num_ramps; /* one per crtc in randr mode */ @@ -86,8 +80,7 @@ struct GSFadeScreenPrivate void (*fade_finish) (GSFade *fade); }; -struct GSFadePrivate -{ +struct GSFadePrivate { guint enabled : 1; guint active : 1; @@ -103,21 +96,19 @@ struct GSFadePrivate struct GSFadeScreenPrivate screen_priv; }; -enum -{ +enum { FADED, LAST_SIGNAL }; -enum -{ +enum { FADE_TYPE_NONE, FADE_TYPE_GAMMA_NUMBER, FADE_TYPE_GAMMA_RAMP, FADE_TYPE_XRANDR, }; -static guint signals [LAST_SIGNAL] = { 0, }; +static guint signals[LAST_SIGNAL] = { 0, }; G_DEFINE_TYPE_WITH_PRIVATE (GSFade, gs_fade, G_TYPE_OBJECT) @@ -135,8 +126,7 @@ static gboolean error_handler_hit = FALSE; static int ignore_all_errors_ehandler (Display *dpy, - XErrorEvent *error) -{ + XErrorEvent *error) { error_handler_hit = TRUE; return 0; @@ -145,8 +135,7 @@ ignore_all_errors_ehandler (Display *dpy, static Bool safe_XF86VidModeQueryVersion (Display *dpy, int *majP, - int *minP) -{ + int *minP) { Bool result; XErrorHandler old_handler; @@ -168,8 +157,7 @@ safe_XF86VidModeQueryVersion (Display *dpy, static gboolean xf86_whack_gamma (int screen, struct GSFadeScreenPrivate *screen_priv, - float ratio) -{ + float ratio) { Bool status; struct GSGammaInfo *gamma_info; @@ -178,17 +166,14 @@ xf86_whack_gamma (int screen, if (!gamma_info) return FALSE; - if (ratio < 0) - { + if (ratio < 0) { ratio = 0; } - if (ratio > 1) - { + if (ratio > 1) { ratio = 1; } - if (gamma_info->size == 0) - { + if (gamma_info->size == 0) { /* we only have a gamma number, not a ramp. */ XF86VidModeGamma g2; @@ -197,24 +182,18 @@ xf86_whack_gamma (int screen, g2.green = screen_priv->vmg.green * ratio; g2.blue = screen_priv->vmg.blue * ratio; - if (g2.red < XF86_MIN_GAMMA) - { + if (g2.red < XF86_MIN_GAMMA) { g2.red = XF86_MIN_GAMMA; } - if (g2.green < XF86_MIN_GAMMA) - { + if (g2.green < XF86_MIN_GAMMA) { g2.green = XF86_MIN_GAMMA; } - if (g2.blue < XF86_MIN_GAMMA) - { + if (g2.blue < XF86_MIN_GAMMA) { g2.blue = XF86_MIN_GAMMA; } status = XF86VidModeSetGamma (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), screen, &g2); - } - else - { - + } else { # ifdef HAVE_XF86VMODE_GAMMA_RAMP unsigned short *r, *g, *b; int i; @@ -223,14 +202,14 @@ xf86_whack_gamma (int screen, g = g_new0 (unsigned short, gamma_info->size); b = g_new0 (unsigned short, gamma_info->size); - for (i = 0; i < gamma_info->size; i++) - { + for (i = 0; i < gamma_info->size; i++) { r[i] = gamma_info->r[i] * ratio; g[i] = gamma_info->g[i] * ratio; b[i] = gamma_info->b[i] * ratio; } - status = XF86VidModeSetGammaRamp (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), screen, gamma_info->size, r, g, b); + status = XF86VidModeSetGammaRamp (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), + screen, gamma_info->size, r, g, b); g_free (r); g_free (g); @@ -258,8 +237,7 @@ xf86_whack_gamma (int screen, gboolean -gs_fade_get_enabled (GSFade *fade) -{ +gs_fade_get_enabled (GSFade *fade) { g_return_val_if_fail (GS_IS_FADE (fade), FALSE); return fade->priv->enabled; @@ -267,20 +245,17 @@ gs_fade_get_enabled (GSFade *fade) void gs_fade_set_enabled (GSFade *fade, - gboolean enabled) -{ + gboolean enabled) { g_return_if_fail (GS_IS_FADE (fade)); - if (fade->priv->enabled != enabled) - { + if (fade->priv->enabled != enabled) { fade->priv->enabled = enabled; } } #ifdef HAVE_XF86VMODE_GAMMA static gboolean -gamma_fade_setup (GSFade *fade) -{ +gamma_fade_setup (GSFade *fade) { gboolean res; struct GSFadeScreenPrivate *screen_priv; @@ -290,8 +265,7 @@ gamma_fade_setup (GSFade *fade) return TRUE; # ifndef HAVE_XF86VMODE_GAMMA_RAMP - if (FADE_TYPE_GAMMA_RAMP == screen_priv->fade_type) - { + if (FADE_TYPE_GAMMA_RAMP == screen_priv->fade_type) { /* server is newer than client! */ screen_priv->fade_type = FADE_TYPE_GAMMA_NUMBER; } @@ -302,16 +276,13 @@ gamma_fade_setup (GSFade *fade) screen_priv->info = g_new0(struct GSGammaInfo, 1); screen_priv->num_ramps = 1; - if (FADE_TYPE_GAMMA_RAMP == screen_priv->fade_type) - { + if (FADE_TYPE_GAMMA_RAMP == screen_priv->fade_type) { /* have ramps */ - res = XF86VidModeGetGammaRampSize (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_SCREEN_XNUMBER (gdk_screen_get_default ()), &screen_priv->info->size); - if (!res || screen_priv->info->size <= 0) - { + if (!res || screen_priv->info->size <= 0) { screen_priv->fade_type = FADE_TYPE_GAMMA_NUMBER; goto test_number; } @@ -320,8 +291,7 @@ gamma_fade_setup (GSFade *fade) screen_priv->info->g = g_new0 (unsigned short, screen_priv->info->size); screen_priv->info->b = g_new0 (unsigned short, screen_priv->info->size); - if (! (screen_priv->info->r && screen_priv->info->g && screen_priv->info->b)) - { + if (!(screen_priv->info->r && screen_priv->info->g && screen_priv->info->b)) { screen_priv->fade_type = FADE_TYPE_GAMMA_NUMBER; goto test_number; } @@ -332,8 +302,7 @@ gamma_fade_setup (GSFade *fade) screen_priv->info->r, screen_priv->info->g, screen_priv->info->b); - if (! res) - { + if (!res) { screen_priv->fade_type = FADE_TYPE_GAMMA_NUMBER; goto test_number; } @@ -342,15 +311,13 @@ gamma_fade_setup (GSFade *fade) # endif /* HAVE_XF86VMODE_GAMMA_RAMP */ test_number: - if (FADE_TYPE_GAMMA_NUMBER == screen_priv->fade_type) - { + if (FADE_TYPE_GAMMA_NUMBER == screen_priv->fade_type) { /* only have gamma parameter, not ramps. */ res = XF86VidModeGetGamma (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_SCREEN_XNUMBER (gdk_screen_get_default ()), &screen_priv->vmg); - if (! res) - { + if (!res) { screen_priv->fade_type = FADE_TYPE_NONE; goto test_none; } @@ -361,8 +328,7 @@ test_number: } test_none: - if (FADE_TYPE_NONE == screen_priv->fade_type) - { + if (FADE_TYPE_NONE == screen_priv->fade_type) { goto FAIL; } @@ -374,8 +340,7 @@ FAIL: #endif /* HAVE_XF86VMODE_GAMMA */ static void -screen_fade_finish (GSFade *fade) -{ +screen_fade_finish (GSFade *fade) { struct GSFadeScreenPrivate *screen_priv; int i; screen_priv = &fade->priv->screen_priv; @@ -383,8 +348,7 @@ screen_fade_finish (GSFade *fade) if (!screen_priv->info) return; - for (i = 0; i < screen_priv->num_ramps; i++) - { + for (i = 0; i < screen_priv->num_ramps; i++) { if (screen_priv->info[i].r) g_free (screen_priv->info[i].r); if (screen_priv->info[i].g) @@ -401,8 +365,7 @@ screen_fade_finish (GSFade *fade) #ifdef HAVE_XF86VMODE_GAMMA static gboolean gamma_fade_set_alpha_gamma (GSFade *fade, - gdouble alpha) -{ + gdouble alpha) { struct GSFadeScreenPrivate *screen_priv; int screen_idx = GDK_SCREEN_XNUMBER (gdk_screen_get_default ()); @@ -414,8 +377,7 @@ gamma_fade_set_alpha_gamma (GSFade *fade, #endif /* HAVE_XF86VMODE_GAMMA */ static void -check_gamma_extension (GSFade *fade) -{ +check_gamma_extension (GSFade *fade) { struct GSFadeScreenPrivate *screen_priv; #ifdef HAVE_XF86VMODE_GAMMA int event; @@ -429,11 +391,11 @@ check_gamma_extension (GSFade *fade) #ifdef HAVE_XF86VMODE_GAMMA res = XF86VidModeQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &event, &error); - if (! res) + if (!res) goto fade_none; res = safe_XF86VidModeQueryVersion (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &major, &minor); - if (! res) + if (!res) goto fade_none; if (major < XF86_VIDMODE_GAMMA_MIN_MAJOR || @@ -447,8 +409,7 @@ check_gamma_extension (GSFade *fade) if (major < XF86_VIDMODE_GAMMA_RAMP_MIN_MAJOR || (major == XF86_VIDMODE_GAMMA_RAMP_MIN_MAJOR && - minor < XF86_VIDMODE_GAMMA_RAMP_MIN_MINOR)) - { + minor < XF86_VIDMODE_GAMMA_RAMP_MIN_MINOR)) { screen_priv->fade_type = FADE_TYPE_GAMMA_NUMBER; return; } @@ -463,8 +424,7 @@ fade_none: /* Xrandr support */ -static gboolean xrandr_fade_setup (GSFade *fade) -{ +static gboolean xrandr_fade_setup (GSFade *fade) { struct GSFadeScreenPrivate *screen_priv; XfceRRCrtc *crtc; XfceRRCrtc **crtcs; @@ -481,33 +441,28 @@ static gboolean xrandr_fade_setup (GSFade *fade) xfce_rr_screen_refresh (screen_priv->rrscreen, NULL); crtcs = xfce_rr_screen_list_crtcs (screen_priv->rrscreen); - while (*crtcs) - { + while (*crtcs) { crtc_count++; crtcs++; - }; + } screen_priv->info = g_new0 (struct GSGammaInfo, crtc_count); screen_priv->num_ramps = crtc_count; crtc_count = 0; crtcs = xfce_rr_screen_list_crtcs (screen_priv->rrscreen); - while (*crtcs) - { + while (*crtcs) { crtc = *crtcs; info = &screen_priv->info[crtc_count]; /* if no mode ignore crtc */ - if (!xfce_rr_crtc_get_current_mode (crtc)) - { + if (!xfce_rr_crtc_get_current_mode (crtc)) { info->size = 0; info->r = NULL; info->g = NULL; info->b = NULL; - } - else - { + } else { res = xfce_rr_crtc_get_gamma (crtc, &info->size, &info->r, &info->g, &info->b); @@ -525,20 +480,17 @@ fail: static void xrandr_crtc_whack_gamma (XfceRRCrtc *crtc, struct GSGammaInfo *gamma_info, - float ratio) -{ + float ratio) { unsigned short *r, *g, *b; int i; if (gamma_info->size == 0) return; - if (ratio < 0) - { + if (ratio < 0) { ratio = 0; } - if (ratio > 1) - { + if (ratio > 1) { ratio = 1; } @@ -546,8 +498,7 @@ static void xrandr_crtc_whack_gamma (XfceRRCrtc *crtc, g = g_new0 (unsigned short, gamma_info->size); b = g_new0 (unsigned short, gamma_info->size); - for (i = 0; i < gamma_info->size; i++) - { + for (i = 0; i < gamma_info->size; i++) { r[i] = gamma_info->r[i] * ratio; g[i] = gamma_info->g[i] * ratio; b[i] = gamma_info->b[i] * ratio; @@ -561,8 +512,7 @@ static void xrandr_crtc_whack_gamma (XfceRRCrtc *crtc, } static gboolean xrandr_fade_set_alpha_gamma (GSFade *fade, - gdouble alpha) -{ + gdouble alpha) { struct GSFadeScreenPrivate *screen_priv; struct GSGammaInfo *info; XfceRRCrtc **crtcs; @@ -576,8 +526,7 @@ static gboolean xrandr_fade_set_alpha_gamma (GSFade *fade, crtcs = xfce_rr_screen_list_crtcs (screen_priv->rrscreen); i = 0; - while (*crtcs) - { + while (*crtcs) { info = &screen_priv->info[i]; xrandr_crtc_whack_gamma (*crtcs, info, alpha); i++; @@ -587,8 +536,7 @@ static gboolean xrandr_fade_set_alpha_gamma (GSFade *fade, } static void -check_randr_extension (GSFade *fade) -{ +check_randr_extension (GSFade *fade) { GdkDisplay *display = gdk_display_get_default (); GdkScreen *screen = gdk_display_get_default_screen (display); struct GSFadeScreenPrivate *screen_priv; @@ -597,8 +545,7 @@ check_randr_extension (GSFade *fade) screen_priv->rrscreen = xfce_rr_screen_new (screen, NULL); - if (!screen_priv->rrscreen) - { + if (!screen_priv->rrscreen) { screen_priv->fade_type = FADE_TYPE_NONE; return; } @@ -611,12 +558,10 @@ check_randr_extension (GSFade *fade) static gboolean gs_fade_set_alpha (GSFade *fade, - gdouble alpha) -{ + gdouble alpha) { gboolean ret = FALSE; - switch (fade->priv->screen_priv.fade_type) - { + switch (fade->priv->screen_priv.fade_type) { case FADE_TYPE_GAMMA_RAMP: case FADE_TYPE_GAMMA_NUMBER: case FADE_TYPE_XRANDR: @@ -635,12 +580,10 @@ gs_fade_set_alpha (GSFade *fade, } static gboolean -gs_fade_out_iter (GSFade *fade) -{ +gs_fade_out_iter (GSFade *fade) { gboolean ret; - if (fade->priv->current_alpha < 0.01) - { + if (fade->priv->current_alpha < 0.01) { return FALSE; } @@ -652,10 +595,8 @@ gs_fade_out_iter (GSFade *fade) } static gboolean -gs_fade_stop (GSFade *fade) -{ - if (fade->priv->timer_id > 0) - { +gs_fade_stop (GSFade *fade) { + if (fade->priv->timer_id > 0) { g_source_remove (fade->priv->timer_id); fade->priv->timer_id = 0; } @@ -667,32 +608,28 @@ gs_fade_stop (GSFade *fade) } void -gs_fade_finish (GSFade *fade) -{ +gs_fade_finish (GSFade *fade) { g_return_if_fail (GS_IS_FADE (fade)); - if (! fade->priv->active) - { + if (!fade->priv->active) { return; } gs_fade_stop (fade); - g_signal_emit (fade, signals [FADED], 0); + g_signal_emit (fade, signals[FADED], 0); fade->priv->active = FALSE; } static gboolean -fade_out_timer (GSFade *fade) -{ +fade_out_timer (GSFade *fade) { gboolean res; res = gs_fade_out_iter (fade); /* if failed then fade is complete */ - if (! res) - { + if (!res) { gs_fade_finish (fade); return FALSE; } @@ -701,8 +638,7 @@ fade_out_timer (GSFade *fade) } gboolean -gs_fade_get_active (GSFade *fade) -{ +gs_fade_get_active (GSFade *fade) { g_return_val_if_fail (GS_IS_FADE (fade), FALSE); return fade->priv->active; @@ -710,8 +646,7 @@ gs_fade_get_active (GSFade *fade) static void gs_fade_set_timeout (GSFade *fade, - guint timeout) -{ + guint timeout) { g_return_if_fail (GS_IS_FADE (fade)); fade->priv->timeout = timeout; @@ -719,23 +654,20 @@ gs_fade_set_timeout (GSFade *fade, static void gs_fade_start (GSFade *fade, - guint timeout) -{ + guint timeout) { guint steps_per_sec = 60; guint msecs_per_step; gboolean active_fade, res; g_return_if_fail (GS_IS_FADE (fade)); - if (fade->priv->screen_priv.fade_type != FADE_TYPE_NONE) - { + if (fade->priv->screen_priv.fade_type != FADE_TYPE_NONE) { res = fade->priv->screen_priv.fade_setup (fade); if (res == FALSE) return; } - if (fade->priv->timer_id > 0) - { + if (fade->priv->timer_id > 0) { gs_fade_stop (fade); } @@ -747,8 +679,7 @@ gs_fade_start (GSFade *fade, if (fade->priv->screen_priv.fade_type != FADE_TYPE_NONE) active_fade = TRUE; - if (active_fade) - { + if (active_fade) { guint num_steps; num_steps = (fade->priv->timeout / 1000) * steps_per_sec; @@ -756,29 +687,24 @@ gs_fade_start (GSFade *fade, fade->priv->alpha_per_iter = 1.0 / (gdouble)num_steps; fade->priv->timer_id = g_timeout_add (msecs_per_step, (GSourceFunc)fade_out_timer, fade); - } - else - { + } else { gs_fade_finish (fade); } } -typedef struct -{ +typedef struct { GSFadeDoneFunc done_cb; gpointer data; } FadedCallbackData; static void gs_fade_async_callback (GSFade *fade, - FadedCallbackData *cdata) -{ + FadedCallbackData *cdata) { g_signal_handlers_disconnect_by_func (fade, gs_fade_async_callback, cdata); - if (cdata->done_cb) - { + if (cdata->done_cb) { cdata->done_cb (fade, cdata->data); } @@ -789,18 +715,15 @@ void gs_fade_async (GSFade *fade, guint timeout, GSFadeDoneFunc func, - gpointer data) -{ + gpointer data) { g_return_if_fail (GS_IS_FADE (fade)); /* if fade is active then pause it */ - if (fade->priv->active) - { + if (fade->priv->active) { gs_fade_stop (fade); } - if (func) - { + if (func) { FadedCallbackData *cb_data; cb_data = g_new0 (FadedCallbackData, 1); @@ -817,8 +740,7 @@ gs_fade_async (GSFade *fade, static void gs_fade_sync_callback (GSFade *fade, - int *flag) -{ + int *flag) { *flag = TRUE; g_signal_handlers_disconnect_by_func (fade, gs_fade_sync_callback, @@ -827,15 +749,13 @@ gs_fade_sync_callback (GSFade *fade, void gs_fade_sync (GSFade *fade, - guint timeout) -{ + guint timeout) { int flag = FALSE; g_return_if_fail (GS_IS_FADE (fade)); /* if fade is active then pause it */ - if (fade->priv->active) - { + if (fade->priv->active) { gs_fade_stop (fade); } @@ -845,21 +765,18 @@ gs_fade_sync (GSFade *fade, gs_fade_start (fade, timeout); - while (! flag) - { + while (!flag) { gtk_main_iteration (); } } void -gs_fade_reset (GSFade *fade) -{ +gs_fade_reset (GSFade *fade) { g_return_if_fail (GS_IS_FADE (fade)); gs_debug ("Resetting fade"); - if (fade->priv->active) - { + if (fade->priv->active) { gs_fade_stop (fade); } @@ -872,13 +789,12 @@ gs_fade_reset (GSFade *fade) } static void -gs_fade_class_init (GSFadeClass *klass) -{ +gs_fade_class_init (GSFadeClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gs_fade_finalize; - signals [FADED] = + signals[FADED] = g_signal_new ("faded", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -891,8 +807,7 @@ gs_fade_class_init (GSFadeClass *klass) } static void -gs_fade_init (GSFade *fade) -{ +gs_fade_init (GSFade *fade) { fade->priv = gs_fade_get_instance_private (fade); fade->priv->timeout = 1000; @@ -905,8 +820,7 @@ gs_fade_init (GSFade *fade) } static void -gs_fade_finalize (GObject *object) -{ +gs_fade_finalize (GObject *object) { GSFade *fade; g_return_if_fail (object != NULL); @@ -926,14 +840,10 @@ gs_fade_finalize (GObject *object) } GSFade * -gs_fade_new (void) -{ - if (fade_object) - { +gs_fade_new (void) { + if (fade_object) { g_object_ref (fade_object); - } - else - { + } else { fade_object = g_object_new (GS_TYPE_FADE, NULL); g_object_add_weak_pointer (fade_object, (gpointer *) &fade_object); diff --git a/src/gs-grab-x11.c b/src/gs-grab-x11.c index 3c67ab52c55aca971722f55c0ce76c76bc082520..d0e300b3a3d62bf3a746bdd5a12389b146e6bd02 100644 --- a/src/gs-grab-x11.c +++ b/src/gs-grab-x11.c @@ -22,10 +22,12 @@ * */ -#include "config.h" +#include <config.h> + #include <stdlib.h> -#include <unistd.h> #include <string.h> +#include <unistd.h> + #include <gdk/gdk.h> #include <gdk/gdkx.h> #include <gtk/gtk.h> @@ -34,9 +36,9 @@ # include <X11/extensions/xf86misc.h> #endif /* HAVE_XF86MISCSETGRABKEYSSTATE */ -#include "gs-window.h" -#include "gs-grab.h" -#include "gs-debug.h" +#include "src/gs-window.h" +#include "src/gs-grab.h" +#include "src/gs-debug.h" static void gs_grab_class_init (GSGrabClass *klass); static void gs_grab_init (GSGrab *grab); @@ -44,8 +46,7 @@ static void gs_grab_finalize (GObject *object); static gpointer grab_object = NULL; -struct GSGrabPrivate -{ +struct GSGrabPrivate { GdkWindow *grab_window; GdkDisplay *grab_display; guint no_pointer_grab : 1; @@ -57,10 +58,8 @@ struct GSGrabPrivate G_DEFINE_TYPE_WITH_PRIVATE (GSGrab, gs_grab, G_TYPE_OBJECT) static const char * -grab_string (int status) -{ - switch (status) - { +grab_string (int status) { + switch (status) { case GDK_GRAB_SUCCESS: return "GrabSuccess"; case GDK_GRAB_ALREADY_GRABBED: @@ -75,7 +74,7 @@ grab_string (int status) return "GrabFailed"; default: { - static char foo [255]; + static char foo[255]; sprintf (foo, "unknown status: %d", status); return foo; } @@ -97,25 +96,20 @@ grab_string (int status) */ static void xorg_lock_smasher_set_active (GSGrab *grab, - gboolean active) -{ + gboolean active) { int status, event, error; GdkDisplay *display; display = gdk_display_get_default(); - if (!XF86MiscQueryExtension (GDK_DISPLAY_XDISPLAY (display), &event, &error)) - { + if (!XF86MiscQueryExtension (GDK_DISPLAY_XDISPLAY (display), &event, &error)) { gs_debug ("No XFree86-Misc extension present"); return; } - if (active) - { + if (active) { gs_debug ("Enabling the x.org grab smasher"); - } - else - { + } else { gs_debug ("Disabling the x.org grab smasher"); } @@ -126,8 +120,7 @@ xorg_lock_smasher_set_active (GSGrab *grab, gdk_display_sync (display); error = gdk_x11_display_error_trap_pop (display); - if (active && status == MiscExtGrabStateAlready) - { + if (active && status == MiscExtGrabStateAlready) { /* shut up, consider this success */ status = MiscExtGrabStateSuccess; } @@ -147,16 +140,14 @@ xorg_lock_smasher_set_active (GSGrab *grab, #else static void xorg_lock_smasher_set_active (GSGrab *grab, - gboolean active) -{ + gboolean active) { } #endif /* HAVE_XF86MISCSETGRABKEYSSTATE */ static void prepare_window_grab_cb (GdkSeat *seat, GdkWindow *window, - gpointer user_data) -{ + gpointer user_data) { gdk_window_show_unraised (window); } @@ -165,8 +156,7 @@ gs_grab_get (GSGrab *grab, GdkWindow *window, GdkDisplay *display, gboolean no_pointer_grab, - gboolean hide_cursor) -{ + gboolean hide_cursor) { GdkGrabStatus status; GdkSeat *seat; GdkSeatCapabilities caps; @@ -196,8 +186,7 @@ gs_grab_get (GSGrab *grab, time between grabbing and ungrabbing is minimal as grab was already completed once */ if (status == GDK_GRAB_SUCCESS && no_pointer_grab && - gdk_display_device_is_grabbed (display, gdk_seat_get_pointer (seat))) - { + gdk_display_device_is_grabbed (display, gdk_seat_get_pointer (seat))) { gs_grab_release (grab, FALSE); gs_debug ("Regrabbing keyboard"); status = gdk_seat_grab (seat, window, @@ -206,10 +195,8 @@ gs_grab_get (GSGrab *grab, NULL, NULL, NULL); } - if (status == GDK_GRAB_SUCCESS) - { - if (grab->priv->grab_window != NULL) - { + if (status == GDK_GRAB_SUCCESS) { + if (grab->priv->grab_window != NULL) { g_object_remove_weak_pointer (G_OBJECT (grab->priv->grab_window), (gpointer *) &grab->priv->grab_window); } @@ -229,10 +216,8 @@ gs_grab_get (GSGrab *grab, } void -gs_grab_reset (GSGrab *grab) -{ - if (grab->priv->grab_window != NULL) - { +gs_grab_reset (GSGrab *grab) { + if (grab->priv->grab_window != NULL) { g_object_remove_weak_pointer (G_OBJECT (grab->priv->grab_window), (gpointer *) &grab->priv->grab_window); } @@ -241,8 +226,7 @@ gs_grab_reset (GSGrab *grab) } void -gs_grab_release (GSGrab *grab, gboolean flush) -{ +gs_grab_release (GSGrab *grab, gboolean flush) { GdkDisplay *display; GdkSeat *seat; @@ -256,8 +240,7 @@ gs_grab_release (GSGrab *grab, gboolean flush) gs_grab_reset (grab); /* FIXME: decide when this is good and when not */ - if (flush) - { + if (flush) { /* FIXME: is it right to enable this? */ xorg_lock_smasher_set_active (grab, TRUE); @@ -271,32 +254,26 @@ gs_grab_move (GSGrab *grab, GdkWindow *window, GdkDisplay *display, gboolean no_pointer_grab, - gboolean hide_cursor) -{ + gboolean hide_cursor) { int result; GdkWindow *old_window; GdkDisplay *old_display; gboolean old_hide_cursor; if (grab->priv->grab_window == window && - grab->priv->no_pointer_grab == no_pointer_grab) - { + grab->priv->no_pointer_grab == no_pointer_grab) { gs_debug ("Window %X is already grabbed, skipping", (guint32) GDK_WINDOW_XID (grab->priv->grab_window)); return TRUE; } - if (grab->priv->grab_window != NULL) - { + if (grab->priv->grab_window != NULL) { gs_debug ("Moving devices grab from %X to %X", (guint32) GDK_WINDOW_XID (grab->priv->grab_window), (guint32) GDK_WINDOW_XID (window)); - } - else - { + } else { gs_debug ("Getting devices grab on %X", (guint32) GDK_WINDOW_XID (window)); - } gs_debug ("*** doing X server grab"); @@ -306,23 +283,20 @@ gs_grab_move (GSGrab *grab, old_display = grab->priv->grab_display; old_hide_cursor = grab->priv->hide_cursor; - if (old_window) - { + if (old_window) { gs_grab_release (grab, FALSE); } result = gs_grab_get (grab, window, display, no_pointer_grab, hide_cursor); - if (result != GDK_GRAB_SUCCESS) - { + if (result != GDK_GRAB_SUCCESS) { g_usleep (G_USEC_PER_SEC); result = gs_grab_get (grab, window, display, no_pointer_grab, hide_cursor); } - if ((result != GDK_GRAB_SUCCESS) && old_window) - { + if ((result != GDK_GRAB_SUCCESS) && old_window) { int old_result; gs_debug ("Could not grab devices for new window. Resuming previous grab."); @@ -340,8 +314,7 @@ gs_grab_move (GSGrab *grab, } static void -gs_grab_nuke_focus (GdkDisplay *display) -{ +gs_grab_nuke_focus (GdkDisplay *display) { Window focus = 0; int rev = 0; @@ -361,22 +334,17 @@ gs_grab_grab_window (GSGrab *grab, GdkWindow *window, GdkDisplay *display, gboolean no_pointer_grab, - gboolean hide_cursor) -{ + gboolean hide_cursor) { gboolean status = FALSE; int i; int retries = 12; - for (i = 0; i < retries; i++) - { + for (i = 0; i < retries; i++) { status = gs_grab_get (grab, window, display, no_pointer_grab, hide_cursor); - if (status == GDK_GRAB_SUCCESS) - { + if (status == GDK_GRAB_SUCCESS) { break; - } - else if (i == (int) (retries / 2)) - { + } else if (i == (int) (retries / 2)) { /* try nuking focus in the middle */ gs_grab_nuke_focus (display); } @@ -385,8 +353,7 @@ gs_grab_grab_window (GSGrab *grab, g_usleep (G_USEC_PER_SEC); } - if (status != GDK_GRAB_SUCCESS) - { + if (status != GDK_GRAB_SUCCESS) { gs_debug ("Couldn't grab devices! (%s)", grab_string (status)); @@ -402,8 +369,7 @@ gs_grab_grab_window (GSGrab *grab, gboolean gs_grab_grab_root (GSGrab *grab, gboolean no_pointer_grab, - gboolean hide_cursor) -{ + gboolean hide_cursor) { GdkDisplay *display; GdkWindow *root; GdkScreen *screen; @@ -427,8 +393,7 @@ gs_grab_grab_root (GSGrab *grab, gboolean gs_grab_grab_offscreen (GSGrab *grab, gboolean no_pointer_grab, - gboolean hide_cursor) -{ + gboolean hide_cursor) { GdkWindow *window; GdkDisplay *display; GdkScreen *screen; @@ -451,16 +416,14 @@ gs_grab_move_to_window (GSGrab *grab, GdkWindow *window, GdkDisplay *display, gboolean no_pointer_grab, - gboolean hide_cursor) -{ + gboolean hide_cursor) { gboolean result = FALSE; g_return_if_fail (GS_IS_GRAB (grab)); xorg_lock_smasher_set_active (grab, FALSE); - while (!result) - { + while (!result) { result = gs_grab_move (grab, window, display, no_pointer_grab, hide_cursor); gdk_display_flush (display); @@ -468,16 +431,14 @@ gs_grab_move_to_window (GSGrab *grab, } static void -gs_grab_class_init (GSGrabClass *klass) -{ +gs_grab_class_init (GSGrabClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gs_grab_finalize; } static void -gs_grab_init (GSGrab *grab) -{ +gs_grab_init (GSGrab *grab) { grab->priv = gs_grab_get_instance_private (grab); grab->priv->no_pointer_grab = FALSE; @@ -487,8 +448,7 @@ gs_grab_init (GSGrab *grab) } static void -gs_grab_finalize (GObject *object) -{ +gs_grab_finalize (GObject *object) { GSGrab *grab; g_return_if_fail (object != NULL); @@ -504,14 +464,10 @@ gs_grab_finalize (GObject *object) } GSGrab * -gs_grab_new (void) -{ - if (grab_object) - { +gs_grab_new (void) { + if (grab_object) { g_object_ref (grab_object); - } - else - { + } else { grab_object = g_object_new (GS_TYPE_GRAB, NULL); g_object_add_weak_pointer (grab_object, (gpointer *) &grab_object); diff --git a/src/gs-job.c b/src/gs-job.c index 1c82f6c7ddf6cbd4bae7ca14eb45b0bf792681d7..9a5ff0b5a77dda8a7c7c53cdcc850a5be8109c87 100644 --- a/src/gs-job.c +++ b/src/gs-job.c @@ -21,36 +21,34 @@ * */ -#include "config.h" +#include <config.h> -#include <stdlib.h> -#include <unistd.h> +#include <errno.h> #include <signal.h> +#include <stdlib.h> +#include <string.h> #include <sys/types.h> #include <sys/wait.h> -#include <errno.h> -#include <string.h> - -#if defined(HAVE_SETPRIORITY) && defined(PRIO_PROCESS) -#include <sys/resource.h> -#endif +#include <unistd.h> #include <glib.h> #include <glib/gstdio.h> #include <gdk/gdk.h> #include <gdk/gdkx.h> -#include "gs-debug.h" -#include "gs-job.h" +#if defined(HAVE_SETPRIORITY) && defined(PRIO_PROCESS) +#include <sys/resource.h> +#endif -#include "subprocs.h" +#include "src/gs-debug.h" +#include "src/gs-job.h" +#include "src/subprocs.h" static void gs_job_class_init (GSJobClass *klass); static void gs_job_init (GSJob *job); static void gs_job_finalize (GObject *object); -typedef enum -{ +typedef enum { GS_JOB_INVALID, GS_JOB_RUNNING, GS_JOB_STOPPED, @@ -58,8 +56,7 @@ typedef enum GS_JOB_DEAD } GSJobStatus; -struct GSJobPrivate -{ +struct GSJobPrivate { GtkWidget *widget; GSJobStatus status; @@ -72,8 +69,7 @@ struct GSJobPrivate G_DEFINE_TYPE_WITH_PRIVATE (GSJob, gs_job, G_TYPE_OBJECT) static char * -widget_get_id_string (GtkWidget *widget) -{ +widget_get_id_string (GtkWidget *widget) { char *id = NULL; g_return_val_if_fail (widget != NULL, NULL); @@ -84,38 +80,29 @@ widget_get_id_string (GtkWidget *widget) } static void -gs_job_class_init (GSJobClass *klass) -{ +gs_job_class_init (GSJobClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gs_job_finalize; } static void -gs_job_init (GSJob *job) -{ +gs_job_init (GSJob *job) { job->priv = gs_job_get_instance_private (job); } /* adapted from gspawn.c */ static int -wait_on_child (int pid) -{ +wait_on_child (int pid) { int status; wait_again: - if (waitpid (pid, &status, 0) < 0) - { - if (errno == EINTR) - { + if (waitpid (pid, &status, 0) < 0) { + if (errno == EINTR) { goto wait_again; - } - else if (errno == ECHILD) - { - ; /* do nothing, child already reaped */ - } - else - { + } else if (errno == ECHILD) { + /* do nothing, child already reaped */ + } else { gs_debug ("waitpid () should not fail in 'GSJob'"); } } @@ -124,10 +111,8 @@ wait_again: } static void -gs_job_died (GSJob *job) -{ - if (job->priv->pid > 0) - { +gs_job_died (GSJob *job) { + if (job->priv->pid > 0) { int exit_status; gs_debug ("Waiting on process %d", job->priv->pid); @@ -135,12 +120,9 @@ gs_job_died (GSJob *job) job->priv->status = GS_JOB_DEAD; - if (WIFEXITED (exit_status) && (WEXITSTATUS (exit_status) != 0)) - { + if (WIFEXITED (exit_status) && (WEXITSTATUS (exit_status) != 0)) { gs_debug ("Wait on child process failed"); - } - else - { + } else { /* exited normally */ } } @@ -151,8 +133,7 @@ gs_job_died (GSJob *job) } static void -gs_job_finalize (GObject *object) -{ +gs_job_finalize (GObject *object) { GSJob *job; g_return_if_fail (object != NULL); @@ -162,8 +143,7 @@ gs_job_finalize (GObject *object) g_return_if_fail (job->priv != NULL); - if (job->priv->pid > 0) - { + if (job->priv->pid > 0) { signal_pid (job->priv->pid, SIGTERM); gs_job_died (job); } @@ -176,18 +156,15 @@ gs_job_finalize (GObject *object) void gs_job_set_widget (GSJob *job, - GtkWidget *widget) -{ + GtkWidget *widget) { g_return_if_fail (job != NULL); g_return_if_fail (GS_IS_JOB (job)); - if (widget != job->priv->widget) - { + if (widget != job->priv->widget) { job->priv->widget = widget; /* restart job */ - if (gs_job_is_running (job)) - { + if (gs_job_is_running (job)) { gs_job_stop (job); gs_job_start (job); } @@ -196,8 +173,7 @@ gs_job_set_widget (GSJob *job, gboolean gs_job_set_command (GSJob *job, - const char *command) -{ + const char *command) { g_return_val_if_fail (GS_IS_JOB (job), FALSE); gs_debug ("Setting command for job: '%s'", @@ -210,8 +186,7 @@ gs_job_set_command (GSJob *job, } GSJob * -gs_job_new (void) -{ +gs_job_new (void) { GObject *job; job = g_object_new (GS_TYPE_JOB, NULL); @@ -220,8 +195,7 @@ gs_job_new (void) } GSJob * -gs_job_new_for_widget (GtkWidget *widget) -{ +gs_job_new_for_widget (GtkWidget *widget) { GObject *job; job = g_object_new (GS_TYPE_JOB, NULL); @@ -233,19 +207,16 @@ gs_job_new_for_widget (GtkWidget *widget) static void nice_process (int pid, - int nice_level) -{ + int nice_level) { g_return_if_fail (pid > 0); - if (nice_level == 0) - { + if (nice_level == 0) { return; } #if defined(HAVE_SETPRIORITY) && defined(PRIO_PROCESS) gs_debug ("Setting child process priority to: %d", nice_level); - if (setpriority (PRIO_PROCESS, pid, nice_level) != 0) - { + if (setpriority (PRIO_PROCESS, pid, nice_level) != 0) { gs_debug ("setpriority(PRIO_PROCESS, %lu, %d) failed", (unsigned long) pid, nice_level); } @@ -255,14 +226,12 @@ nice_process (int pid, } static GPtrArray * -get_env_vars (GtkWidget *widget) -{ +get_env_vars (GtkWidget *widget) { GPtrArray *env; const gchar *display_name; gchar *str; int i; - static const char *allowed_env_vars [] = - { + static const char *allowed_env_vars[] = { "PATH", "SESSION_MANAGER", "XAUTHORITY", @@ -280,14 +249,12 @@ get_env_vars (GtkWidget *widget) g_ptr_array_add (env, g_strdup_printf ("HOME=%s", g_get_home_dir ())); - for (i = 0; i < G_N_ELEMENTS (allowed_env_vars); i++) - { + for (i = 0; i < G_N_ELEMENTS (allowed_env_vars); i++) { const char *var; const char *val; - var = allowed_env_vars [i]; + var = allowed_env_vars[i]; val = g_getenv (var); - if (val != NULL) - { + if (val != NULL) { g_ptr_array_add (env, g_strdup_printf ("%s=%s", var, val)); @@ -309,8 +276,7 @@ spawn_on_widget (GtkWidget *widget, int *pid, GIOFunc watch_func, gpointer user_data, - guint *watch_id) -{ + guint *watch_id) { char **argv; GPtrArray *env; gboolean result; @@ -321,13 +287,11 @@ spawn_on_widget (GtkWidget *widget, int id; int i; - if (command == NULL) - { + if (command == NULL) { return FALSE; } - if (! g_shell_parse_argv (command, NULL, &argv, &error)) - { + if (!g_shell_parse_argv (command, NULL, &argv, &error)) { gs_debug ("Could not parse command: %s", error->message); g_error_free (error); return FALSE; @@ -348,14 +312,12 @@ spawn_on_widget (GtkWidget *widget, &standard_error, &error); - for (i = 0; i < env->len; i++) - { + for (i = 0; i < env->len; i++) { g_free (g_ptr_array_index (env, i)); } g_ptr_array_free (env, TRUE); - if (! result) - { + if (!result) { gs_debug ("Could not start command '%s': %s", command, error->message); g_error_free (error); g_strfreev (argv); @@ -366,12 +328,9 @@ spawn_on_widget (GtkWidget *widget, nice_process (child_pid, 10); - if (pid != NULL) - { + if (pid != NULL) { *pid = child_pid; - } - else - { + } else { g_spawn_close_pid (child_pid); } @@ -384,8 +343,7 @@ spawn_on_widget (GtkWidget *widget, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, watch_func, user_data); - if (watch_id != NULL) - { + if (watch_id != NULL) { *watch_id = id; } @@ -397,45 +355,35 @@ spawn_on_widget (GtkWidget *widget, static gboolean command_watch (GIOChannel *source, GIOCondition condition, - GSJob *job) -{ + GSJob *job) { GIOStatus status; GError *error = NULL; gboolean done = FALSE; g_return_val_if_fail (job != NULL, FALSE); - if (condition & G_IO_IN) - { + if (condition & G_IO_IN) { char *str; status = g_io_channel_read_line (source, &str, NULL, NULL, &error); - if (status == G_IO_STATUS_NORMAL) - { + if (status == G_IO_STATUS_NORMAL) { gs_debug ("command output: %s", str); - } - else if (status == G_IO_STATUS_EOF) - { + } else if (status == G_IO_STATUS_EOF) { done = TRUE; - } - else if (error != NULL) - { + } else if (error != NULL) { gs_debug ("command error: %s", error->message); g_error_free (error); } g_free (str); - } - else if (condition & G_IO_HUP) - { + } else if (condition & G_IO_HUP) { done = TRUE; } - if (done) - { + if (done) { gs_job_died (job); job->priv->watch_id = 0; @@ -446,8 +394,7 @@ command_watch (GIOChannel *source, } gboolean -gs_job_is_running (GSJob *job) -{ +gs_job_is_running (GSJob *job) { gboolean running; g_return_val_if_fail (GS_IS_JOB (job), FALSE); @@ -458,8 +405,7 @@ gs_job_is_running (GSJob *job) } gboolean -gs_job_start (GSJob *job) -{ +gs_job_start (GSJob *job) { gboolean result; g_return_val_if_fail (job != NULL, FALSE); @@ -467,20 +413,17 @@ gs_job_start (GSJob *job) gs_debug ("starting job"); - if (job->priv->pid != 0) - { + if (job->priv->pid != 0) { gs_debug ("Cannot restart active job."); return FALSE; } - if (job->priv->widget == NULL) - { + if (job->priv->widget == NULL) { gs_debug ("Could not start job: screensaver window is not set."); return FALSE; } - if (job->priv->command == NULL) - { + if (job->priv->command == NULL) { /* no warning here because a NULL command is interpreted as a no-op job */ gs_debug ("No command set for job."); @@ -494,8 +437,7 @@ gs_job_start (GSJob *job) job, &job->priv->watch_id); - if (result) - { + if (result) { job->priv->status = GS_JOB_RUNNING; } @@ -503,31 +445,26 @@ gs_job_start (GSJob *job) } static void -remove_command_watch (GSJob *job) -{ - if (job->priv->watch_id != 0) - { +remove_command_watch (GSJob *job) { + if (job->priv->watch_id != 0) { g_source_remove (job->priv->watch_id); job->priv->watch_id = 0; } } gboolean -gs_job_stop (GSJob *job) -{ +gs_job_stop (GSJob *job) { g_return_val_if_fail (job != NULL, FALSE); g_return_val_if_fail (GS_IS_JOB (job), FALSE); gs_debug ("stopping job"); - if (job->priv->pid == 0) - { + if (job->priv->pid == 0) { gs_debug ("Could not stop job: pid not defined"); return FALSE; } - if (job->priv->status == GS_JOB_STOPPED) - { + if (job->priv->status == GS_JOB_STOPPED) { gs_job_suspend (job, FALSE); } @@ -544,15 +481,13 @@ gs_job_stop (GSJob *job) gboolean gs_job_suspend (GSJob *job, - gboolean suspend) -{ + gboolean suspend) { g_return_val_if_fail (job != NULL, FALSE); g_return_val_if_fail (GS_IS_JOB (job), FALSE); gs_debug ("suspending job"); - if (job->priv->pid == 0) - { + if (job->priv->pid == 0) { return FALSE; } diff --git a/src/gs-listener-dbus.c b/src/gs-listener-dbus.c index 2f20c5960f68b7f741a5ac8500cb1f5d6e85424d..d8761dea32be276e896f11ad6118a0fd03c2035f 100644 --- a/src/gs-listener-dbus.c +++ b/src/gs-listener-dbus.c @@ -21,26 +21,27 @@ * */ -#include "config.h" -#include <stdlib.h> +#include <config.h> + #include <stdio.h> -#include <time.h> +#include <stdlib.h> #include <string.h> +#include <time.h> #include <unistd.h> -#include <libxfce4util/libxfce4util.h> - #include <dbus/dbus.h> #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> +#include <libxfce4util/libxfce4util.h> + #ifdef WITH_SYSTEMD #include <systemd/sd-login.h> #endif -#include "gs-listener-dbus.h" -#include "gs-marshal.h" -#include "gs-debug.h" +#include "src/gs-listener-dbus.h" +#include "src/gs-marshal.h" +#include "src/gs-debug.h" static void gs_listener_class_init (GSListenerClass *klass); static void gs_listener_init (GSListener *listener); @@ -79,8 +80,7 @@ static DBusHandlerResult gs_listener_message_handler (DBusConnection *connec #define TYPE_MISMATCH_ERROR GS_LISTENER_INTERFACE ".TypeMismatch" -struct GSListenerPrivate -{ +struct GSListenerPrivate { DBusConnection *connection; DBusConnection *system_connection; @@ -101,8 +101,7 @@ struct GSListenerPrivate guint32 ck_throttle_cookie; }; -typedef struct -{ +typedef struct { int entry_type; char *application; char *reason; @@ -112,8 +111,7 @@ typedef struct GTimeVal since; } GSListenerRefEntry; -enum -{ +enum { LOCK, CYCLE, QUIT, @@ -124,16 +122,14 @@ enum LAST_SIGNAL }; -enum -{ +enum { PROP_0, PROP_ACTIVE, PROP_SESSION_IDLE, PROP_ACTIVATION_ENABLED, }; -enum -{ +enum { REF_ENTRY_TYPE_INHIBIT, REF_ENTRY_TYPE_THROTTLE }; @@ -147,16 +143,14 @@ gs_listener_vtable = { &gs_listener_unregister_handler, NULL }; -static guint signals [LAST_SIGNAL] = { 0, }; +static guint signals[LAST_SIGNAL] = { 0, }; G_DEFINE_TYPE_WITH_PRIVATE (GSListener, gs_listener, G_TYPE_OBJECT) GQuark -gs_listener_error_quark (void) -{ +gs_listener_error_quark (void) { static GQuark quark = 0; - if (!quark) - { + if (!quark) { quark = g_quark_from_static_string ("gs_listener_error"); } @@ -164,8 +158,7 @@ gs_listener_error_quark (void) } static void -gs_listener_ref_entry_free (GSListenerRefEntry *entry) -{ +gs_listener_ref_entry_free (GSListenerRefEntry *entry) { g_free (entry->connection); g_free (entry->application); g_free (entry->reason); @@ -175,28 +168,24 @@ gs_listener_ref_entry_free (GSListenerRefEntry *entry) static void gs_listener_unregister_handler (DBusConnection *connection, - void *data) -{ + void *data) { } static gboolean send_dbus_message (DBusConnection *connection, - DBusMessage *message) -{ + DBusMessage *message) { gboolean is_connected; gboolean sent; g_return_val_if_fail (message != NULL, FALSE); - if (!connection) - { + if (!connection) { gs_debug ("There is no valid connection to the message bus"); return FALSE; } is_connected = dbus_connection_get_is_connected (connection); - if (!is_connected) - { + if (!is_connected) { gs_debug ("Not connected to the message bus"); return FALSE; } @@ -209,8 +198,7 @@ send_dbus_message (DBusConnection *connection, static void send_dbus_boolean_signal (GSListener *listener, const char *name, - gboolean value) -{ + gboolean value) { DBusMessage *message; DBusMessageIter iter; @@ -223,8 +211,7 @@ send_dbus_boolean_signal (GSListener *listener, dbus_message_iter_init_append (message, &iter); dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &value); - if (! send_dbus_message (listener->priv->connection, message)) - { + if (!send_dbus_message (listener->priv->connection, message)) { gs_debug ("Could not send %s signal", name); } @@ -232,8 +219,7 @@ send_dbus_boolean_signal (GSListener *listener, } static void -gs_listener_send_signal_active_changed (GSListener *listener) -{ +gs_listener_send_signal_active_changed (GSListener *listener) { g_return_if_fail (listener != NULL); gs_debug ("Sending the ActiveChanged(%s) signal on the session bus", @@ -243,12 +229,10 @@ gs_listener_send_signal_active_changed (GSListener *listener) } static const char * -get_name_for_entry_type (int entry_type) -{ +get_name_for_entry_type (int entry_type) { const char *name; - switch (entry_type) - { + switch (entry_type) { case REF_ENTRY_TYPE_INHIBIT: name = "inhibitor"; break; @@ -265,12 +249,10 @@ get_name_for_entry_type (int entry_type) static GHashTable * get_hash_for_entry_type (GSListener *listener, - int entry_type) -{ + int entry_type) { GHashTable *hash; - switch (entry_type) - { + switch (entry_type) { case REF_ENTRY_TYPE_INHIBIT: hash = listener->priv->inhibitors; break; @@ -288,8 +270,7 @@ get_hash_for_entry_type (GSListener *listener, static void list_ref_entry (gpointer key, gpointer value, - gpointer user_data) -{ + gpointer user_data) { GSListenerRefEntry *entry; entry = (GSListenerRefEntry *)value; @@ -302,8 +283,7 @@ list_ref_entry (gpointer key, static gboolean listener_ref_entry_is_present (GSListener *listener, - int entry_type) -{ + int entry_type) { guint n_entries; gboolean is_set; GHashTable *hash; @@ -312,8 +292,7 @@ listener_ref_entry_is_present (GSListener *listener, /* if we aren't inhibited then activate */ n_entries = 0; - if (hash != NULL) - { + if (hash != NULL) { n_entries = g_hash_table_size (hash); g_hash_table_foreach (hash, list_ref_entry, NULL); @@ -325,20 +304,17 @@ listener_ref_entry_is_present (GSListener *listener, } static gboolean -listener_check_activation (GSListener *listener) -{ +listener_check_activation (GSListener *listener) { gboolean inhibited; gboolean res; gs_debug ("Checking for activation"); - if (! listener->priv->activation_enabled) - { + if (!listener->priv->activation_enabled) { return TRUE; } - if (! listener->priv->session_idle) - { + if (!listener->priv->session_idle) { return TRUE; } @@ -346,8 +322,7 @@ listener_check_activation (GSListener *listener) inhibited = listener_ref_entry_is_present (listener, REF_ENTRY_TYPE_INHIBIT); res = FALSE; - if (! inhibited) - { + if (!inhibited) { gs_debug ("Trying to activate"); res = gs_listener_set_active (listener, TRUE); } @@ -357,31 +332,27 @@ listener_check_activation (GSListener *listener) static void gs_listener_set_throttle (GSListener *listener, - gboolean throttled) -{ + gboolean throttled) { g_return_if_fail (GS_IS_LISTENER (listener)); - if (listener->priv->throttled != throttled) - { + if (listener->priv->throttled != throttled) { gs_debug ("Changing throttle status: %d", throttled); listener->priv->throttled = throttled; - g_signal_emit (listener, signals [THROTTLE_CHANGED], 0, throttled); + g_signal_emit (listener, signals[THROTTLE_CHANGED], 0, throttled); } } static gboolean -listener_check_throttle (GSListener *listener) -{ +listener_check_throttle (GSListener *listener) { gboolean throttled; gs_debug ("Checking for throttle"); throttled = listener_ref_entry_is_present (listener, REF_ENTRY_TYPE_THROTTLE); - if (throttled != listener->priv->throttled) - { + if (throttled != listener->priv->throttled) { gs_listener_set_throttle (listener, throttled); } @@ -390,16 +361,12 @@ listener_check_throttle (GSListener *listener) static gboolean listener_set_session_idle_internal (GSListener *listener, - gboolean idle) -{ + gboolean idle) { listener->priv->session_idle = idle; - if (idle) - { + if (idle) { listener->priv->session_idle_start = time (NULL); - } - else - { + } else { listener->priv->session_idle_start = 0; } @@ -408,22 +375,17 @@ listener_set_session_idle_internal (GSListener *listener, static gboolean listener_set_active_internal (GSListener *listener, - gboolean active) -{ + gboolean active) { listener->priv->active = active; /* if idle not in sync with active, change it */ - if (listener->priv->session_idle != active) - { + if (listener->priv->session_idle != active) { listener_set_session_idle_internal (listener, active); } - if (active) - { + if (active) { listener->priv->active_start = time (NULL); - } - else - { + } else { listener->priv->active_start = 0; } @@ -434,29 +396,25 @@ listener_set_active_internal (GSListener *listener, gboolean gs_listener_set_active (GSListener *listener, - gboolean active) -{ + gboolean active) { gboolean res; g_return_val_if_fail (GS_IS_LISTENER (listener), FALSE); - if (listener->priv->active == active) - { + if (listener->priv->active == active) { gs_debug ("Trying to set active state when already: %s", active ? "active" : "inactive"); return FALSE; } res = FALSE; - g_signal_emit (listener, signals [ACTIVE_CHANGED], 0, active, &res); - if (! res) - { + g_signal_emit (listener, signals[ACTIVE_CHANGED], 0, active, &res); + if (!res) { /* if the signal is not handled then we haven't changed state */ gs_debug ("Active-changed signal not handled"); /* clear the idle state */ - if (active) - { + if (active) { listener_set_session_idle_internal (listener, FALSE); } @@ -470,30 +428,26 @@ gs_listener_set_active (GSListener *listener, gboolean gs_listener_set_session_idle (GSListener *listener, - gboolean idle) -{ + gboolean idle) { gboolean res; g_return_val_if_fail (GS_IS_LISTENER (listener), FALSE); gs_debug ("Setting session idle: %d", idle); - if (listener->priv->session_idle == idle) - { + if (listener->priv->session_idle == idle) { gs_debug ("Trying to set idle state when already %s", idle ? "idle" : "not idle"); return FALSE; } - if (idle) - { + if (idle) { gboolean inhibited; inhibited = listener_ref_entry_is_present (listener, REF_ENTRY_TYPE_INHIBIT); /* if we are inhibited then do nothing */ - if (inhibited) - { + if (inhibited) { return FALSE; } } @@ -502,12 +456,9 @@ gs_listener_set_session_idle (GSListener *listener, res = listener_check_activation (listener); /* if activation fails then don't set idle */ - if (res) - { + if (res) { listener_set_session_idle_internal (listener, idle); - } - else - { + } else { gs_debug ("Idle activation failed"); listener->priv->session_idle = !idle; } @@ -516,16 +467,14 @@ gs_listener_set_session_idle (GSListener *listener, } gboolean -gs_listener_get_activation_enabled (GSListener *listener) -{ +gs_listener_get_activation_enabled (GSListener *listener) { g_return_val_if_fail (GS_IS_LISTENER (listener), FALSE); return listener->priv->activation_enabled; } gboolean -gs_listener_is_inhibited (GSListener *listener) -{ +gs_listener_is_inhibited (GSListener *listener) { gboolean inhibited; g_return_val_if_fail (GS_IS_LISTENER (listener), FALSE); @@ -537,12 +486,10 @@ gs_listener_is_inhibited (GSListener *listener) void gs_listener_set_activation_enabled (GSListener *listener, - gboolean enabled) -{ + gboolean enabled) { g_return_if_fail (GS_IS_LISTENER (listener)); - if (listener->priv->activation_enabled != enabled) - { + if (listener->priv->activation_enabled != enabled) { listener->priv->activation_enabled = enabled; } } @@ -550,14 +497,12 @@ gs_listener_set_activation_enabled (GSListener *listener, static dbus_bool_t listener_property_set_bool (GSListener *listener, guint prop_id, - dbus_bool_t value) -{ + dbus_bool_t value) { dbus_bool_t ret; ret = FALSE; - switch (prop_id) - { + switch (prop_id) { case PROP_ACTIVE: gs_listener_set_active (listener, value); ret = TRUE; @@ -573,8 +518,7 @@ static void raise_error (DBusConnection *connection, DBusMessage *in_reply_to, const char *error_name, - char *format, ...) -{ + char *format, ...) { char buf[512]; DBusMessage *reply; @@ -585,12 +529,10 @@ raise_error (DBusConnection *connection, gs_debug (buf); reply = dbus_message_new_error (in_reply_to, error_name, buf); - if (reply == NULL) - { + if (reply == NULL) { g_error ("No memory"); } - if (! dbus_connection_send (connection, reply, NULL)) - { + if (!dbus_connection_send (connection, reply, NULL)) { g_error ("No memory"); } @@ -600,8 +542,7 @@ raise_error (DBusConnection *connection, static void raise_syntax (DBusConnection *connection, DBusMessage *in_reply_to, - const char *method_name) -{ + const char *method_name) { raise_error (connection, in_reply_to, GS_LISTENER_SERVICE ".SyntaxError", "There is a syntax error in the invocation of the method %s", @@ -609,8 +550,7 @@ raise_syntax (DBusConnection *connection, } static guint32 -generate_cookie (void) -{ +generate_cookie (void) { guint32 cookie; cookie = (guint32)g_random_int_range (1, G_MAXINT32); @@ -620,28 +560,23 @@ generate_cookie (void) static guint32 listener_generate_unique_key (GSListener *listener, - int entry_type) -{ + int entry_type) { guint32 cookie; GHashTable *hash; hash = get_hash_for_entry_type (listener, entry_type); - do - { + do { cookie = generate_cookie (); - } - while (g_hash_table_lookup (hash, &cookie) != NULL); + } while (g_hash_table_lookup (hash, &cookie) != NULL); return cookie; } static void listener_ref_entry_check (GSListener *listener, - int entry_type) -{ - switch (entry_type) - { + int entry_type) { + switch (entry_type) { case REF_ENTRY_TYPE_INHIBIT: listener_check_activation (listener); break; @@ -656,8 +591,7 @@ listener_ref_entry_check (GSListener *listener, static void add_session_inhibit (GSListener *listener, - GSListenerRefEntry *entry) -{ + GSListenerRefEntry *entry) { DBusMessage *message; DBusMessage *reply; DBusMessageIter iter; @@ -674,8 +608,7 @@ add_session_inhibit (GSListener *listener, SESSION_PATH, SESSION_INTERFACE, "Inhibit"); - if (message == NULL) - { + if (message == NULL) { gs_debug ("Couldn't allocate the dbus message"); return; } @@ -695,8 +628,7 @@ add_session_inhibit (GSListener *listener, &error); dbus_message_unref (message); - if (dbus_error_is_set (&error)) - { + if (dbus_error_is_set (&error)) { gs_debug ("%s raised:\n %s\n\n", error.name, error.message); dbus_error_free (&error); return; @@ -710,8 +642,7 @@ add_session_inhibit (GSListener *listener, static void remove_session_inhibit (GSListener *listener, - GSListenerRefEntry *entry) -{ + GSListenerRefEntry *entry) { DBusMessage *message; DBusMessage *reply; DBusMessageIter iter; @@ -719,8 +650,7 @@ remove_session_inhibit (GSListener *listener, g_return_if_fail (listener != NULL); - if (entry->foreign_cookie == 0) - { + if (entry->foreign_cookie == 0) { gs_debug ("Can't remove inhibitor from session: Session cookie not set"); return; } @@ -731,8 +661,7 @@ remove_session_inhibit (GSListener *listener, SESSION_PATH, SESSION_INTERFACE, "Uninhibit"); - if (message == NULL) - { + if (message == NULL) { gs_debug ("Couldn't allocate the dbus message"); return; } @@ -747,8 +676,7 @@ remove_session_inhibit (GSListener *listener, &error); dbus_message_unref (message); - if (dbus_error_is_set (&error)) - { + if (dbus_error_is_set (&error)) { gs_debug ("%s raised:\n %s\n\n", error.name, error.message); dbus_error_free (&error); return; @@ -760,8 +688,7 @@ remove_session_inhibit (GSListener *listener, static void listener_add_ref_entry (GSListener *listener, int entry_type, - GSListenerRefEntry *entry) -{ + GSListenerRefEntry *entry) { GHashTable *hash; gs_debug ("adding %s from %s for reason '%s' on connection %s", @@ -773,8 +700,7 @@ listener_add_ref_entry (GSListener *listener, hash = get_hash_for_entry_type (listener, entry_type); g_hash_table_insert (hash, &entry->cookie, entry); - if (entry_type == REF_ENTRY_TYPE_INHIBIT) - { + if (entry_type == REF_ENTRY_TYPE_INHIBIT) { /* proxy inhibit over to xfce session */ add_session_inhibit (listener, entry); } @@ -785,8 +711,7 @@ listener_add_ref_entry (GSListener *listener, static gboolean listener_remove_ref_entry (GSListener *listener, int entry_type, - guint32 cookie) -{ + guint32 cookie) { GHashTable *hash; gboolean removed; GSListenerRefEntry *entry; @@ -796,8 +721,7 @@ listener_remove_ref_entry (GSListener *listener, hash = get_hash_for_entry_type (listener, entry_type); entry = g_hash_table_lookup (hash, &cookie); - if (entry == NULL) - { + if (entry == NULL) { goto out; } @@ -807,20 +731,16 @@ listener_remove_ref_entry (GSListener *listener, entry->reason, entry->connection); - if (entry_type == REF_ENTRY_TYPE_INHIBIT) - { + if (entry_type == REF_ENTRY_TYPE_INHIBIT) { /* remove inhibit from xfce session */ remove_session_inhibit (listener, entry); } removed = g_hash_table_remove (hash, &cookie); out: - if (removed) - { + if (removed) { listener_ref_entry_check (listener, entry_type); - } - else - { + } else { gs_debug ("Cookie %u was not in the list!", cookie); } @@ -830,8 +750,7 @@ out: static void accumulate_ref_entry (gpointer key, GSListenerRefEntry *entry, - DBusMessageIter *iter) -{ + DBusMessageIter *iter) { char *description; char *time; @@ -852,8 +771,7 @@ static DBusHandlerResult listener_dbus_get_ref_entries (GSListener *listener, int entry_type, DBusConnection *connection, - DBusMessage *message) -{ + DBusMessage *message) { DBusMessage *reply; GHashTable *hash; DBusMessageIter iter; @@ -862,8 +780,7 @@ listener_dbus_get_ref_entries (GSListener *listener, hash = get_hash_for_entry_type (listener, entry_type); reply = dbus_message_new_method_return (message); - if (reply == NULL) - { + if (reply == NULL) { g_error ("No memory"); } @@ -873,8 +790,7 @@ listener_dbus_get_ref_entries (GSListener *listener, DBUS_TYPE_STRING_AS_STRING, &iter_array); - if (hash != NULL) - { + if (hash != NULL) { g_hash_table_foreach (hash, (GHFunc)accumulate_ref_entry, &iter_array); @@ -882,8 +798,7 @@ listener_dbus_get_ref_entries (GSListener *listener, dbus_message_iter_close_container (&iter, &iter_array); - if (! dbus_connection_send (connection, reply, NULL)) - { + if (!dbus_connection_send (connection, reply, NULL)) { g_error ("No memory"); } @@ -898,8 +813,7 @@ listener_add_ck_ref_entry (GSListener *listener, int entry_type, DBusConnection *connection, DBusMessage *message, - guint32 *cookiep) -{ + guint32 *cookiep) { GSListenerRefEntry *entry; entry = g_new0 (GSListenerRefEntry, 1); @@ -913,8 +827,7 @@ listener_add_ck_ref_entry (GSListener *listener, /* takes ownership of entry */ listener_add_ref_entry (listener, entry_type, entry); - if (cookiep != NULL) - { + if (cookiep != NULL) { *cookiep = entry->cookie; } } @@ -922,8 +835,7 @@ listener_add_ck_ref_entry (GSListener *listener, static void listener_remove_ck_ref_entry (GSListener *listener, int entry_type, - guint32 cookie) -{ + guint32 cookie) { listener_remove_ref_entry (listener, entry_type, cookie); } #endif @@ -932,8 +844,7 @@ static DBusHandlerResult listener_dbus_add_ref_entry (GSListener *listener, int entry_type, DBusConnection *connection, - DBusMessage *message) -{ + DBusMessage *message) { DBusMessage *reply; DBusError error; const char *application; @@ -942,21 +853,15 @@ listener_dbus_add_ref_entry (GSListener *listener, DBusMessageIter iter; dbus_error_init (&error); - if (! dbus_message_get_args (message, &error, - DBUS_TYPE_STRING, &application, - DBUS_TYPE_STRING, &reason, - DBUS_TYPE_INVALID)) - { - if (entry_type == REF_ENTRY_TYPE_INHIBIT) - { + if (!dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &application, + DBUS_TYPE_STRING, &reason, + DBUS_TYPE_INVALID)) { + if (entry_type == REF_ENTRY_TYPE_INHIBIT) { raise_syntax (connection, message, "Inhibit"); - } - else if (entry_type == REF_ENTRY_TYPE_THROTTLE) - { + } else if (entry_type == REF_ENTRY_TYPE_THROTTLE) { raise_syntax (connection, message, "Throttle"); - } - else - { + } else { g_assert_not_reached (); } @@ -964,8 +869,7 @@ listener_dbus_add_ref_entry (GSListener *listener, } reply = dbus_message_new_method_return (message); - if (reply == NULL) - { + if (reply == NULL) { g_error ("No memory"); } @@ -982,8 +886,7 @@ listener_dbus_add_ref_entry (GSListener *listener, dbus_message_iter_init_append (reply, &iter); dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &entry->cookie); - if (! dbus_connection_send (connection, reply, NULL)) - { + if (!dbus_connection_send (connection, reply, NULL)) { g_error ("No memory"); } @@ -996,27 +899,20 @@ static DBusHandlerResult listener_dbus_remove_ref_entry (GSListener *listener, int entry_type, DBusConnection *connection, - DBusMessage *message) -{ + DBusMessage *message) { DBusMessage *reply; DBusError error; guint32 cookie; dbus_error_init (&error); - if (! dbus_message_get_args (message, &error, - DBUS_TYPE_UINT32, &cookie, - DBUS_TYPE_INVALID)) - { - if (entry_type == REF_ENTRY_TYPE_INHIBIT) - { + if (!dbus_message_get_args (message, &error, + DBUS_TYPE_UINT32, &cookie, + DBUS_TYPE_INVALID)) { + if (entry_type == REF_ENTRY_TYPE_INHIBIT) { raise_syntax (connection, message, "UnInhibit"); - } - else if (entry_type == REF_ENTRY_TYPE_THROTTLE) - { + } else if (entry_type == REF_ENTRY_TYPE_THROTTLE) { raise_syntax (connection, message, "UnThrottle"); - } - else - { + } else { g_assert_not_reached (); } @@ -1033,8 +929,7 @@ listener_dbus_remove_ref_entry (GSListener *listener, listener_remove_ref_entry (listener, entry_type, cookie); /* FIXME: Pointless? */ - if (! dbus_connection_send (connection, reply, NULL)) - { + if (!dbus_connection_send (connection, reply, NULL)) { g_error ("No memory"); } @@ -1046,8 +941,7 @@ listener_dbus_remove_ref_entry (GSListener *listener, static gboolean listener_ref_entry_remove_for_connection (GSListener *listener, int entry_type, - const char *connection) -{ + const char *connection) { gboolean removed; GHashTable *hash; GHashTableIter iter; @@ -1060,19 +954,16 @@ listener_ref_entry_remove_for_connection (GSListener *listener, removed = FALSE; g_hash_table_iter_init (&iter, hash); - while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&entry)) - { + while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&entry)) { if (entry->connection != NULL && - strcmp (connection, entry->connection) == 0) - { + strcmp (connection, entry->connection) == 0) { gs_debug ("removing %s from %s for reason '%s' on connection %s", get_name_for_entry_type (entry->entry_type), entry->application, entry->reason, entry->connection); - if (entry->entry_type == REF_ENTRY_TYPE_INHIBIT) - { + if (entry->entry_type == REF_ENTRY_TYPE_INHIBIT) { /* remove inhibit from xfce session */ remove_session_inhibit (listener, entry); } @@ -1087,17 +978,15 @@ listener_ref_entry_remove_for_connection (GSListener *listener, static void listener_service_deleted (GSListener *listener, - DBusMessage *message) -{ + DBusMessage *message) { const char *old_service_name; const char *new_service_name; gboolean removed; - if (! dbus_message_get_args (message, NULL, - DBUS_TYPE_STRING, &old_service_name, - DBUS_TYPE_STRING, &new_service_name, - DBUS_TYPE_INVALID)) - { + if (!dbus_message_get_args (message, NULL, + DBUS_TYPE_STRING, &old_service_name, + DBUS_TYPE_STRING, &new_service_name, + DBUS_TYPE_INVALID)) { g_error ("Invalid NameOwnerChanged signal from bus!"); return; } @@ -1105,28 +994,24 @@ listener_service_deleted (GSListener *listener, gs_debug ("DBUS service deleted: %s", new_service_name); removed = listener_ref_entry_remove_for_connection (listener, REF_ENTRY_TYPE_THROTTLE, new_service_name); - if (removed) - { + if (removed) { listener_ref_entry_check (listener, REF_ENTRY_TYPE_THROTTLE); } removed = listener_ref_entry_remove_for_connection (listener, REF_ENTRY_TYPE_INHIBIT, new_service_name); - if (removed) - { + if (removed) { listener_ref_entry_check (listener, REF_ENTRY_TYPE_INHIBIT); } - } static void raise_property_type_error (DBusConnection *connection, DBusMessage *in_reply_to, - const char *device_id) -{ - char buf [512]; + const char *device_id) { + char buf[512]; DBusMessage *reply; - snprintf (buf, 511, + snprintf (buf, sizeof(buf), "Type mismatch setting property with id %s", device_id); gs_debug (buf); @@ -1134,12 +1019,10 @@ raise_property_type_error (DBusConnection *connection, reply = dbus_message_new_error (in_reply_to, TYPE_MISMATCH_ERROR, buf); - if (reply == NULL) - { + if (reply == NULL) { g_error ("No memory"); } - if (! dbus_connection_send (connection, reply, NULL)) - { + if (!dbus_connection_send (connection, reply, NULL)) { g_error ("No memory"); } @@ -1150,8 +1033,7 @@ static DBusHandlerResult listener_set_property (GSListener *listener, DBusConnection *connection, DBusMessage *message, - guint prop_id) -{ + guint prop_id) { const char *path; int type; gboolean rc; @@ -1164,8 +1046,7 @@ listener_set_property (GSListener *listener, type = dbus_message_iter_get_arg_type (&iter); rc = FALSE; - switch (type) - { + switch (type) { case DBUS_TYPE_BOOLEAN: { dbus_bool_t v; @@ -1178,21 +1059,18 @@ listener_set_property (GSListener *listener, break; } - if (! rc) - { + if (!rc) { raise_property_type_error (connection, message, path); return DBUS_HANDLER_RESULT_HANDLED; } reply = dbus_message_new_method_return (message); - if (reply == NULL) - { + if (reply == NULL) { g_error ("No memory"); } - if (! dbus_connection_send (connection, reply, NULL)) - { + if (!dbus_connection_send (connection, reply, NULL)) { g_error ("No memory"); } @@ -1205,8 +1083,7 @@ static DBusHandlerResult listener_get_property (GSListener *listener, DBusConnection *connection, DBusMessage *message, - guint prop_id) -{ + guint prop_id) { DBusMessageIter iter; DBusMessage *reply; @@ -1217,8 +1094,7 @@ listener_get_property (GSListener *listener, if (reply == NULL) g_error ("No memory"); - switch (prop_id) - { + switch (prop_id) { case PROP_ACTIVE: { dbus_bool_t b; @@ -1231,8 +1107,7 @@ listener_get_property (GSListener *listener, break; } - if (! dbus_connection_send (connection, reply, NULL)) - { + if (!dbus_connection_send (connection, reply, NULL)) { g_error ("No memory"); } @@ -1244,8 +1119,7 @@ listener_get_property (GSListener *listener, static DBusHandlerResult listener_get_active_time (GSListener *listener, DBusConnection *connection, - DBusMessage *message) -{ + DBusMessage *message) { DBusMessageIter iter; DBusMessage *reply; dbus_uint32_t secs; @@ -1254,42 +1128,32 @@ listener_get_active_time (GSListener *listener, dbus_message_iter_init_append (reply, &iter); - if (reply == NULL) - { + if (reply == NULL) { g_error ("No memory"); } - if (listener->priv->active) - { + if (listener->priv->active) { time_t now = time (NULL); - if (now < listener->priv->active_start) - { + if (now < listener->priv->active_start) { /* shouldn't happen */ gs_debug ("Active start time is in the future"); secs = 0; - } - else if (listener->priv->active_start <= 0) - { + } else if (listener->priv->active_start <= 0) { /* shouldn't happen */ gs_debug ("Active start time was not set"); secs = 0; - } - else - { + } else { secs = now - listener->priv->active_start; } - } - else - { + } else { secs = 0; } gs_debug ("Returning screensaver active for %u seconds", secs); dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &secs); - if (! dbus_connection_send (connection, reply, NULL)) - { + if (!dbus_connection_send (connection, reply, NULL)) { g_error ("No memory"); } @@ -1301,8 +1165,7 @@ listener_get_active_time (GSListener *listener, static DBusHandlerResult listener_show_message (GSListener *listener, DBusConnection *connection, - DBusMessage *message) -{ + DBusMessage *message) { DBusMessageIter iter; DBusMessage *reply; DBusError error; @@ -1311,13 +1174,11 @@ listener_show_message (GSListener *listener, dbus_message_iter_init_append (reply, &iter); - if (reply == NULL) - { + if (reply == NULL) { g_error ("No memory"); } - if (listener->priv->active) - { + if (listener->priv->active) { char *summary; char *body; char *icon; @@ -1325,21 +1186,19 @@ listener_show_message (GSListener *listener, /* if we're not active we ignore the request */ dbus_error_init (&error); - if (! dbus_message_get_args (message, &error, - DBUS_TYPE_STRING, &summary, - DBUS_TYPE_STRING, &body, - DBUS_TYPE_STRING, &icon, - DBUS_TYPE_INVALID)) - { + if (!dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &summary, + DBUS_TYPE_STRING, &body, + DBUS_TYPE_STRING, &icon, + DBUS_TYPE_INVALID)) { raise_syntax (connection, message, "ShowMessage"); return DBUS_HANDLER_RESULT_HANDLED; } - g_signal_emit (listener, signals [SHOW_MESSAGE], 0, summary, body, icon); + g_signal_emit (listener, signals[SHOW_MESSAGE], 0, summary, body, icon); } - if (! dbus_connection_send (connection, reply, NULL)) - { + if (!dbus_connection_send (connection, reply, NULL)) { g_error ("No memory"); } @@ -1351,8 +1210,7 @@ listener_show_message (GSListener *listener, static DBusHandlerResult do_introspect (DBusConnection *connection, DBusMessage *message, - dbus_bool_t local_interface) -{ + dbus_bool_t local_interface) { DBusMessage *reply; GString *xml; char *xml_string; @@ -1425,13 +1283,11 @@ do_introspect (DBusConnection *connection, g_free (xml_string); - if (reply == NULL) - { + if (reply == NULL) { g_error ("No memory"); } - if (! dbus_connection_send (connection, reply, NULL)) - { + if (!dbus_connection_send (connection, reply, NULL)) { g_error ("No memory"); } @@ -1444,8 +1300,7 @@ static DBusHandlerResult listener_dbus_handle_session_message (DBusConnection *connection, DBusMessage *message, void *user_data, - dbus_bool_t local_interface) -{ + dbus_bool_t local_interface) { GSListener *listener = GS_LISTENER (user_data); #if 0 @@ -1459,64 +1314,50 @@ listener_dbus_handle_session_message (DBusConnection *connection, g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "Lock")) - { - g_signal_emit (listener, signals [LOCK], 0); + if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "Lock")) { + g_signal_emit (listener, signals[LOCK], 0); return DBUS_HANDLER_RESULT_HANDLED; } - if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "Quit")) - { - g_signal_emit (listener, signals [QUIT], 0); + if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "Quit")) { + g_signal_emit (listener, signals[QUIT], 0); return DBUS_HANDLER_RESULT_HANDLED; } - if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "Cycle")) - { - g_signal_emit (listener, signals [CYCLE], 0); + if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "Cycle")) { + g_signal_emit (listener, signals[CYCLE], 0); return DBUS_HANDLER_RESULT_HANDLED; } - if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "Inhibit")) - { + if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "Inhibit")) { return listener_dbus_add_ref_entry (listener, REF_ENTRY_TYPE_INHIBIT, connection, message); } - if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "UnInhibit")) - { + if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "UnInhibit")) { return listener_dbus_remove_ref_entry (listener, REF_ENTRY_TYPE_INHIBIT, connection, message); } - if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "GetInhibitors")) - { + if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "GetInhibitors")) { return listener_dbus_get_ref_entries (listener, REF_ENTRY_TYPE_INHIBIT, connection, message); } - if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "Throttle")) - { + if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "Throttle")) { return listener_dbus_add_ref_entry (listener, REF_ENTRY_TYPE_THROTTLE, connection, message); } - if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "UnThrottle")) - { + if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "UnThrottle")) { return listener_dbus_remove_ref_entry (listener, REF_ENTRY_TYPE_THROTTLE, connection, message); } - if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "SetActive")) - { + if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "SetActive")) { return listener_set_property (listener, connection, message, PROP_ACTIVE); } - if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "GetActive")) - { + if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "GetActive")) { return listener_get_property (listener, connection, message, PROP_ACTIVE); } - if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "GetActiveTime")) - { + if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "GetActiveTime")) { return listener_get_active_time (listener, connection, message); } - if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "ShowMessage")) - { + if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "ShowMessage")) { return listener_show_message (listener, connection, message); } - if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "SimulateUserActivity")) - { - g_signal_emit (listener, signals [SIMULATE_USER_ACTIVITY], 0); + if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "SimulateUserActivity")) { + g_signal_emit (listener, signals[SIMULATE_USER_ACTIVITY], 0); return DBUS_HANDLER_RESULT_HANDLED; } - if (dbus_message_is_method_call (message, "org.freedesktop.DBus.Introspectable", "Introspect")) - { + if (dbus_message_is_method_call (message, "org.freedesktop.DBus.Introspectable", "Introspect")) { return do_introspect (connection, message, local_interface); } @@ -1525,8 +1366,7 @@ listener_dbus_handle_session_message (DBusConnection *connection, static gboolean _listener_message_path_is_our_session (GSListener *listener, - DBusMessage *message) -{ + DBusMessage *message) { const char *ssid; ssid = dbus_message_get_path (message); @@ -1546,8 +1386,7 @@ _listener_message_path_is_our_session (GSListener *listener, #ifdef WITH_SYSTEMD static gboolean properties_changed_match (DBusMessage *message, - const char *property) -{ + const char *property) { DBusMessageIter iter, sub, sub2; /* Checks whether a certain property is listed in the @@ -1617,8 +1456,7 @@ static DBusHandlerResult listener_dbus_handle_system_message (DBusConnection *connection, DBusMessage *message, void *user_data, - dbus_bool_t local_interface) -{ + dbus_bool_t local_interface) { GSListener *listener = GS_LISTENER (user_data); g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); @@ -1634,7 +1472,6 @@ listener_dbus_handle_system_message (DBusConnection *connection, #ifdef WITH_SYSTEMD if (listener->priv->have_systemd) { - if (dbus_message_is_signal (message, SYSTEMD_LOGIND_SESSION_INTERFACE, "Unlock")) { if (_listener_message_path_is_our_session (listener, message)) { gs_debug ("systemd requested session unlock"); @@ -1645,14 +1482,12 @@ listener_dbus_handle_system_message (DBusConnection *connection, } else if (dbus_message_is_signal (message, SYSTEMD_LOGIND_SESSION_INTERFACE, "Lock")) { if (_listener_message_path_is_our_session (listener, message)) { gs_debug ("systemd requested session lock"); - g_signal_emit (listener, signals [LOCK], 0); + g_signal_emit (listener, signals[LOCK], 0); } return DBUS_HANDLER_RESULT_HANDLED; } else if (dbus_message_is_signal (message, DBUS_INTERFACE_PROPERTIES, "PropertiesChanged")) { - if (_listener_message_path_is_our_session (listener, message)) { - if (properties_changed_match (message, "Active")) { gboolean new_active; @@ -1665,7 +1500,7 @@ listener_dbus_handle_system_message (DBusConnection *connection, new_active = sd_session_is_active (listener->priv->session_id) != 0; if (new_active) - g_signal_emit (listener, signals [SIMULATE_USER_ACTIVITY], 0); + g_signal_emit (listener, signals[SIMULATE_USER_ACTIVITY], 0); } } @@ -1678,8 +1513,7 @@ listener_dbus_handle_system_message (DBusConnection *connection, #ifdef WITH_CONSOLE_KIT - if (dbus_message_is_signal (message, HAL_DEVICE_INTERFACE, "Condition")) - { + if (dbus_message_is_signal (message, HAL_DEVICE_INTERFACE, "Condition")) { DBusError error; const char *event; const char *keyname; @@ -1688,47 +1522,34 @@ listener_dbus_handle_system_message (DBusConnection *connection, if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &event, DBUS_TYPE_STRING, &keyname, - DBUS_TYPE_INVALID)) - { + DBUS_TYPE_INVALID)) { if ((event && strcmp (event, "ButtonPressed") == 0) && - (keyname && strcmp (keyname, "coffee") == 0)) - { + (keyname && strcmp (keyname, "coffee") == 0)) { gs_debug ("Coffee key was pressed - locking"); - g_signal_emit (listener, signals [LOCK], 0); + g_signal_emit (listener, signals[LOCK], 0); } } - if (dbus_error_is_set (&error)) - { + if (dbus_error_is_set (&error)) { dbus_error_free (&error); } return DBUS_HANDLER_RESULT_HANDLED; - } - - - else if (dbus_message_is_signal (message, CK_SESSION_INTERFACE, "Unlock")) - { - if (_listener_message_path_is_our_session (listener, message)) - { + } else if (dbus_message_is_signal (message, CK_SESSION_INTERFACE, "Unlock")) { + if (_listener_message_path_is_our_session (listener, message)) { gs_debug ("Console kit requested session unlock"); gs_listener_set_active (listener, FALSE); } return DBUS_HANDLER_RESULT_HANDLED; - } - else if (dbus_message_is_signal (message, CK_SESSION_INTERFACE, "Lock")) - { - if (_listener_message_path_is_our_session (listener, message)) - { + } else if (dbus_message_is_signal (message, CK_SESSION_INTERFACE, "Lock")) { + if (_listener_message_path_is_our_session (listener, message)) { gs_debug ("ConsoleKit requested session lock"); - g_signal_emit (listener, signals [LOCK], 0); + g_signal_emit (listener, signals[LOCK], 0); } return DBUS_HANDLER_RESULT_HANDLED; - } - else if (dbus_message_is_signal (message, CK_SESSION_INTERFACE, "ActiveChanged")) - { + } else if (dbus_message_is_signal (message, CK_SESSION_INTERFACE, "ActiveChanged")) { /* NB that `ActiveChanged' refers to the active * session in ConsoleKit terminology - ie which * session is currently displayed on the screen. @@ -1737,36 +1558,29 @@ listener_dbus_handle_system_message (DBusConnection *connection, * that's not what we're referring to here. */ - if (_listener_message_path_is_our_session (listener, message)) - { + if (_listener_message_path_is_our_session (listener, message)) { DBusError error; dbus_bool_t new_active; dbus_error_init (&error); if (dbus_message_get_args (message, &error, DBUS_TYPE_BOOLEAN, &new_active, - DBUS_TYPE_INVALID)) - { + DBUS_TYPE_INVALID)) { gs_debug ("ConsoleKit notified ActiveChanged %d", new_active); /* when we aren't active add an implicit throttle from CK * when we become active remove the throttle and poke the lock */ - if (new_active) - { - if (listener->priv->ck_throttle_cookie != 0) - { + if (new_active) { + if (listener->priv->ck_throttle_cookie != 0) { listener_remove_ck_ref_entry (listener, REF_ENTRY_TYPE_THROTTLE, listener->priv->ck_throttle_cookie); listener->priv->ck_throttle_cookie = 0; } - g_signal_emit (listener, signals [SIMULATE_USER_ACTIVITY], 0); - } - else - { - if (listener->priv->ck_throttle_cookie != 0) - { + g_signal_emit (listener, signals[SIMULATE_USER_ACTIVITY], 0); + } else { + if (listener->priv->ck_throttle_cookie != 0) { g_warning ("ConsoleKit throttle already set"); listener_remove_ck_ref_entry (listener, REF_ENTRY_TYPE_THROTTLE, @@ -1782,8 +1596,7 @@ listener_dbus_handle_system_message (DBusConnection *connection, } } - if (dbus_error_is_set (&error)) - { + if (dbus_error_is_set (&error)) { dbus_error_free (&error); } } @@ -1797,8 +1610,7 @@ listener_dbus_handle_system_message (DBusConnection *connection, static DBusHandlerResult gs_listener_message_handler (DBusConnection *connection, DBusMessage *message, - void *user_data) -{ + void *user_data) { g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); @@ -1810,53 +1622,42 @@ gs_listener_message_handler (DBusConnection *connection, dbus_message_get_destination (message)); #endif - if (dbus_message_is_method_call (message, "org.freedesktop.DBus", "AddMatch")) - { + if (dbus_message_is_method_call (message, "org.freedesktop.DBus", "AddMatch")) { DBusMessage *reply; reply = dbus_message_new_method_return (message); - if (reply == NULL) - { + if (reply == NULL) { g_error ("No memory"); } - if (! dbus_connection_send (connection, reply, NULL)) - { + if (!dbus_connection_send (connection, reply, NULL)) { g_error ("No memory"); } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; - } - else if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") && - strcmp (dbus_message_get_path (message), DBUS_PATH_LOCAL) == 0) - { + } else if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") && + strcmp (dbus_message_get_path (message), DBUS_PATH_LOCAL) == 0) { dbus_connection_unref (connection); return DBUS_HANDLER_RESULT_HANDLED; - } - else - { + } else { return listener_dbus_handle_session_message (connection, message, user_data, TRUE); } } static gboolean -gs_listener_dbus_init (GSListener *listener) -{ +gs_listener_dbus_init (GSListener *listener) { DBusError error; dbus_error_init (&error); - if (listener->priv->connection == NULL) - { + if (listener->priv->connection == NULL) { listener->priv->connection = dbus_bus_get (DBUS_BUS_SESSION, &error); - if (listener->priv->connection == NULL) - { - if (dbus_error_is_set (&error)) - { + if (listener->priv->connection == NULL) { + if (dbus_error_is_set (&error)) { gs_debug ("couldn't connect to session bus: %s", error.message); dbus_error_free (&error); @@ -1868,13 +1669,10 @@ gs_listener_dbus_init (GSListener *listener) dbus_connection_set_exit_on_disconnect (listener->priv->connection, FALSE); } - if (listener->priv->system_connection == NULL) - { + if (listener->priv->system_connection == NULL) { listener->priv->system_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error); - if (listener->priv->system_connection == NULL) - { - if (dbus_error_is_set (&error)) - { + if (listener->priv->system_connection == NULL) { + if (dbus_error_is_set (&error)) { gs_debug ("couldn't connect to system bus: %s", error.message); dbus_error_free (&error); @@ -1890,8 +1688,7 @@ gs_listener_dbus_init (GSListener *listener) } static gboolean -reinit_dbus (GSListener *listener) -{ +reinit_dbus (GSListener *listener) { gboolean initialized; gboolean try_again; @@ -1910,8 +1707,7 @@ reinit_dbus (GSListener *listener) static DBusHandlerResult listener_dbus_filter_function (DBusConnection *connection, DBusMessage *message, - void *user_data) -{ + void *user_data) { GSListener *listener = GS_LISTENER (user_data); const char *path; @@ -1925,9 +1721,7 @@ listener_dbus_filter_function (DBusConnection *connection, */ if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") - && strcmp (path, DBUS_PATH_LOCAL) == 0) - { - + && strcmp (path, DBUS_PATH_LOCAL) == 0) { g_message ("Got disconnected from the session message bus; " "retrying to reconnect every 10 seconds"); @@ -1935,19 +1729,13 @@ listener_dbus_filter_function (DBusConnection *connection, listener->priv->connection = NULL; g_timeout_add (10000, (GSourceFunc)reinit_dbus, listener); - } - else if (dbus_message_is_signal (message, + } else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, - "NameOwnerChanged")) - { - - if (listener->priv->inhibitors != NULL) - { + "NameOwnerChanged")) { + if (listener->priv->inhibitors != NULL) { listener_service_deleted (listener, message); } - } - else - { + } else { return listener_dbus_handle_session_message (connection, message, user_data, FALSE); } @@ -1957,17 +1745,14 @@ listener_dbus_filter_function (DBusConnection *connection, static DBusHandlerResult listener_dbus_system_filter_function (DBusConnection *connection, DBusMessage *message, - void *user_data) -{ + void *user_data) { GSListener *listener = GS_LISTENER (user_data); const char *path; path = dbus_message_get_path (message); if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") - && strcmp (path, DBUS_PATH_LOCAL) == 0) - { - + && strcmp (path, DBUS_PATH_LOCAL) == 0) { g_message ("Got disconnected from the system message bus; " "retrying to reconnect every 10 seconds"); @@ -1975,9 +1760,7 @@ listener_dbus_system_filter_function (DBusConnection *connection, listener->priv->system_connection = NULL; g_timeout_add (10000, (GSourceFunc)reinit_dbus, listener); - } - else - { + } else { return listener_dbus_handle_system_message (connection, message, user_data, FALSE); } @@ -1988,14 +1771,12 @@ static void gs_listener_set_property (GObject *object, guint prop_id, const GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GSListener *self; self = GS_LISTENER (object); - switch (prop_id) - { + switch (prop_id) { case PROP_ACTIVE: gs_listener_set_active (self, g_value_get_boolean (value)); break; @@ -2015,14 +1796,12 @@ static void gs_listener_get_property (GObject *object, guint prop_id, GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GSListener *self; self = GS_LISTENER (object); - switch (prop_id) - { + switch (prop_id) { case PROP_ACTIVE: g_value_set_boolean (value, self->priv->active); break; @@ -2039,15 +1818,14 @@ gs_listener_get_property (GObject *object, } static void -gs_listener_class_init (GSListenerClass *klass) -{ +gs_listener_class_init (GSListenerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gs_listener_finalize; object_class->get_property = gs_listener_get_property; object_class->set_property = gs_listener_set_property; - signals [LOCK] = + signals[LOCK] = g_signal_new ("lock", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -2057,7 +1835,7 @@ gs_listener_class_init (GSListenerClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - signals [QUIT] = + signals[QUIT] = g_signal_new ("quit", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -2067,7 +1845,7 @@ gs_listener_class_init (GSListenerClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - signals [CYCLE] = + signals[CYCLE] = g_signal_new ("cycle", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -2077,7 +1855,7 @@ gs_listener_class_init (GSListenerClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - signals [SIMULATE_USER_ACTIVITY] = + signals[SIMULATE_USER_ACTIVITY] = g_signal_new ("simulate-user-activity", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -2087,7 +1865,7 @@ gs_listener_class_init (GSListenerClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - signals [ACTIVE_CHANGED] = + signals[ACTIVE_CHANGED] = g_signal_new ("active-changed", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -2098,7 +1876,7 @@ gs_listener_class_init (GSListenerClass *klass) G_TYPE_BOOLEAN, 1, G_TYPE_BOOLEAN); - signals [THROTTLE_CHANGED] = + signals[THROTTLE_CHANGED] = g_signal_new ("throttle-changed", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -2109,7 +1887,7 @@ gs_listener_class_init (GSListenerClass *klass) G_TYPE_NONE, 1, G_TYPE_BOOLEAN); - signals [SHOW_MESSAGE] = + signals[SHOW_MESSAGE] = g_signal_new ("show-message", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -2140,8 +1918,7 @@ gs_listener_class_init (GSListenerClass *klass) } static gboolean -screensaver_is_running (DBusConnection *connection) -{ +screensaver_is_running (DBusConnection *connection) { DBusError error; gboolean exists; @@ -2149,8 +1926,7 @@ screensaver_is_running (DBusConnection *connection) dbus_error_init (&error); exists = dbus_bus_name_has_owner (connection, GS_LISTENER_SERVICE, &error); - if (dbus_error_is_set (&error)) - { + if (dbus_error_is_set (&error)) { dbus_error_free (&error); } @@ -2159,16 +1935,14 @@ screensaver_is_running (DBusConnection *connection) gboolean gs_listener_acquire (GSListener *listener, - GError **error) -{ + GError **error) { int acquired; DBusError buserror; gboolean is_connected; g_return_val_if_fail (listener != NULL, FALSE); - if (! listener->priv->connection) - { + if (!listener->priv->connection) { g_set_error (error, GS_LISTENER_ERROR, GS_LISTENER_ERROR_ACQUISITION_FAILURE, @@ -2178,8 +1952,7 @@ gs_listener_acquire (GSListener *listener, } is_connected = dbus_connection_get_is_connected (listener->priv->connection); - if (! is_connected) - { + if (!is_connected) { g_set_error (error, GS_LISTENER_ERROR, GS_LISTENER_ERROR_ACQUISITION_FAILURE, @@ -2188,8 +1961,7 @@ gs_listener_acquire (GSListener *listener, return FALSE; } - if (screensaver_is_running (listener->priv->connection)) - { + if (screensaver_is_running (listener->priv->connection)) { g_set_error (error, GS_LISTENER_ERROR, GS_LISTENER_ERROR_ACQUISITION_FAILURE, @@ -2203,8 +1975,7 @@ gs_listener_acquire (GSListener *listener, if (dbus_connection_register_object_path (listener->priv->connection, GS_LISTENER_PATH, &gs_listener_vtable, - listener) == FALSE) - { + listener) == FALSE) { g_critical ("out of memory registering object path"); return FALSE; } @@ -2213,8 +1984,7 @@ gs_listener_acquire (GSListener *listener, GS_LISTENER_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &buserror); - if (dbus_error_is_set (&buserror)) - { + if (dbus_error_is_set (&buserror)) { g_set_error (error, GS_LISTENER_ERROR, GS_LISTENER_ERROR_ACQUISITION_FAILURE, @@ -2241,8 +2011,7 @@ gs_listener_acquire (GSListener *listener, ",member='NameOwnerChanged'", NULL); - if (listener->priv->system_connection != NULL) - { + if (listener->priv->system_connection != NULL) { dbus_connection_add_filter (listener->priv->system_connection, listener_dbus_system_filter_function, listener, @@ -2300,16 +2069,14 @@ gs_listener_acquire (GSListener *listener, } static char * -query_session_id (GSListener *listener) -{ +query_session_id (GSListener *listener) { DBusMessage *message; DBusMessage *reply; DBusError error; DBusMessageIter reply_iter; char *ssid; - if (listener->priv->system_connection == NULL) - { + if (listener->priv->system_connection == NULL) { gs_debug ("No connection to the system bus"); return NULL; } @@ -2326,16 +2093,14 @@ query_session_id (GSListener *listener) SYSTEMD_LOGIND_PATH, SYSTEMD_LOGIND_INTERFACE, "GetSessionByPID"); - if (message == NULL) - { + if (message == NULL) { gs_debug ("Couldn't allocate the dbus message"); return NULL; } if (dbus_message_append_args (message, DBUS_TYPE_UINT32, - &pid, DBUS_TYPE_INVALID) == FALSE) - { + &pid, DBUS_TYPE_INVALID) == FALSE) { gs_debug ("Couldn't add args to the dbus message"); return NULL; } @@ -2346,8 +2111,7 @@ query_session_id (GSListener *listener) -1, &error); dbus_message_unref (message); - if (dbus_error_is_set (&error)) - { + if (dbus_error_is_set (&error)) { gs_debug ("%s raised:\n %s\n\n", error.name, error.message); dbus_error_free (&error); return NULL; @@ -2364,8 +2128,7 @@ query_session_id (GSListener *listener) #ifdef WITH_CONSOLE_KIT message = dbus_message_new_method_call (CK_NAME, CK_MANAGER_PATH, CK_MANAGER_INTERFACE, "GetCurrentSession"); - if (message == NULL) - { + if (message == NULL) { gs_debug ("Couldn't allocate the dbus message"); return NULL; } @@ -2376,8 +2139,7 @@ query_session_id (GSListener *listener) -1, &error); dbus_message_unref (message); - if (dbus_error_is_set (&error)) - { + if (dbus_error_is_set (&error)) { gs_debug ("%s raised:\n %s\n\n", error.name, error.message); dbus_error_free (&error); return NULL; @@ -2395,16 +2157,14 @@ query_session_id (GSListener *listener) } static void -init_session_id (GSListener *listener) -{ +init_session_id (GSListener *listener) { g_free (listener->priv->session_id); listener->priv->session_id = query_session_id (listener); gs_debug ("Got session-id: %s", listener->priv->session_id); } static void -gs_listener_init (GSListener *listener) -{ +gs_listener_init (GSListener *listener) { listener->priv = gs_listener_get_instance_private (listener); #ifdef WITH_SYSTEMD @@ -2427,8 +2187,7 @@ gs_listener_init (GSListener *listener) } static void -gs_listener_finalize (GObject *object) -{ +gs_listener_finalize (GObject *object) { GSListener *listener; g_return_if_fail (object != NULL); @@ -2438,13 +2197,11 @@ gs_listener_finalize (GObject *object) g_return_if_fail (listener->priv != NULL); - if (listener->priv->inhibitors) - { + if (listener->priv->inhibitors) { g_hash_table_destroy (listener->priv->inhibitors); } - if (listener->priv->throttlers) - { + if (listener->priv->throttlers) { g_hash_table_destroy (listener->priv->throttlers); } @@ -2454,8 +2211,7 @@ gs_listener_finalize (GObject *object) } GSListener * -gs_listener_new (void) -{ +gs_listener_new (void) { GSListener *listener; listener = g_object_new (GS_TYPE_LISTENER, NULL); diff --git a/src/gs-listener-x11.c b/src/gs-listener-x11.c index 830c07b7df67d209186b853e2722b446ca1f2917..99723d62435f8e6ec983067600be0914e3e3985a 100644 --- a/src/gs-listener-x11.c +++ b/src/gs-listener-x11.c @@ -20,11 +20,12 @@ * */ -#include "config.h" -#include <stdlib.h> +#include <config.h> + #include <stdio.h> -#include <time.h> +#include <stdlib.h> #include <string.h> +#include <time.h> #include <unistd.h> #include <glib/gi18n.h> @@ -35,9 +36,9 @@ #include <X11/extensions/scrnsaver.h> #endif -#include "gs-listener-x11.h" -#include "gs-marshal.h" -#include "gs-debug.h" +#include "src/gs-listener-x11.h" +#include "src/gs-marshal.h" +#include "src/gs-debug.h" static void gs_listener_x11_class_init (GSListenerX11Class *klass); static void gs_listener_x11_init (GSListenerX11 *listener); @@ -46,8 +47,7 @@ static void gs_listener_x11_finalize (GObject *object) static void reset_lock_timer (GSListenerX11 *listener, guint timeout); - struct GSListenerX11Private -{ +struct GSListenerX11Private { #ifdef HAVE_MIT_SAVER_EXTENSION int scrnsaver_event_base; #endif @@ -61,18 +61,17 @@ enum { LAST_SIGNAL }; -static guint signals [LAST_SIGNAL] = { 0, }; +static guint signals[LAST_SIGNAL] = { 0, }; G_DEFINE_TYPE_WITH_PRIVATE (GSListenerX11, gs_listener_x11, G_TYPE_OBJECT) static void -gs_listener_x11_class_init (GSListenerX11Class *klass) -{ +gs_listener_x11_class_init (GSListenerX11Class *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gs_listener_x11_finalize; - signals [LOCK] = + signals[LOCK] = g_signal_new ("lock", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -86,49 +85,45 @@ gs_listener_x11_class_init (GSListenerX11Class *klass) static gboolean get_x11_idle_info (guint *idle_time, - gint *state) -{ + gint *state) { Display *display = gdk_x11_display_get_xdisplay(gdk_display_get_default()); static XScreenSaverInfo *mit_info = NULL; mit_info = XScreenSaverAllocInfo(); XScreenSaverQueryInfo(display, GDK_ROOT_WINDOW(), mit_info); - *idle_time = mit_info->idle / 1000; // seconds + *idle_time = mit_info->idle / 1000; // seconds *state = mit_info->state; return TRUE; } static gboolean -lock_timer (GSListenerX11 *listener) -{ +lock_timer (GSListenerX11 *listener) { guint idle_time; gint state; get_x11_idle_info (&idle_time, &state); - switch (state) - { + switch (state) { case ScreenSaverOff: - gs_debug("Lock Timeout: %is, Idle: %is, Screensaver: Enabled, Lock State: Unlocked", listener->priv->lock_timeout, idle_time); + gs_debug("Lock Timeout: %is, Idle: %is, Screensaver: Enabled, Lock State: Unlocked", + listener->priv->lock_timeout, idle_time); break; case ScreenSaverDisabled: - gs_debug("Lock Timeout: %is, Idle: %is, Screensaver: Disabled, Lock State: Unlocked", listener->priv->lock_timeout, idle_time); + gs_debug("Lock Timeout: %is, Idle: %is, Screensaver: Disabled, Lock State: Unlocked", + listener->priv->lock_timeout, idle_time); break; case ScreenSaverOn: - gs_debug("Lock Timeout: %is, Idle: %is, Screensaver: Enabled, Lock State: Locked", listener->priv->lock_timeout, idle_time); + gs_debug("Lock Timeout: %is, Idle: %is, Screensaver: Enabled, Lock State: Locked", + listener->priv->lock_timeout, idle_time); break; } - if (idle_time >= listener->priv->lock_timeout && state != ScreenSaverDisabled) - { + if (idle_time >= listener->priv->lock_timeout && state != ScreenSaverDisabled) { g_signal_emit(listener, signals[LOCK], 0); - } - else - { - switch (state) - { + } else { + switch (state) { case ScreenSaverOff: // Reset the lock timer reset_lock_timer(listener, listener->priv->lock_timeout - idle_time); @@ -144,17 +139,14 @@ lock_timer (GSListenerX11 *listener) g_signal_emit(listener, signals[LOCK], 0); break; } - } return TRUE; } static void -remove_lock_timer(GSListenerX11 *listener) -{ - if (listener->priv->lock_timer_id != 0) - { +remove_lock_timer(GSListenerX11 *listener) { + if (listener->priv->lock_timer_id != 0) { g_source_remove(listener->priv->lock_timer_id); listener->priv->lock_timer_id = 0; } @@ -162,8 +154,7 @@ remove_lock_timer(GSListenerX11 *listener) static void reset_lock_timer(GSListenerX11 *listener, - guint timeout) -{ + guint timeout) { remove_lock_timer(listener); listener->priv->lock_timer_id = g_timeout_add_seconds(timeout, @@ -174,8 +165,7 @@ reset_lock_timer(GSListenerX11 *listener, static GdkFilterReturn xroot_filter (GdkXEvent *xevent, GdkEvent *event, - gpointer data) -{ + gpointer data) { GSListenerX11 *listener; XEvent *ev; @@ -203,7 +193,7 @@ xroot_filter (GdkXEvent *xevent, case ScreenSaverOn: // lock now! gs_debug("ScreenSaver on"); - g_signal_emit (listener, signals [LOCK], 0); + g_signal_emit (listener, signals[LOCK], 0); break; } } @@ -216,8 +206,7 @@ xroot_filter (GdkXEvent *xevent, gboolean -gs_listener_x11_acquire (GSListenerX11 *listener) -{ +gs_listener_x11_acquire (GSListenerX11 *listener) { GdkDisplay *display; GdkScreen *screen; GdkWindow *window; @@ -234,7 +223,9 @@ gs_listener_x11_acquire (GSListenerX11 *listener) #ifdef HAVE_MIT_SAVER_EXTENSION gdk_x11_display_error_trap_push (display); - if (XScreenSaverQueryExtension (GDK_DISPLAY_XDISPLAY (display), &listener->priv->scrnsaver_event_base, &scrnsaver_error_base)) { + if (XScreenSaverQueryExtension (GDK_DISPLAY_XDISPLAY (display), + &listener->priv->scrnsaver_event_base, + &scrnsaver_error_base)) { events = ScreenSaverNotifyMask; XScreenSaverSelectInput (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), events); gs_debug ("ScreenSaver Registered"); @@ -252,24 +243,21 @@ gs_listener_x11_acquire (GSListenerX11 *listener) void gs_listener_x11_set_lock_after (GSListenerX11 *listener, - gint lock_after) -{ + gint lock_after) { gs_debug ("Lock timeout updated to %i minutes", lock_after); listener->priv->lock_timeout = lock_after * 60; reset_lock_timer(listener, listener->priv->lock_timeout); } static void -gs_listener_x11_init (GSListenerX11 *listener) -{ +gs_listener_x11_init (GSListenerX11 *listener) { listener->priv = gs_listener_x11_get_instance_private (listener); listener->priv->lock_timeout = 300; } static void -gs_listener_x11_finalize (GObject *object) -{ +gs_listener_x11_finalize (GObject *object) { GSListenerX11 *listener; g_return_if_fail (object != NULL); @@ -285,8 +273,7 @@ gs_listener_x11_finalize (GObject *object) } GSListenerX11 * -gs_listener_x11_new (void) -{ +gs_listener_x11_new (void) { GSListenerX11 *listener; listener = g_object_new (GS_TYPE_LISTENER_X11, NULL); diff --git a/src/gs-lock-plug.c b/src/gs-lock-plug.c index 3eb728ce35446b8ea5d721d6bdf2a09c50a3cbd5..58534af838214b92c9c169cbf9db7f6f4087b6ca 100644 --- a/src/gs-lock-plug.c +++ b/src/gs-lock-plug.c @@ -22,47 +22,42 @@ * */ -#include "config.h" +#include <config.h> +#include <errno.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> -#include <errno.h> +#include <sys/utsname.h> #include <time.h> #include <unistd.h> -#include <sys/utsname.h> +#include <gio/gio.h> #include <glib/gprintf.h> #include <glib/gstdio.h> -#include <libxfce4util/libxfce4util.h> #include <gdk/gdkkeysyms.h> #include <gdk/gdkx.h> #include <gtk/gtk.h> #include <gtk/gtkx.h> -#include <gio/gio.h> +#include <libxfce4util/libxfce4util.h> -#include "xfce-desktop-utils.h" +#include "src/gs-lock-plug.h" +#include "src/gs-debug.h" +#include "src/xfce-bg.h" +#include "src/xfce-desktop-utils.h" +#include "src/xfce4-screensaver-dialog-ui.h" #ifdef WITH_KBD_LAYOUT_INDICATOR -#include "xfcekbd-indicator.h" +#include "src/xfcekbd-indicator.h" #endif -#include "gs-lock-plug.h" - -#include "gs-debug.h" -#include "xfce-bg.h" - -#include "xfce4-screensaver-dialog-ui.h" - #define MDM_FLEXISERVER_COMMAND "mdmflexiserver" #define MDM_FLEXISERVER_ARGS "--startnew Standard" #define GDM_FLEXISERVER_COMMAND "gdmflexiserver" #define GDM_FLEXISERVER_ARGS "--startnew Standard" -enum -{ +enum { AUTH_PAGE = 0, }; @@ -72,8 +67,7 @@ enum static void gs_lock_plug_finalize (GObject *object); static void redraw_background (GSLockPlug *plug); -struct GSLockPlugPrivate -{ +struct GSLockPlugPrivate { GtkWidget *vbox; GtkWidget *auth_action_area; @@ -116,21 +110,17 @@ struct GSLockPlugPrivate typedef struct _ResponseData ResponseData; -struct _ResponseData -{ +struct _ResponseData { gint response_id; }; - -enum -{ +enum { RESPONSE, CLOSE, LAST_SIGNAL }; -enum -{ +enum { PROP_0, PROP_LOGOUT_ENABLED, PROP_LOGOUT_COMMAND, @@ -139,25 +129,22 @@ enum PROP_MONITOR_INDEX }; -static guint lock_plug_signals [LAST_SIGNAL] = { 0 }; +static guint lock_plug_signals[LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE_WITH_PRIVATE (GSLockPlug, gs_lock_plug, GTK_TYPE_PLUG) static void gs_lock_plug_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ + GtkStyle *previous_style) { GSLockPlug *plug; - if (GTK_WIDGET_CLASS (gs_lock_plug_parent_class)->style_set) - { + if (GTK_WIDGET_CLASS (gs_lock_plug_parent_class)->style_set) { GTK_WIDGET_CLASS (gs_lock_plug_parent_class)->style_set (widget, previous_style); } plug = GS_LOCK_PLUG (widget); - if (! plug->priv->vbox) - { + if (!plug->priv->vbox) { return; } @@ -169,8 +156,7 @@ gs_lock_plug_style_set (GtkWidget *widget, } static gboolean -process_is_running (const char * name) -{ +process_is_running (const char * name) { int num_processes; gchar *command = g_strdup_printf ("pidof %s | wc -l", name); FILE *fp = popen(command, "r"); @@ -182,21 +168,19 @@ process_is_running (const char * name) g_free (command); if (num_processes > 0) { - return TRUE; + return TRUE; } else { - return FALSE; + return FALSE; } } static void -do_user_switch (GSLockPlug *plug) -{ +do_user_switch (GSLockPlug *plug) { GError *error; gboolean res; char *command; - if (process_is_running ("mdm")) - { + if (process_is_running ("mdm")) { /* MDM */ command = g_strdup_printf ("%s %s", MDM_FLEXISERVER_COMMAND, @@ -209,14 +193,11 @@ do_user_switch (GSLockPlug *plug) g_free (command); - if (! res) - { + if (!res) { gs_debug ("Unable to start MDM greeter: %s", error->message); g_error_free (error); } - } - else if (process_is_running ("gdm") || process_is_running("gdm3") || process_is_running("gdm-binary")) - { + } else if (process_is_running ("gdm") || process_is_running("gdm3") || process_is_running("gdm-binary")) { /* GDM */ command = g_strdup_printf ("%s %s", GDM_FLEXISERVER_COMMAND, @@ -229,13 +210,11 @@ do_user_switch (GSLockPlug *plug) g_free (command); - if (! res) { + if (!res) { gs_debug ("Unable to start GDM greeter: %s", error->message); g_error_free (error); } - } - else if (g_getenv ("XDG_SEAT_PATH") != NULL) - { + } else if (g_getenv ("XDG_SEAT_PATH") != NULL) { /* LightDM */ GDBusProxyFlags flags = G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START; GDBusProxy *proxy = NULL; @@ -258,21 +237,17 @@ do_user_switch (GSLockPlug *plug) NULL, NULL); g_object_unref (proxy); - } - else { + } else { gs_debug ("Unable to start LightDM greeter: %s", error->message); g_error_free (error); } } - } static void set_status_text (GSLockPlug *plug, - const char *text) -{ - if (plug->priv->auth_message_label != NULL) - { + const char *text) { + if (plug->priv->auth_message_label != NULL) { gtk_label_set_text (GTK_LABEL (plug->priv->auth_message_label), text); if (g_utf8_strlen (text, 1) == 0) { gtk_widget_hide (GTK_WIDGET (plug->priv->auth_message_label)); @@ -283,8 +258,7 @@ set_status_text (GSLockPlug *plug, } static void -date_time_update (GSLockPlug *plug) -{ +date_time_update (GSLockPlug *plug) { GDateTime *datetime; gchar *datetime_format; gchar *str; @@ -302,8 +276,7 @@ date_time_update (GSLockPlug *plug) void gs_lock_plug_set_sensitive (GSLockPlug *plug, - gboolean sensitive) -{ + gboolean sensitive) { g_return_if_fail (GS_IS_LOCK_PLUG (plug)); gtk_widget_set_sensitive (plug->priv->auth_prompt_entry, sensitive); @@ -311,30 +284,24 @@ gs_lock_plug_set_sensitive (GSLockPlug *plug, } static void -remove_datetime_timeout (GSLockPlug *plug) -{ - if (plug->priv->datetime_timeout_id > 0) - { +remove_datetime_timeout (GSLockPlug *plug) { + if (plug->priv->datetime_timeout_id > 0) { g_source_remove (plug->priv->datetime_timeout_id); plug->priv->datetime_timeout_id = 0; } } static void -remove_cancel_timeout (GSLockPlug *plug) -{ - if (plug->priv->cancel_timeout_id > 0) - { +remove_cancel_timeout (GSLockPlug *plug) { + if (plug->priv->cancel_timeout_id > 0) { g_source_remove (plug->priv->cancel_timeout_id); plug->priv->cancel_timeout_id = 0; } } static void -remove_response_idle (GSLockPlug *plug) -{ - if (plug->priv->response_idle_id > 0) - { +remove_response_idle (GSLockPlug *plug) { + if (plug->priv->response_idle_id > 0) { g_source_remove (plug->priv->response_idle_id); plug->priv->response_idle_id = 0; } @@ -342,8 +309,7 @@ remove_response_idle (GSLockPlug *plug) static void gs_lock_plug_response (GSLockPlug *plug, - gint response_id) -{ + gint response_id) { int new_response; new_response = response_id; @@ -352,28 +318,25 @@ gs_lock_plug_response (GSLockPlug *plug, /* Act only on response IDs we recognize */ if (!(response_id == GS_LOCK_PLUG_RESPONSE_OK - || response_id == GS_LOCK_PLUG_RESPONSE_CANCEL)) - { + || response_id == GS_LOCK_PLUG_RESPONSE_CANCEL)) { return; } remove_cancel_timeout (plug); remove_response_idle (plug); - if (response_id == GS_LOCK_PLUG_RESPONSE_CANCEL) - { + if (response_id == GS_LOCK_PLUG_RESPONSE_CANCEL) { gtk_entry_set_text (GTK_ENTRY (plug->priv->auth_prompt_entry), ""); } g_signal_emit (plug, - lock_plug_signals [RESPONSE], + lock_plug_signals[RESPONSE], 0, new_response); } static gboolean -response_cancel_idle_cb (GSLockPlug *plug) -{ +response_cancel_idle_cb (GSLockPlug *plug) { plug->priv->response_idle_id = 0; gs_lock_plug_response (plug, GS_LOCK_PLUG_RESPONSE_CANCEL); @@ -382,13 +345,11 @@ response_cancel_idle_cb (GSLockPlug *plug) } static gboolean -dialog_timed_out (GSLockPlug *plug) -{ +dialog_timed_out (GSLockPlug *plug) { gs_lock_plug_set_sensitive (plug, FALSE); set_status_text (plug, _("Time has expired.")); - if (plug->priv->response_idle_id != 0) - { + if (plug->priv->response_idle_id != 0) { g_warning ("Response idle ID already set but shouldn't be"); } @@ -403,29 +364,22 @@ dialog_timed_out (GSLockPlug *plug) static void capslock_update (GSLockPlug *plug, - gboolean is_on) -{ - + gboolean is_on) { plug->priv->caps_lock_on = is_on; - if (plug->priv->auth_capslock_label == NULL) - { + if (plug->priv->auth_capslock_label == NULL) { return; } - if (is_on) - { + if (is_on) { gtk_widget_show (GTK_WIDGET (plug->priv->auth_capslock_label)); - } - else - { + } else { gtk_widget_hide (GTK_WIDGET (plug->priv->auth_capslock_label)); } } static gboolean -is_capslock_on (void) -{ +is_capslock_on (void) { GdkKeymap *keymap; gboolean res; @@ -440,8 +394,7 @@ is_capslock_on (void) } static void -restart_cancel_timeout (GSLockPlug *plug) -{ +restart_cancel_timeout (GSLockPlug *plug) { remove_cancel_timeout (plug); plug->priv->cancel_timeout_id = g_timeout_add (plug->priv->timeout, @@ -451,8 +404,7 @@ restart_cancel_timeout (GSLockPlug *plug) void gs_lock_plug_get_text (GSLockPlug *plug, - char **text) -{ + char **text) { const char *typed_text; char *null_text; char *local_text; @@ -465,18 +417,14 @@ gs_lock_plug_get_text (GSLockPlug *plug, gtk_entry_set_text (GTK_ENTRY (plug->priv->auth_prompt_entry), ""); g_free (null_text); - if (text != NULL) - { + if (text != NULL) { *text = local_text; - } - else - { + } else { g_free (local_text); } } -typedef struct -{ +typedef struct { GSLockPlug *plug; gint response_id; GMainLoop *loop; @@ -484,16 +432,14 @@ typedef struct } RunInfo; static void -shutdown_loop (RunInfo *ri) -{ +shutdown_loop (RunInfo *ri) { if (g_main_loop_is_running (ri->loop)) g_main_loop_quit (ri->loop); } static void run_unmap_handler (GSLockPlug *plug, - gpointer data) -{ + gpointer data) { RunInfo *ri = data; shutdown_loop (ri); @@ -502,8 +448,7 @@ run_unmap_handler (GSLockPlug *plug, static void run_response_handler (GSLockPlug *plug, gint response_id, - gpointer data) -{ + gpointer data) { RunInfo *ri; ri = data; @@ -516,8 +461,7 @@ run_response_handler (GSLockPlug *plug, static gint run_delete_handler (GSLockPlug *plug, GdkEventAny *event, - gpointer data) -{ + gpointer data) { RunInfo *ri = data; shutdown_loop (ri); @@ -527,8 +471,7 @@ run_delete_handler (GSLockPlug *plug, static void run_destroy_handler (GSLockPlug *plug, - gpointer data) -{ + gpointer data) { RunInfo *ri = data; /* shutdown_loop will be called by run_unmap_handler */ @@ -537,15 +480,13 @@ run_destroy_handler (GSLockPlug *plug, static void run_keymap_handler (GdkKeymap *keymap, - GSLockPlug *plug) -{ + GSLockPlug *plug) { capslock_update (plug, is_capslock_on ()); } /* adapted from GTK+ gtkdialog.c */ int -gs_lock_plug_run (GSLockPlug *plug) -{ +gs_lock_plug_run (GSLockPlug *plug) { RunInfo ri = { NULL, GTK_RESPONSE_NONE, NULL, FALSE }; gboolean was_modal; gulong response_handler; @@ -560,13 +501,11 @@ gs_lock_plug_run (GSLockPlug *plug) g_object_ref (plug); was_modal = gtk_window_get_modal (GTK_WINDOW (plug)); - if (!was_modal) - { + if (!was_modal) { gtk_window_set_modal (GTK_WINDOW (plug), TRUE); } - if (!gtk_widget_get_visible (GTK_WIDGET (plug))) - { + if (!gtk_widget_get_visible (GTK_WIDGET (plug))) { gtk_widget_show (GTK_WIDGET (plug)); } @@ -610,10 +549,8 @@ gs_lock_plug_run (GSLockPlug *plug) ri.loop = NULL; - if (!ri.destroyed) - { - if (!was_modal) - { + if (!ri.destroyed) { + if (!was_modal) { gtk_window_set_modal (GTK_WINDOW (plug), FALSE); } @@ -630,8 +567,7 @@ gs_lock_plug_run (GSLockPlug *plug) } static gboolean -set_face_image (GSLockPlug *plug) -{ +set_face_image (GSLockPlug *plug) { GdkPixbuf *pixbuf = NULL; const char *homedir; char *path; @@ -644,8 +580,7 @@ set_face_image (GSLockPlug *plug) g_free (path); - if (pixbuf == NULL) - { + if (pixbuf == NULL) { g_warning ("Could not load the user avatar: %s", error->message); g_error_free (error); return FALSE; @@ -661,8 +596,7 @@ set_face_image (GSLockPlug *plug) static void gs_lock_plug_get_preferred_width (GtkWidget *widget, gint *minimum_width, - gint *natural_width) -{ + gint *natural_width) { gint scale; GTK_WIDGET_CLASS (gs_lock_plug_parent_class)->get_preferred_width (widget, minimum_width, natural_width); @@ -676,11 +610,13 @@ static void gs_lock_plug_get_preferred_height_for_width (GtkWidget *widget, gint width, gint *minimum_height, - gint *natural_height) -{ + gint *natural_height) { gint scale; - GTK_WIDGET_CLASS (gs_lock_plug_parent_class)->get_preferred_height_for_width (widget, width, minimum_height, natural_height); + GTK_WIDGET_CLASS (gs_lock_plug_parent_class)->get_preferred_height_for_width (widget, + width, + minimum_height, + natural_height); scale = gtk_widget_get_scale_factor (widget); *minimum_height /= scale; @@ -689,23 +625,19 @@ gs_lock_plug_get_preferred_height_for_width (GtkWidget *widget, #endif static void -gs_lock_plug_show (GtkWidget *widget) -{ +gs_lock_plug_show (GtkWidget *widget) { GSLockPlug *plug = GS_LOCK_PLUG (widget); gs_profile_start (NULL); gs_profile_start ("parent"); - if (GTK_WIDGET_CLASS (gs_lock_plug_parent_class)->show) - { + if (GTK_WIDGET_CLASS (gs_lock_plug_parent_class)->show) { GTK_WIDGET_CLASS (gs_lock_plug_parent_class)->show (widget); } gs_profile_end ("parent"); - - if (plug->priv->auth_face_image) - { + if (plug->priv->auth_face_image) { set_face_image (plug); } @@ -717,18 +649,15 @@ gs_lock_plug_show (GtkWidget *widget) } static void -gs_lock_plug_hide (GtkWidget *widget) -{ - if (GTK_WIDGET_CLASS (gs_lock_plug_parent_class)->hide) - { +gs_lock_plug_hide (GtkWidget *widget) { + if (GTK_WIDGET_CLASS (gs_lock_plug_parent_class)->hide) { GTK_WIDGET_CLASS (gs_lock_plug_parent_class)->hide (widget); } } static void queue_key_event (GSLockPlug *plug, - GdkEventKey *event) -{ + GdkEventKey *event) { GdkEvent *saved_event; saved_event = gdk_event_copy ((GdkEvent *)event); @@ -737,11 +666,9 @@ queue_key_event (GSLockPlug *plug, } static void -forward_key_events (GSLockPlug *plug) -{ +forward_key_events (GSLockPlug *plug) { plug->priv->key_events = g_list_reverse (plug->priv->key_events); - while (plug->priv->key_events != NULL) - { + while (plug->priv->key_events != NULL) { GdkEventKey *event = plug->priv->key_events->data; gtk_window_propagate_key_event (GTK_WINDOW (plug), event); @@ -755,41 +682,33 @@ forward_key_events (GSLockPlug *plug) static void gs_lock_plug_set_logout_enabled (GSLockPlug *plug, - gboolean logout_enabled) -{ + gboolean logout_enabled) { g_return_if_fail (GS_LOCK_PLUG (plug)); - if (plug->priv->logout_enabled == logout_enabled) - { + if (plug->priv->logout_enabled == logout_enabled) { return; } plug->priv->logout_enabled = logout_enabled; g_object_notify (G_OBJECT (plug), "logout-enabled"); - if (plug->priv->auth_logout_button == NULL) - { + if (plug->priv->auth_logout_button == NULL) { return; } - if (logout_enabled) - { + if (logout_enabled) { gtk_widget_show (plug->priv->auth_logout_button); - } - else - { + } else { gtk_widget_hide (plug->priv->auth_logout_button); } } static void gs_lock_plug_set_monitor_index (GSLockPlug *plug, - gint monitor_index) -{ + gint monitor_index) { g_return_if_fail (GS_LOCK_PLUG (plug)); - if (plug->priv->monitor_index == monitor_index) - { + if (plug->priv->monitor_index == monitor_index) { return; } @@ -801,41 +720,32 @@ gs_lock_plug_set_monitor_index (GSLockPlug *plug, static void gs_lock_plug_set_logout_command (GSLockPlug *plug, - const char *command) -{ + const char *command) { g_return_if_fail (GS_LOCK_PLUG (plug)); g_free (plug->priv->logout_command); - if (command) - { + if (command) { plug->priv->logout_command = g_strdup (command); - } - else - { + } else { plug->priv->logout_command = NULL; } } static void gs_lock_plug_set_status_message (GSLockPlug *plug, - const char *status_message) -{ + const char *status_message) { g_return_if_fail (GS_LOCK_PLUG (plug)); g_free (plug->priv->status_message); plug->priv->status_message = g_strdup (status_message); - if (plug->priv->status_message_label) - { - if (plug->priv->status_message) - { + if (plug->priv->status_message_label) { + if (plug->priv->status_message) { gtk_label_set_text (GTK_LABEL (plug->priv->status_message_label), plug->priv->status_message); gtk_widget_show (plug->priv->status_message_label); - } - else - { + } else { gtk_widget_hide (plug->priv->status_message_label); } } @@ -845,14 +755,12 @@ static void gs_lock_plug_get_property (GObject *object, guint prop_id, GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GSLockPlug *self; self = GS_LOCK_PLUG (object); - switch (prop_id) - { + switch (prop_id) { case PROP_LOGOUT_ENABLED: g_value_set_boolean (value, self->priv->logout_enabled); break; @@ -876,48 +784,35 @@ gs_lock_plug_get_property (GObject *object, static void gs_lock_plug_set_switch_enabled (GSLockPlug *plug, - gboolean switch_enabled) -{ + gboolean switch_enabled) { g_return_if_fail (GS_LOCK_PLUG (plug)); - if (plug->priv->switch_enabled == switch_enabled) - { + if (plug->priv->switch_enabled == switch_enabled) { return; } plug->priv->switch_enabled = switch_enabled; g_object_notify (G_OBJECT (plug), "switch-enabled"); - if (plug->priv->auth_switch_button == NULL) - { + if (plug->priv->auth_switch_button == NULL) { return; } - if (switch_enabled) - { - if (process_is_running ("mdm")) - { + if (switch_enabled) { + if (process_is_running ("mdm")) { /* MDM */ gtk_widget_show (plug->priv->auth_switch_button); - } - else if (process_is_running ("gdm") || process_is_running("gdm3") || process_is_running("gdm-binary")) - { + } else if (process_is_running ("gdm") || process_is_running("gdm3") || process_is_running("gdm-binary")) { /* GDM */ gtk_widget_show (plug->priv->auth_switch_button); - } - else if (g_getenv ("XDG_SEAT_PATH") != NULL) - { + } else if (g_getenv ("XDG_SEAT_PATH") != NULL) { /* LightDM */ gtk_widget_show (plug->priv->auth_switch_button); - } - else - { + } else { gs_debug ("Warning: Unknown DM for switch button"); gtk_widget_hide (plug->priv->auth_switch_button); } - } - else - { + } else { gtk_widget_hide (plug->priv->auth_switch_button); } } @@ -926,14 +821,12 @@ static void gs_lock_plug_set_property (GObject *object, guint prop_id, const GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GSLockPlug *self; self = GS_LOCK_PLUG (object); - switch (prop_id) - { + switch (prop_id) { case PROP_LOGOUT_ENABLED: gs_lock_plug_set_logout_enabled (self, g_value_get_boolean (value)); break; @@ -956,8 +849,7 @@ gs_lock_plug_set_property (GObject *object, } static void -gs_lock_plug_close (GSLockPlug *plug) -{ +gs_lock_plug_close (GSLockPlug *plug) { /* Synthesize delete_event to close dialog. */ GtkWidget *widget = GTK_WIDGET (plug); @@ -972,8 +864,7 @@ gs_lock_plug_close (GSLockPlug *plug) } static void -gs_lock_plug_class_init (GSLockPlugClass *klass) -{ +gs_lock_plug_class_init (GSLockPlugClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); GtkBindingSet *binding_set; @@ -992,21 +883,21 @@ gs_lock_plug_class_init (GSLockPlugClass *klass) klass->close = gs_lock_plug_close; - lock_plug_signals [RESPONSE] = g_signal_new ("response", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GSLockPlugClass, response), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, - G_TYPE_INT); - lock_plug_signals [CLOSE] = g_signal_new ("close", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GSLockPlugClass, close), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); + lock_plug_signals[RESPONSE] = g_signal_new ("response", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GSLockPlugClass, response), + NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, 1, + G_TYPE_INT); + lock_plug_signals[CLOSE] = g_signal_new ("close", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (GSLockPlugClass, close), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); g_object_class_install_property (object_class, PROP_LOGOUT_ENABLED, @@ -1053,8 +944,7 @@ gs_lock_plug_class_init (GSLockPlugClass *klass) } static void -clear_clipboards (GSLockPlug *plug) -{ +clear_clipboards (GSLockPlug *plug) { GtkClipboard *clipboard; clipboard = gtk_widget_get_clipboard (GTK_WIDGET (plug), GDK_SELECTION_PRIMARY); @@ -1067,21 +957,18 @@ clear_clipboards (GSLockPlug *plug) static void logout_button_clicked (GtkButton *button, - GSLockPlug *plug) -{ + GSLockPlug *plug) { char **argv = NULL; GError *error = NULL; gboolean res; - if (! plug->priv->logout_command) - { + if (!plug->priv->logout_command) { return; } res = g_shell_parse_argv (plug->priv->logout_command, NULL, &argv, &error); - if (! res) - { + if (!res) { g_warning ("Could not parse logout command: %s", error->message); g_error_free (error); return; @@ -1098,16 +985,14 @@ logout_button_clicked (GtkButton *button, g_strfreev (argv); - if (error) - { + if (error) { g_warning ("Could not run logout command: %s", error->message); g_error_free (error); } } void -gs_lock_plug_set_busy (GSLockPlug *plug) -{ +gs_lock_plug_set_busy (GSLockPlug *plug) { GdkDisplay *display; GdkCursor *cursor; GtkWidget *top_level; @@ -1122,8 +1007,7 @@ gs_lock_plug_set_busy (GSLockPlug *plug) } void -gs_lock_plug_set_ready (GSLockPlug *plug) -{ +gs_lock_plug_set_ready (GSLockPlug *plug) { GdkDisplay *display; GdkCursor *cursor; GtkWidget *top_level; @@ -1139,8 +1023,7 @@ gs_lock_plug_set_ready (GSLockPlug *plug) void gs_lock_plug_enable_prompt (GSLockPlug *plug, const char *message, - gboolean visible) -{ + gboolean visible) { g_return_if_fail (GS_IS_LOCK_PLUG (plug)); gs_debug ("Setting prompt to: %s", message); @@ -1160,8 +1043,7 @@ gs_lock_plug_enable_prompt (GSLockPlug *plug, gtk_widget_set_sensitive (plug->priv->auth_prompt_entry, TRUE); gtk_widget_show (plug->priv->auth_prompt_entry); - if (! gtk_widget_has_focus (plug->priv->auth_prompt_entry)) - { + if (!gtk_widget_has_focus (plug->priv->auth_prompt_entry)) { gtk_widget_grab_focus (plug->priv->auth_prompt_entry); } @@ -1174,8 +1056,7 @@ gs_lock_plug_enable_prompt (GSLockPlug *plug, } void -gs_lock_plug_disable_prompt (GSLockPlug *plug) -{ +gs_lock_plug_disable_prompt (GSLockPlug *plug) { g_return_if_fail (GS_IS_LOCK_PLUG (plug)); /* gtk_widget_hide (plug->priv->auth_prompt_entry); */ @@ -1189,8 +1070,7 @@ gs_lock_plug_disable_prompt (GSLockPlug *plug) void gs_lock_plug_show_message (GSLockPlug *plug, - const char *message) -{ + const char *message) { g_return_if_fail (GS_IS_LOCK_PLUG (plug)); set_status_text (plug, message ? message : ""); @@ -1199,10 +1079,8 @@ gs_lock_plug_show_message (GSLockPlug *plug, /* button press handler used to inhibit popup menu */ static gint entry_button_press (GtkWidget *widget, - GdkEventButton *event) -{ - if (event->button == 3 && event->type == GDK_BUTTON_PRESS) - { + GdkEventButton *event) { + if (event->button == 3 && event->type == GDK_BUTTON_PRESS) { return TRUE; } @@ -1212,21 +1090,18 @@ entry_button_press (GtkWidget *widget, static gint entry_key_press (GtkWidget *widget, GdkEventKey *event, - GSLockPlug *plug) -{ + GSLockPlug *plug) { restart_cancel_timeout (plug); /* if the input widget is visible and ready for input * then just carry on as usual */ if (gtk_widget_get_visible (plug->priv->auth_prompt_entry) && - gtk_widget_is_sensitive (plug->priv->auth_prompt_entry)) - { + gtk_widget_is_sensitive (plug->priv->auth_prompt_entry)) { return FALSE; } - if (strcmp (event->string, "") == 0) - { + if (strcmp (event->string, "") == 0) { return FALSE; } @@ -1239,8 +1114,7 @@ entry_key_press (GtkWidget *widget, static GtkWidget * gs_lock_plug_add_button (GSLockPlug *plug, GtkWidget *action_area, - const gchar *button_text) -{ + const gchar *button_text) { GtkWidget *button; g_return_val_if_fail (GS_IS_LOCK_PLUG (plug), NULL); @@ -1260,23 +1134,20 @@ gs_lock_plug_add_button (GSLockPlug *plug, } static char * -get_user_display_name (void) -{ +get_user_display_name (void) { const char *name; char *utf8_name; name = g_get_real_name (); if (name == NULL || g_strcmp0 (name, "") == 0 || - g_strcmp0 (name, "Unknown") == 0) - { + g_strcmp0 (name, "Unknown") == 0) { name = g_get_user_name (); } utf8_name = NULL; - if (name != NULL) - { + if (name != NULL) { utf8_name = g_locale_to_utf8 (name, -1, NULL, NULL, NULL); } @@ -1284,16 +1155,14 @@ get_user_display_name (void) } static char * -get_user_name (void) -{ +get_user_name (void) { const char *name; char *utf8_name; name = g_get_user_name (); utf8_name = NULL; - if (name != NULL) - { + if (name != NULL) { utf8_name = g_locale_to_utf8 (name, -1, NULL, NULL, NULL); } @@ -1301,8 +1170,7 @@ get_user_name (void) } static void -create_page_one_buttons (GSLockPlug *plug) -{ +create_page_one_buttons (GSLockPlug *plug) { gs_profile_start ("page one buttons"); plug->priv->auth_switch_button = gs_lock_plug_add_button (GS_LOCK_PLUG (plug), @@ -1337,8 +1205,7 @@ create_page_one_buttons (GSLockPlug *plug) /* adapted from MDM */ static char * -expand_string (const char *text) -{ +expand_string (const char *text) { GString *str; const char *p; char *username; @@ -1352,47 +1219,36 @@ expand_string (const char *text) n_chars = g_utf8_strlen (text, -1); i = 0; - while (i < n_chars) - { + while (i < n_chars) { gunichar ch; ch = g_utf8_get_char (p); /* Backslash commands */ - if (ch == '\\') - { + if (ch == '\\') { p = g_utf8_next_char (p); i++; ch = g_utf8_get_char (p); - if (i >= n_chars || ch == '\0') - { + if (i >= n_chars || ch == '\0') { g_warning ("Unescaped \\ at end of text\n"); goto bail; - } - else if (ch == 'n') - { + } else if (ch == 'n') { g_string_append_unichar (str, '\n'); - } - else - { + } else { g_string_append_unichar (str, ch); } - } - else if (ch == '%') - { + } else if (ch == '%') { p = g_utf8_next_char (p); i++; ch = g_utf8_get_char (p); - if (i >= n_chars || ch == '\0') - { + if (i >= n_chars || ch == '\0') { g_warning ("Unescaped %% at end of text\n"); goto bail; } - switch (ch) - { + switch (ch) { case '%': g_string_append (str, "%"); break; @@ -1440,18 +1296,13 @@ expand_string (const char *text) g_free (username); break; default: - if (ch < 127) - { + if (ch < 127) { g_warning ("unknown escape code %%%c in text\n", (char)ch); - } - else - { + } else { g_warning ("unknown escape code %%(U%x) in text\n", (int)ch); } } - } - else - { + } else { g_string_append_unichar (str, ch); } p = g_utf8_next_char (p); @@ -1464,8 +1315,7 @@ bail: } static void -expand_string_for_label (GtkWidget *label) -{ +expand_string_for_label (GtkWidget *label) { const char *template; char *str; @@ -1476,8 +1326,7 @@ expand_string_for_label (GtkWidget *label) } static void -create_page_one (GSLockPlug *plug) -{ +create_page_one (GSLockPlug *plug) { GtkWidget *vbox; GtkWidget *vbox2; GtkWidget *hbox; @@ -1558,22 +1407,19 @@ create_page_one (GSLockPlug *plug) static void unlock_button_clicked (GtkButton *button, - GSLockPlug *plug) -{ + GSLockPlug *plug) { gs_lock_plug_response (plug, GS_LOCK_PLUG_RESPONSE_OK); } static void cancel_button_clicked (GtkButton *button, - GSLockPlug *plug) -{ + GSLockPlug *plug) { gs_lock_plug_response (plug, GS_LOCK_PLUG_RESPONSE_CANCEL); } static void switch_user_button_clicked (GtkButton *button, - GSLockPlug *plug) -{ + GSLockPlug *plug) { remove_response_idle (plug); gs_lock_plug_set_sensitive (plug, FALSE); @@ -1592,8 +1438,7 @@ get_draw_dimensions(GSLockPlug *plug, gint *screen_width, gint *screen_height, gint *monitor_width, - gint *monitor_height) -{ + gint *monitor_height) { GdkWindow *window; GdkDisplay *display; GdkScreen *screen; @@ -1611,8 +1456,7 @@ get_draw_dimensions(GSLockPlug *plug, scale = gdk_window_get_scale_factor(gdk_screen_get_root_window(screen)); monitor = gdk_display_get_monitor (display, plug->priv->monitor_index); - if (!monitor) - { + if (!monitor) { if (window != NULL) monitor = gdk_display_get_monitor_at_window(display, window); else @@ -1632,8 +1476,7 @@ get_draw_dimensions(GSLockPlug *plug, } static void -redraw_background (GSLockPlug *plug) -{ +redraw_background (GSLockPlug *plug) { XfceBG *bg; GdkPixbuf *pixbuf; gint screen_width, screen_height, monitor_width, monitor_height; @@ -1645,18 +1488,16 @@ redraw_background (GSLockPlug *plug) } static gboolean -load_theme (GSLockPlug *plug) -{ +load_theme (GSLockPlug *plug) { GtkBuilder *builder; GtkWidget *lock_overlay; GtkWidget *lock_panel; GtkWidget *lock_dialog; - GError *error=NULL; + GError *error = NULL; builder = gtk_builder_new(); if (!gtk_builder_add_from_string (builder, xfce4_screensaver_dialog_ui, - xfce4_screensaver_dialog_ui_length, &error)) - { + xfce4_screensaver_dialog_ui_length, &error)) { g_warning ("Error loading UI: %s", error->message); g_error_free(error); return FALSE; @@ -1695,13 +1536,12 @@ load_theme (GSLockPlug *plug) plug->priv->background_image = GTK_WIDGET (gtk_builder_get_object(builder, "lock-image")); /* Placeholder for the keyboard indicator */ - plug->priv->auth_prompt_kbd_layout_indicator = GTK_WIDGET (gtk_builder_get_object(builder, "auth-prompt-kbd-layout-indicator")); - if (plug->priv->auth_logout_button != NULL) - { + plug->priv->auth_prompt_kbd_layout_indicator = GTK_WIDGET ( + gtk_builder_get_object(builder, "auth-prompt-kbd-layout-indicator")); + if (plug->priv->auth_logout_button != NULL) { gtk_widget_set_no_show_all (plug->priv->auth_logout_button, TRUE); } - if (plug->priv->auth_switch_button != NULL) - { + if (plug->priv->auth_switch_button != NULL) { gtk_widget_set_no_show_all (plug->priv->auth_switch_button, TRUE); } @@ -1718,16 +1558,14 @@ load_theme (GSLockPlug *plug) static int delete_handler (GSLockPlug *plug, GdkEventAny *event, - gpointer data) -{ + gpointer data) { gs_lock_plug_response (plug, GS_LOCK_PLUG_RESPONSE_CANCEL); return TRUE; /* Do not destroy */ } static void -gs_lock_plug_init (GSLockPlug *plug) -{ +gs_lock_plug_init (GSLockPlug *plug) { gs_profile_start (NULL); plug->priv = gs_lock_plug_get_instance_private (plug); @@ -1739,8 +1577,7 @@ gs_lock_plug_init (GSLockPlug *plug) context = gtk_widget_get_style_context (GTK_WIDGET (plug)); gtk_style_context_add_class (context, "lock-dialog"); - if (!load_theme (plug)) - { + if (!load_theme (plug)) { gs_debug ("Unable to load theme!"); plug->priv->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); @@ -1757,13 +1594,11 @@ gs_lock_plug_init (GSLockPlug *plug) /* Layout indicator */ #ifdef WITH_KBD_LAYOUT_INDICATOR - if (plug->priv->auth_prompt_kbd_layout_indicator != NULL) - { + if (plug->priv->auth_prompt_kbd_layout_indicator != NULL) { XklEngine *engine; engine = xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ())); - if (xkl_engine_get_num_groups (engine) > 1) - { + if (xkl_engine_get_num_groups (engine) > 1) { GtkWidget *layout_indicator; layout_indicator = xfcekbd_indicator_new (); @@ -1776,9 +1611,7 @@ gs_lock_plug_init (GSLockPlug *plug) gtk_widget_show_all (layout_indicator); gtk_widget_show (plug->priv->auth_prompt_kbd_layout_indicator); - } - else - { + } else { gtk_widget_hide (plug->priv->auth_prompt_kbd_layout_indicator); } @@ -1786,34 +1619,26 @@ gs_lock_plug_init (GSLockPlug *plug) } #endif - if (plug->priv->auth_switch_button != NULL) - { - if (plug->priv->switch_enabled) - { + if (plug->priv->auth_switch_button != NULL) { + if (plug->priv->switch_enabled) { gtk_widget_show_all (plug->priv->auth_switch_button); - } - else - { + } else { gtk_widget_hide (plug->priv->auth_switch_button); } } gtk_widget_grab_default (plug->priv->auth_unlock_button); - if (plug->priv->auth_username_label != NULL) - { + if (plug->priv->auth_username_label != NULL) { expand_string_for_label (plug->priv->auth_username_label); } - if (plug->priv->auth_realname_label != NULL) - { + if (plug->priv->auth_realname_label != NULL) { expand_string_for_label (plug->priv->auth_realname_label); } - if (! plug->priv->logout_enabled || ! plug->priv->logout_command) - { - if (plug->priv->auth_logout_button != NULL) - { + if (!plug->priv->logout_enabled || !plug->priv->logout_command) { + if (plug->priv->auth_logout_button != NULL) { gtk_widget_hide (plug->priv->auth_logout_button); } } @@ -1835,28 +1660,22 @@ gs_lock_plug_init (GSLockPlug *plug) g_signal_connect (plug->priv->auth_cancel_button, "clicked", G_CALLBACK (cancel_button_clicked), plug); - if (plug->priv->status_message_label) - { - if (plug->priv->status_message) - { + if (plug->priv->status_message_label) { + if (plug->priv->status_message) { gtk_label_set_text (GTK_LABEL (plug->priv->status_message_label), plug->priv->status_message); gtk_widget_show (plug->priv->status_message_label); - } - else - { + } else { gtk_widget_hide (plug->priv->status_message_label); } } - if (plug->priv->auth_switch_button != NULL) - { + if (plug->priv->auth_switch_button != NULL) { g_signal_connect (plug->priv->auth_switch_button, "clicked", G_CALLBACK (switch_user_button_clicked), plug); } - if (plug->priv->auth_logout_button != NULL) - { + if (plug->priv->auth_logout_button != NULL) { g_signal_connect (plug->priv->auth_logout_button, "clicked", G_CALLBACK (logout_button_clicked), plug); } @@ -1867,8 +1686,7 @@ gs_lock_plug_init (GSLockPlug *plug) } static void -gs_lock_plug_finalize (GObject *object) -{ +gs_lock_plug_finalize (GObject *object) { GSLockPlug *plug; g_return_if_fail (object != NULL); @@ -1888,8 +1706,7 @@ gs_lock_plug_finalize (GObject *object) } GtkWidget * -gs_lock_plug_new (void) -{ +gs_lock_plug_new (void) { GtkWidget *result; result = g_object_new (GS_TYPE_LOCK_PLUG, NULL); diff --git a/src/gs-manager.c b/src/gs-manager.c index ef13104cc5befd302e60898704cd8b355c26e255..c3b5cb47def69c15718e797e4d476e2e600de432 100644 --- a/src/gs-manager.c +++ b/src/gs-manager.c @@ -21,33 +21,29 @@ * */ -#include "config.h" +#include <config.h> #include <time.h> + #include <gdk/gdk.h> #include <gdk/gdkx.h> - #include <gio/gio.h> - -#include "xfce-bg.h" - -#include "gs-prefs.h" /* for GSSaverMode */ - -#include "gs-manager.h" -#include "gs-window.h" -#include "gs-theme-manager.h" -#include "gs-job.h" -#include "gs-grab.h" -#include "gs-fade.h" -#include "gs-debug.h" +#include "src/gs-debug.h" +#include "src/gs-grab.h" +#include "src/gs-fade.h" +#include "src/gs-job.h" +#include "src/gs-manager.h" +#include "src/gs-prefs.h" /* for GSSaverMode */ +#include "src/gs-theme-manager.h" +#include "src/gs-window.h" +#include "src/xfce-bg.h" static void gs_manager_class_init (GSManagerClass *klass); static void gs_manager_init (GSManager *manager); static void gs_manager_finalize (GObject *object); -struct GSManagerPrivate -{ +struct GSManagerPrivate { GSList *windows; GHashTable *jobs; @@ -89,8 +85,7 @@ struct GSManagerPrivate guint unfade_idle_id; }; -enum -{ +enum { ACTIVATED, DEACTIVATED, AUTH_REQUEST_BEGIN, @@ -98,8 +93,7 @@ enum LAST_SIGNAL }; -enum -{ +enum { PROP_0, PROP_LOCK_ENABLED, PROP_LOGOUT_ENABLED, @@ -117,17 +111,15 @@ enum #define FADE_TIMEOUT 1000 -static guint signals [LAST_SIGNAL] = { 0, }; +static guint signals[LAST_SIGNAL] = { 0, }; G_DEFINE_TYPE_WITH_PRIVATE (GSManager, gs_manager, G_TYPE_OBJECT) static void manager_add_job_for_window (GSManager *manager, GSWindow *window, - GSJob *job) -{ - if (manager->priv->jobs == NULL) - { + GSJob *job) { + if (manager->priv->jobs == NULL) { return; } @@ -135,24 +127,20 @@ manager_add_job_for_window (GSManager *manager, } static const char * -select_theme (GSManager *manager) -{ +select_theme (GSManager *manager) { const char *theme = NULL; g_return_val_if_fail (manager != NULL, NULL); g_return_val_if_fail (GS_IS_MANAGER (manager), NULL); - if (manager->priv->saver_mode == GS_MODE_BLANK_ONLY) - { + if (manager->priv->saver_mode == GS_MODE_BLANK_ONLY) { return NULL; } - if (manager->priv->themes) - { + if (manager->priv->themes) { int number = 0; - if (manager->priv->saver_mode == GS_MODE_RANDOM) - { + if (manager->priv->saver_mode == GS_MODE_RANDOM) { g_random_set_seed (time (NULL)); number = g_random_int_range (0, g_slist_length (manager->priv->themes)); } @@ -164,12 +152,10 @@ select_theme (GSManager *manager) static GSJob * lookup_job_for_window (GSManager *manager, - GSWindow *window) -{ + GSWindow *window) { GSJob *job; - if (manager->priv->jobs == NULL) - { + if (manager->priv->jobs == NULL) { return NULL; } @@ -180,14 +166,12 @@ lookup_job_for_window (GSManager *manager, static void manager_maybe_stop_job_for_window (GSManager *manager, - GSWindow *window) -{ + GSWindow *window) { GSJob *job; job = lookup_job_for_window (manager, window); - if (job == NULL) - { + if (job == NULL) { gs_debug ("Job not found for window"); return; } @@ -197,86 +181,63 @@ manager_maybe_stop_job_for_window (GSManager *manager, static void manager_maybe_start_job_for_window (GSManager *manager, - GSWindow *window) -{ + GSWindow *window) { GSJob *job; job = lookup_job_for_window (manager, window); - if (job == NULL) - { + if (job == NULL) { gs_debug ("Job not found for window"); return; } - if (! manager->priv->dialog_up) - { - if (! manager->priv->throttled) - { - if (! gs_job_is_running (job)) - { - if (! gs_window_is_obscured (window)) - { + if (!manager->priv->dialog_up) { + if (!manager->priv->throttled) { + if (!gs_job_is_running (job)) { + if (!gs_window_is_obscured (window)) { gs_debug ("Starting job for window"); gs_job_start (job); - } - else - { + } else { gs_debug ("Window is obscured deferring start of job"); } - } - else - { + } else { gs_debug ("Not starting job because job is running"); } - } - else - { + } else { gs_debug ("Not starting job because throttled"); } - } - else - { + } else { gs_debug ("Not starting job because dialog is up"); } } static void manager_select_theme_for_job (GSManager *manager, - GSJob *job) -{ + GSJob *job) { const char *theme; theme = select_theme (manager); - if (theme != NULL) - { + if (theme != NULL) { GSThemeInfo *info; const char *command; command = NULL; info = gs_theme_manager_lookup_theme_info (manager->priv->theme_manager, theme); - if (info != NULL) - { + if (info != NULL) { command = gs_theme_info_get_exec (info); - } - else - { + } else { gs_debug ("Could not find information for theme: %s", theme); } gs_job_set_command (job, command); - - if (info != NULL) - { + if (info != NULL) { gs_theme_info_unref (info); } - } - else - { + } else { gs_job_set_command (job, NULL); } } @@ -284,18 +245,15 @@ manager_select_theme_for_job (GSManager *manager, static void cycle_job (GSWindow *window, GSJob *job, - GSManager *manager) -{ + GSManager *manager) { gs_job_stop (job); manager_select_theme_for_job (manager, job); manager_maybe_start_job_for_window (manager, window); } static void -manager_cycle_jobs (GSManager *manager) -{ - if (manager->priv->jobs != NULL) - { +manager_cycle_jobs (GSManager *manager) { + if (manager->priv->jobs != NULL) { g_hash_table_foreach (manager->priv->jobs, (GHFunc) cycle_job, manager); } } @@ -303,23 +261,17 @@ manager_cycle_jobs (GSManager *manager) static void throttle_job (GSWindow *window, GSJob *job, - GSManager *manager) -{ - if (manager->priv->throttled) - { + GSManager *manager) { + if (manager->priv->throttled) { gs_job_stop (job); - } - else - { + } else { manager_maybe_start_job_for_window (manager, window); } } static void -manager_throttle_jobs (GSManager *manager) -{ - if (manager->priv->jobs != NULL) - { +manager_throttle_jobs (GSManager *manager) { + if (manager->priv->jobs != NULL) { g_hash_table_foreach (manager->priv->jobs, (GHFunc) throttle_job, manager); } } @@ -327,23 +279,17 @@ manager_throttle_jobs (GSManager *manager) static void resume_job (GSWindow *window, GSJob *job, - GSManager *manager) -{ - if (gs_job_is_running (job)) - { + GSManager *manager) { + if (gs_job_is_running (job)) { gs_job_suspend (job, FALSE); - } - else - { + } else { manager_maybe_start_job_for_window (manager, window); } } static void -manager_resume_jobs (GSManager *manager) -{ - if (manager->priv->jobs != NULL) - { +manager_resume_jobs (GSManager *manager) { + if (manager->priv->jobs != NULL) { g_hash_table_foreach (manager->priv->jobs, (GHFunc) resume_job, manager); } } @@ -351,45 +297,36 @@ manager_resume_jobs (GSManager *manager) static void suspend_job (GSWindow *window, GSJob *job, - GSManager *manager) -{ + GSManager *manager) { gs_job_suspend (job, TRUE); } static void -manager_suspend_jobs (GSManager *manager) -{ - if (manager->priv->jobs != NULL) - { +manager_suspend_jobs (GSManager *manager) { + if (manager->priv->jobs != NULL) { g_hash_table_foreach (manager->priv->jobs, (GHFunc) suspend_job, manager); } } static void -manager_stop_jobs (GSManager *manager) -{ - if (manager->priv->jobs != NULL) - { +manager_stop_jobs (GSManager *manager) { + if (manager->priv->jobs != NULL) { g_hash_table_destroy (manager->priv->jobs); - } manager->priv->jobs = NULL; } void gs_manager_set_mode (GSManager *manager, - GSSaverMode mode) -{ + GSSaverMode mode) { g_return_if_fail (GS_IS_MANAGER (manager)); manager->priv->saver_mode = mode; } static void -free_themes (GSManager *manager) -{ - if (manager->priv->themes) - { +free_themes (GSManager *manager) { + if (manager->priv->themes) { g_slist_foreach (manager->priv->themes, (GFunc)g_free, NULL); g_slist_free (manager->priv->themes); } @@ -397,8 +334,7 @@ free_themes (GSManager *manager) void gs_manager_set_themes (GSManager *manager, - GSList *themes) -{ + GSList *themes) { GSList *l; g_return_if_fail (GS_IS_MANAGER (manager)); @@ -406,31 +342,25 @@ gs_manager_set_themes (GSManager *manager, free_themes (manager); manager->priv->themes = NULL; - for (l = themes; l; l = l->next) - { + for (l = themes; l; l = l->next) { manager->priv->themes = g_slist_append (manager->priv->themes, g_strdup (l->data)); } } void gs_manager_set_throttled (GSManager *manager, - gboolean throttled) -{ + gboolean throttled) { g_return_if_fail (GS_IS_MANAGER (manager)); - if (manager->priv->throttled != throttled) - { + if (manager->priv->throttled != throttled) { GSList *l; manager->priv->throttled = throttled; - if (! manager->priv->dialog_up) - { - + if (!manager->priv->dialog_up) { manager_throttle_jobs (manager); - for (l = manager->priv->windows; l; l = l->next) - { + for (l = manager->priv->windows; l; l = l->next) { gs_window_clear (l->data); } } @@ -439,77 +369,64 @@ gs_manager_set_throttled (GSManager *manager, void gs_manager_get_lock_active (GSManager *manager, - gboolean *lock_active) -{ - if (lock_active != NULL) - { + gboolean *lock_active) { + if (lock_active != NULL) { *lock_active = FALSE; } g_return_if_fail (GS_IS_MANAGER (manager)); - if (lock_active != NULL) - { + if (lock_active != NULL) { *lock_active = manager->priv->lock_active; } } void gs_manager_set_lock_active (GSManager *manager, - gboolean lock_active) -{ + gboolean lock_active) { g_return_if_fail (GS_IS_MANAGER (manager)); gs_debug ("Setting lock active: %d", lock_active); - if (manager->priv->lock_active != lock_active) - { + if (manager->priv->lock_active != lock_active) { manager->priv->lock_active = lock_active; } } void gs_manager_get_lock_enabled (GSManager *manager, - gboolean *lock_enabled) -{ - if (lock_enabled != NULL) - { + gboolean *lock_enabled) { + if (lock_enabled != NULL) { *lock_enabled = FALSE; } g_return_if_fail (GS_IS_MANAGER (manager)); - if (lock_enabled != NULL) - { + if (lock_enabled != NULL) { *lock_enabled = manager->priv->lock_enabled; } } void gs_manager_set_lock_enabled (GSManager *manager, - gboolean lock_enabled) -{ + gboolean lock_enabled) { g_return_if_fail (GS_IS_MANAGER (manager)); - if (manager->priv->lock_enabled != lock_enabled) - { + if (manager->priv->lock_enabled != lock_enabled) { manager->priv->lock_enabled = lock_enabled; } } void gs_manager_set_logout_enabled (GSManager *manager, - gboolean logout_enabled) -{ + gboolean logout_enabled) { g_return_if_fail (GS_IS_MANAGER (manager)); - if (manager->priv->logout_enabled != logout_enabled) - { + if (manager->priv->logout_enabled != logout_enabled) { GSList *l; manager->priv->logout_enabled = logout_enabled; - for (l = manager->priv->windows; l; l = l->next) - { + for (l = manager->priv->windows; l; l = l->next) { gs_window_set_logout_enabled (l->data, logout_enabled); } } @@ -517,17 +434,14 @@ gs_manager_set_logout_enabled (GSManager *manager, void gs_manager_set_keyboard_enabled (GSManager *manager, - gboolean enabled) -{ + gboolean enabled) { g_return_if_fail (GS_IS_MANAGER (manager)); - if (manager->priv->keyboard_enabled != enabled) - { + if (manager->priv->keyboard_enabled != enabled) { GSList *l; manager->priv->keyboard_enabled = enabled; - for (l = manager->priv->windows; l; l = l->next) - { + for (l = manager->priv->windows; l; l = l->next) { gs_window_set_keyboard_enabled (l->data, enabled); } } @@ -535,27 +449,22 @@ gs_manager_set_keyboard_enabled (GSManager *manager, void gs_manager_set_user_switch_enabled (GSManager *manager, - gboolean user_switch_enabled) -{ + gboolean user_switch_enabled) { g_return_if_fail (GS_IS_MANAGER (manager)); - if (manager->priv->user_switch_enabled != user_switch_enabled) - { + if (manager->priv->user_switch_enabled != user_switch_enabled) { GSList *l; manager->priv->user_switch_enabled = user_switch_enabled; - for (l = manager->priv->windows; l; l = l->next) - { + for (l = manager->priv->windows; l; l = l->next) { gs_window_set_user_switch_enabled (l->data, user_switch_enabled); } } } static gboolean -activate_lock_timeout (GSManager *manager) -{ - if (manager->priv->lock_enabled) - { +activate_lock_timeout (GSManager *manager) { + if (manager->priv->lock_enabled) { gs_manager_set_lock_active (manager, TRUE); } @@ -565,10 +474,8 @@ activate_lock_timeout (GSManager *manager) } static void -remove_lock_timer (GSManager *manager) -{ - if (manager->priv->lock_timeout_id != 0) - { +remove_lock_timer (GSManager *manager) { + if (manager->priv->lock_timeout_id != 0) { g_source_remove (manager->priv->lock_timeout_id); manager->priv->lock_timeout_id = 0; } @@ -576,8 +483,7 @@ remove_lock_timer (GSManager *manager) static void add_lock_timer (GSManager *manager, - glong timeout) -{ + glong timeout) { manager->priv->lock_timeout_id = g_timeout_add (timeout, (GSourceFunc)activate_lock_timeout, manager); @@ -585,30 +491,22 @@ add_lock_timer (GSManager *manager, void gs_manager_set_lock_timeout (GSManager *manager, - glong lock_timeout) -{ + glong lock_timeout) { g_return_if_fail (GS_IS_MANAGER (manager)); - if (manager->priv->lock_timeout != lock_timeout) - { - + if (manager->priv->lock_timeout != lock_timeout) { manager->priv->lock_timeout = lock_timeout; if (manager->priv->active - && ! manager->priv->lock_active - && (lock_timeout >= 0)) - { - + && !manager->priv->lock_active + && (lock_timeout >= 0)) { glong elapsed = (time (NULL) - manager->priv->activate_time) * 1000; remove_lock_timer (manager); - if (elapsed >= lock_timeout) - { + if (elapsed >= lock_timeout) { activate_lock_timeout (manager); - } - else - { + } else { add_lock_timer (manager, lock_timeout - elapsed); } } @@ -617,17 +515,14 @@ gs_manager_set_lock_timeout (GSManager *manager, void gs_manager_set_logout_timeout (GSManager *manager, - glong logout_timeout) -{ + glong logout_timeout) { g_return_if_fail (GS_IS_MANAGER (manager)); - if (manager->priv->logout_timeout != logout_timeout) - { + if (manager->priv->logout_timeout != logout_timeout) { GSList *l; manager->priv->logout_timeout = logout_timeout; - for (l = manager->priv->windows; l; l = l->next) - { + for (l = manager->priv->windows; l; l = l->next) { gs_window_set_logout_timeout (l->data, logout_timeout); } } @@ -635,58 +530,47 @@ gs_manager_set_logout_timeout (GSManager *manager, void gs_manager_set_logout_command (GSManager *manager, - const char *command) -{ + const char *command) { GSList *l; g_return_if_fail (GS_IS_MANAGER (manager)); g_free (manager->priv->logout_command); - if (command) - { + if (command) { manager->priv->logout_command = g_strdup (command); - } - else - { + } else { manager->priv->logout_command = NULL; } - for (l = manager->priv->windows; l; l = l->next) - { + for (l = manager->priv->windows; l; l = l->next) { gs_window_set_logout_command (l->data, manager->priv->logout_command); } } void gs_manager_set_keyboard_command (GSManager *manager, - const char *command) -{ + const char *command) { GSList *l; g_return_if_fail (GS_IS_MANAGER (manager)); g_free (manager->priv->keyboard_command); - if (command) - { + if (command) { manager->priv->keyboard_command = g_strdup (command); - } - else - { + } else { manager->priv->keyboard_command = NULL; } - for (l = manager->priv->windows; l; l = l->next) - { + for (l = manager->priv->windows; l; l = l->next) { gs_window_set_keyboard_command (l->data, manager->priv->keyboard_command); } } void gs_manager_set_status_message (GSManager *manager, - const char *status_message) -{ + const char *status_message) { GSList *l; g_return_if_fail (GS_IS_MANAGER (manager)); @@ -695,32 +579,27 @@ gs_manager_set_status_message (GSManager *manager, manager->priv->status_message = g_strdup (status_message); - for (l = manager->priv->windows; l; l = l->next) - { + for (l = manager->priv->windows; l; l = l->next) { gs_window_set_status_message (l->data, manager->priv->status_message); } } gboolean -gs_manager_cycle (GSManager *manager) -{ +gs_manager_cycle (GSManager *manager) { g_return_val_if_fail (manager != NULL, FALSE); g_return_val_if_fail (GS_IS_MANAGER (manager), FALSE); gs_debug ("cycling jobs"); - if (! manager->priv->active) - { + if (!manager->priv->active) { return FALSE; } - if (manager->priv->dialog_up) - { + if (manager->priv->dialog_up) { return FALSE; } - if (manager->priv->throttled) - { + if (manager->priv->throttled) { return FALSE; } @@ -730,13 +609,11 @@ gs_manager_cycle (GSManager *manager) } static gboolean -cycle_timeout (GSManager *manager) -{ +cycle_timeout (GSManager *manager) { g_return_val_if_fail (manager != NULL, FALSE); g_return_val_if_fail (GS_IS_MANAGER (manager), FALSE); - if (! manager->priv->dialog_up) - { + if (!manager->priv->dialog_up) { gs_manager_cycle (manager); } @@ -744,10 +621,8 @@ cycle_timeout (GSManager *manager) } static void -remove_cycle_timer (GSManager *manager) -{ - if (manager->priv->cycle_timeout_id != 0) - { +remove_cycle_timer (GSManager *manager) { + if (manager->priv->cycle_timeout_id != 0) { g_source_remove (manager->priv->cycle_timeout_id); manager->priv->cycle_timeout_id = 0; } @@ -755,8 +630,7 @@ remove_cycle_timer (GSManager *manager) static void add_cycle_timer (GSManager *manager, - glong timeout) -{ + glong timeout) { manager->priv->cycle_timeout_id = g_timeout_add (timeout, (GSourceFunc)cycle_timeout, manager); @@ -764,33 +638,25 @@ add_cycle_timer (GSManager *manager, void gs_manager_set_cycle_timeout (GSManager *manager, - glong cycle_timeout) -{ + glong cycle_timeout) { g_return_if_fail (GS_IS_MANAGER (manager)); - if (manager->priv->cycle_timeout != cycle_timeout) - { - + if (manager->priv->cycle_timeout != cycle_timeout) { manager->priv->cycle_timeout = cycle_timeout; - if (manager->priv->active && (cycle_timeout >= 0)) - { + if (manager->priv->active && (cycle_timeout >= 0)) { glong timeout; glong elapsed = (time (NULL) - manager->priv->activate_time) * 1000; remove_cycle_timer (manager); - if (elapsed >= cycle_timeout) - { + if (elapsed >= cycle_timeout) { timeout = 0; - } - else - { + } else { timeout = cycle_timeout - elapsed; } add_cycle_timer (manager, timeout); - } } } @@ -799,14 +665,12 @@ static void gs_manager_set_property (GObject *object, guint prop_id, const GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GSManager *self; self = GS_MANAGER (object); - switch (prop_id) - { + switch (prop_id) { case PROP_THROTTLED: gs_manager_set_throttled (self, g_value_get_boolean (value)); break; @@ -850,14 +714,12 @@ static void gs_manager_get_property (GObject *object, guint prop_id, GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GSManager *self; self = GS_MANAGER (object); - switch (prop_id) - { + switch (prop_id) { case PROP_THROTTLED: g_value_set_boolean (value, self->priv->throttled); break; @@ -901,15 +763,14 @@ gs_manager_get_property (GObject *object, } static void -gs_manager_class_init (GSManagerClass *klass) -{ +gs_manager_class_init (GSManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gs_manager_finalize; object_class->get_property = gs_manager_get_property; object_class->set_property = gs_manager_set_property; - signals [ACTIVATED] = + signals[ACTIVATED] = g_signal_new ("activated", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -919,7 +780,7 @@ gs_manager_class_init (GSManagerClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - signals [DEACTIVATED] = + signals[DEACTIVATED] = g_signal_new ("deactivated", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -929,7 +790,7 @@ gs_manager_class_init (GSManagerClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - signals [AUTH_REQUEST_BEGIN] = + signals[AUTH_REQUEST_BEGIN] = g_signal_new ("auth-request-begin", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -939,7 +800,7 @@ gs_manager_class_init (GSManagerClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - signals [AUTH_REQUEST_END] = + signals[AUTH_REQUEST_END] = g_signal_new ("auth-request-end", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -1024,14 +885,12 @@ gs_manager_class_init (GSManagerClass *klass) static void on_bg_changed (XfceBG *bg, - GSManager *manager) -{ + GSManager *manager) { gs_debug ("background changed"); } static void -gs_manager_init (GSManager *manager) -{ +gs_manager_init (GSManager *manager) { manager->priv = gs_manager_get_instance_private (manager); manager->priv->fade = gs_fade_new (); @@ -1049,17 +908,14 @@ gs_manager_init (GSManager *manager) } static void -remove_timers (GSManager *manager) -{ +remove_timers (GSManager *manager) { remove_lock_timer (manager); remove_cycle_timer (manager); } static void -remove_unfade_idle (GSManager *manager) -{ - if (manager->priv->unfade_idle_id > 0) - { +remove_unfade_idle (GSManager *manager) { + if (manager->priv->unfade_idle_id > 0) { g_source_remove (manager->priv->unfade_idle_id); manager->priv->unfade_idle_id = 0; } @@ -1067,22 +923,20 @@ remove_unfade_idle (GSManager *manager) static gboolean -window_deactivated_idle (GSManager *manager) -{ +window_deactivated_idle (GSManager *manager) { g_return_val_if_fail (manager != NULL, FALSE); g_return_val_if_fail (GS_IS_MANAGER (manager), FALSE); /* don't deactivate directly but only emit a signal so that we let the parent deactivate */ - g_signal_emit (manager, signals [DEACTIVATED], 0); + g_signal_emit (manager, signals[DEACTIVATED], 0); return FALSE; } static void window_deactivated_cb (GSWindow *window, - GSManager *manager) -{ + GSManager *manager) { g_return_if_fail (manager != NULL); g_return_if_fail (GS_IS_MANAGER (manager)); @@ -1090,8 +944,7 @@ window_deactivated_cb (GSWindow *window, } static GSWindow * -find_window_at_pointer (GSManager *manager) -{ +find_window_at_pointer (GSManager *manager) { GdkDisplay *display; GdkDevice *device; GdkMonitor *monitor; @@ -1107,25 +960,20 @@ find_window_at_pointer (GSManager *manager) /* Find the gs-window that is on that monitor */ window = NULL; - for (l = manager->priv->windows; l; l = l->next) - { + for (l = manager->priv->windows; l; l = l->next) { GSWindow *win = GS_WINDOW (l->data); if (gs_window_get_display (win) == display && - gs_window_get_monitor (win) == monitor) - { + gs_window_get_monitor (win) == monitor) { window = win; } } - if (window == NULL) - { + if (window == NULL) { gs_debug ("WARNING: Could not find the GSWindow for display %s", gdk_display_get_name (display)); /* take the first one */ window = manager->priv->windows->data; - } - else - { + } else { gs_debug ("Requesting unlock for display %s", gdk_display_get_name (display)); } @@ -1137,8 +985,7 @@ void gs_manager_show_message (GSManager *manager, const char *summary, const char *body, - const char *icon) -{ + const char *icon) { GSWindow *window; g_return_if_fail (GS_IS_MANAGER (manager)); @@ -1151,8 +998,7 @@ gs_manager_show_message (GSManager *manager, static gboolean manager_maybe_grab_window (GSManager *manager, - GSWindow *window) -{ + GSWindow *window) { GdkDisplay *display; GdkDevice *device; GdkMonitor *monitor; @@ -1167,8 +1013,7 @@ manager_maybe_grab_window (GSManager *manager, gdk_display_flush (display); grabbed = FALSE; if (gs_window_get_display (window) == display && - gs_window_get_monitor (window) == monitor) - { + gs_window_get_monitor (window) == monitor) { gs_debug ("Initiate grab move to %p", window); gs_grab_move_to_window (manager->priv->grab, gs_window_get_gdk_window (window), @@ -1183,8 +1028,7 @@ manager_maybe_grab_window (GSManager *manager, static void window_grab_broken_cb (GSWindow *window, GdkEventGrabBroken *event, - GSManager *manager) -{ + GSManager *manager) { GdkDisplay *display; GdkSeat *seat; GdkDevice *device; @@ -1192,15 +1036,12 @@ window_grab_broken_cb (GSWindow *window, display = gdk_window_get_display (gs_window_get_gdk_window (window)); seat = gdk_display_get_default_seat (display); - if (event->keyboard) - { + if (event->keyboard) { gs_debug ("KEYBOARD GRAB BROKEN!"); device = gdk_seat_get_pointer (seat); if (!gdk_display_device_is_grabbed (display, device)) gs_grab_reset (manager->priv->grab); - } - else - { + } else { gs_debug ("POINTER GRAB BROKEN!"); device = gdk_seat_get_keyboard (seat); if (!gdk_display_device_is_grabbed (display, device)) @@ -1209,18 +1050,15 @@ window_grab_broken_cb (GSWindow *window, } static gboolean -unfade_idle (GSManager *manager) -{ +unfade_idle (GSManager *manager) { gs_debug ("resetting fade"); gs_fade_reset (manager->priv->fade); manager->priv->unfade_idle_id = 0; return FALSE; } - static void -add_unfade_idle (GSManager *manager) -{ +add_unfade_idle (GSManager *manager) { remove_unfade_idle (manager); manager->priv->unfade_idle_id = g_timeout_add (500, (GSourceFunc)unfade_idle, manager); } @@ -1228,8 +1066,7 @@ add_unfade_idle (GSManager *manager) static gboolean window_map_event_cb (GSWindow *window, GdkEvent *event, - GSManager *manager) -{ + GSManager *manager) { gs_debug ("Handling window map_event event"); manager_maybe_grab_window (manager, window); @@ -1241,22 +1078,19 @@ window_map_event_cb (GSWindow *window, static void window_map_cb (GSWindow *window, - GSManager *manager) -{ + GSManager *manager) { gs_debug ("Handling window map event"); } static void window_unmap_cb (GSWindow *window, - GSManager *manager) -{ + GSManager *manager) { gs_debug ("window unmapped!"); } static void apply_background_to_window (GSManager *manager, - GSWindow *window) -{ + GSWindow *window) { cairo_surface_t *surface; GdkMonitor *monitor; GdkRectangle geometry; @@ -1267,8 +1101,7 @@ apply_background_to_window (GSManager *manager, xfce_bg_load_from_preferences (manager->priv->bg, monitor); - if (manager->priv->bg == NULL) - { + if (manager->priv->bg == NULL) { gs_debug ("No background available"); gs_window_set_background_surface (window, NULL); } @@ -1291,8 +1124,7 @@ apply_background_to_window (GSManager *manager, static void manager_show_window (GSManager *manager, - GSWindow *window) -{ + GSWindow *window) { GSJob *job; apply_background_to_window (manager, window); @@ -1304,14 +1136,12 @@ manager_show_window (GSManager *manager, manager->priv->activate_time = time (NULL); - if (manager->priv->lock_timeout >= 0) - { + if (manager->priv->lock_timeout >= 0) { remove_lock_timer (manager); add_lock_timer (manager, manager->priv->lock_timeout); } - if (manager->priv->cycle_timeout >= 10000) - { + if (manager->priv->cycle_timeout >= 10000) { remove_cycle_timer (manager); add_cycle_timer (manager, manager->priv->cycle_timeout); } @@ -1319,14 +1149,12 @@ manager_show_window (GSManager *manager, add_unfade_idle (manager); /* FIXME: only emit signal once */ - g_signal_emit (manager, signals [ACTIVATED], 0); + g_signal_emit (manager, signals[ACTIVATED], 0); } static void window_show_cb (GSWindow *window, - GSManager *manager) -{ - + GSManager *manager) { g_return_if_fail (manager != NULL); g_return_if_fail (GS_IS_MANAGER (manager)); g_return_if_fail (window != NULL); @@ -1339,14 +1167,10 @@ window_show_cb (GSWindow *window, static void maybe_set_window_throttle (GSManager *manager, GSWindow *window, - gboolean throttled) -{ - if (throttled) - { + gboolean throttled) { + if (throttled) { manager_maybe_stop_job_for_window (manager, window); - } - else - { + } else { manager_maybe_start_job_for_window (manager, window); } } @@ -1354,8 +1178,7 @@ maybe_set_window_throttle (GSManager *manager, static void window_obscured_cb (GSWindow *window, GParamSpec *pspec, - GSManager *manager) -{ + GSManager *manager) { gboolean obscured; obscured = gs_window_is_obscured (window); @@ -1366,8 +1189,7 @@ window_obscured_cb (GSWindow *window, static void handle_window_dialog_up (GSManager *manager, - GSWindow *window) -{ + GSWindow *window) { GSList *l; g_return_if_fail (manager != NULL); @@ -1375,14 +1197,12 @@ handle_window_dialog_up (GSManager *manager, gs_debug ("Handling dialog up"); - g_signal_emit (manager, signals [AUTH_REQUEST_BEGIN], 0); + g_signal_emit (manager, signals[AUTH_REQUEST_BEGIN], 0); manager->priv->dialog_up = TRUE; /* make all other windows insensitive to not get events */ - for (l = manager->priv->windows; l; l = l->next) - { - if (l->data != window) - { + for (l = manager->priv->windows; l; l = l->next) { + if (l->data != window) { gtk_widget_set_sensitive (GTK_WIDGET (l->data), FALSE); } } @@ -1396,8 +1216,7 @@ handle_window_dialog_up (GSManager *manager, gs_window_get_display (window), TRUE, FALSE); - if (! manager->priv->throttled) - { + if (!manager->priv->throttled) { gs_debug ("Suspending jobs"); manager_suspend_jobs (manager); @@ -1406,8 +1225,7 @@ handle_window_dialog_up (GSManager *manager, static void handle_window_dialog_down (GSManager *manager, - GSWindow *window) -{ + GSWindow *window) { GSList *l; g_return_if_fail (manager != NULL); @@ -1422,44 +1240,37 @@ handle_window_dialog_down (GSManager *manager, FALSE, FALSE); /* make all windows sensitive to get events */ - for (l = manager->priv->windows; l; l = l->next) - { + for (l = manager->priv->windows; l; l = l->next) { gtk_widget_set_sensitive (GTK_WIDGET (l->data), TRUE); } manager->priv->dialog_up = FALSE; - if (! manager->priv->throttled) - { + if (!manager->priv->throttled) { manager_resume_jobs (manager); } - g_signal_emit (manager, signals [AUTH_REQUEST_END], 0); + g_signal_emit (manager, signals[AUTH_REQUEST_END], 0); } static void window_dialog_up_changed_cb (GSWindow *window, GParamSpec *pspec, - GSManager *manager) -{ + GSManager *manager) { gboolean up; up = gs_window_is_dialog_up (window); gs_debug ("Handling window dialog up changed: %s", up ? "up" : "down"); - if (up) - { + if (up) { handle_window_dialog_up (manager, window); - } - else - { + } else { handle_window_dialog_down (manager, window); } } static gboolean window_activity_cb (GSWindow *window, - GSManager *manager) -{ + GSManager *manager) { gboolean handled; handled = gs_manager_request_unlock (manager); @@ -1468,8 +1279,7 @@ window_activity_cb (GSWindow *window, static void disconnect_window_signals (GSManager *manager, - GSWindow *window) -{ + GSWindow *window) { g_signal_handlers_disconnect_by_func (window, window_deactivated_cb, manager); g_signal_handlers_disconnect_by_func (window, window_activity_cb, manager); g_signal_handlers_disconnect_by_func (window, window_show_cb, manager); @@ -1483,15 +1293,13 @@ disconnect_window_signals (GSManager *manager, static void window_destroyed_cb (GtkWindow *window, - GSManager *manager) -{ + GSManager *manager) { disconnect_window_signals (manager, GS_WINDOW (window)); } static void connect_window_signals (GSManager *manager, - GSWindow *window) -{ + GSWindow *window) { g_signal_connect_object (window, "destroy", G_CALLBACK (window_destroyed_cb), manager, 0); g_signal_connect_object (window, "activity", @@ -1516,8 +1324,7 @@ connect_window_signals (GSManager *manager, static void gs_manager_create_window_for_monitor (GSManager *manager, - GdkMonitor *monitor) -{ + GdkMonitor *monitor) { GSWindow *window; GdkRectangle rect; @@ -1540,8 +1347,7 @@ gs_manager_create_window_for_monitor (GSManager *manager, manager->priv->windows = g_slist_append (manager->priv->windows, window); - if (manager->priv->active && !manager->priv->fading) - { + if (manager->priv->active && !manager->priv->fading) { gtk_widget_show (GTK_WIDGET (window)); } } @@ -1549,8 +1355,7 @@ gs_manager_create_window_for_monitor (GSManager *manager, static void on_display_monitor_added (GdkDisplay *display, GdkMonitor *monitor, - GSManager *manager) -{ + GSManager *manager) { GSList *l; int n_monitors; @@ -1566,8 +1371,7 @@ on_display_monitor_added (GdkDisplay *display, * to the new monitor */ l = manager->priv->windows; - while (l != NULL) - { + while (l != NULL) { gs_window_cancel_unlock_request (GS_WINDOW (l->data)); l = l->next; } @@ -1576,8 +1380,7 @@ on_display_monitor_added (GdkDisplay *display, static void on_display_monitor_removed (GdkDisplay *display, GdkMonitor *monitor, - GSManager *manager) -{ + GSManager *manager) { GSList *l; int n_monitors; GdkMonitor *last_monitor = NULL; @@ -1591,24 +1394,20 @@ on_display_monitor_removed (GdkDisplay *display, /* remove the now extra window */ l = manager->priv->windows; - while (l != NULL) - { + while (l != NULL) { GdkDisplay *this_display; GdkMonitor *this_monitor; GSList *next = l->next; this_display = gs_window_get_display (GS_WINDOW (l->data)); this_monitor = gs_window_get_monitor (GS_WINDOW (l->data)); - if (this_display == display && this_monitor == monitor) - { + if (this_display == display && this_monitor == monitor) { manager_maybe_stop_job_for_window (manager, GS_WINDOW (l->data)); g_hash_table_remove (manager->priv->jobs, l->data); gs_window_destroy (GS_WINDOW (l->data)); manager->priv->windows = g_slist_delete_link (manager->priv->windows, l); - } - else - { + } else { last_monitor = this_monitor; gs_window_cancel_unlock_request (GS_WINDOW (l->data)); } @@ -1627,16 +1426,14 @@ on_display_monitor_removed (GdkDisplay *display, } static void -gs_manager_destroy_windows (GSManager *manager) -{ +gs_manager_destroy_windows (GSManager *manager) { GdkDisplay *display; GSList *l; g_return_if_fail (manager != NULL); g_return_if_fail (GS_IS_MANAGER (manager)); - if (manager->priv->windows == NULL) - { + if (manager->priv->windows == NULL) { return; } @@ -1649,8 +1446,7 @@ gs_manager_destroy_windows (GSManager *manager) on_display_monitor_added, manager); - for (l = manager->priv->windows; l; l = l->next) - { + for (l = manager->priv->windows; l; l = l->next) { gs_window_destroy (l->data); } g_slist_free (manager->priv->windows); @@ -1658,8 +1454,7 @@ gs_manager_destroy_windows (GSManager *manager) } static void -gs_manager_finalize (GObject *object) -{ +gs_manager_finalize (GObject *object) { GSManager *manager; g_return_if_fail (object != NULL); @@ -1669,8 +1464,7 @@ gs_manager_finalize (GObject *object) g_return_if_fail (manager->priv != NULL); - if (manager->priv->bg != NULL) - { + if (manager->priv->bg != NULL) { g_object_unref (manager->priv->bg); } @@ -1701,8 +1495,7 @@ gs_manager_finalize (GObject *object) static void gs_manager_create_windows_for_display (GSManager *manager, - GdkDisplay *display) -{ + GdkDisplay *display) { int n_monitors; int i; @@ -1718,8 +1511,7 @@ gs_manager_create_windows_for_display (GSManager *manager, gs_debug ("Creating %d windows for display %s", n_monitors, gdk_display_get_name (display)); - for (i = 0; i < n_monitors; i++) - { + for (i = 0; i < n_monitors; i++) { GdkMonitor *mon = gdk_display_get_monitor (display, i); gs_manager_create_window_for_monitor (manager, mon); } @@ -1729,8 +1521,7 @@ gs_manager_create_windows_for_display (GSManager *manager, } static void -gs_manager_create_windows (GSManager *manager) -{ +gs_manager_create_windows (GSManager *manager) { GdkDisplay *display; g_return_if_fail (manager != NULL); @@ -1750,8 +1541,7 @@ gs_manager_create_windows (GSManager *manager) } GSManager * -gs_manager_new (void) -{ +gs_manager_new (void) { GObject *manager; manager = g_object_new (GS_TYPE_MANAGER, NULL); @@ -1760,21 +1550,17 @@ gs_manager_new (void) } static void -show_windows (GSList *windows) -{ +show_windows (GSList *windows) { GSList *l; - for (l = windows; l; l = l->next) - { + for (l = windows; l; l = l->next) { gtk_widget_show (GTK_WIDGET (l->data)); } } static void -remove_job (GSJob *job) -{ - if (job == NULL) - { +remove_job (GSJob *job) { + if (job == NULL) { return; } @@ -1784,36 +1570,31 @@ remove_job (GSJob *job) static void fade_done_cb (GSFade *fade, - GSManager *manager) -{ + GSManager *manager) { gs_debug ("fade completed, showing windows"); show_windows (manager->priv->windows); manager->priv->fading = FALSE; } static gboolean -gs_manager_activate (GSManager *manager) -{ +gs_manager_activate (GSManager *manager) { gboolean do_fade; gboolean res; g_return_val_if_fail (manager != NULL, FALSE); g_return_val_if_fail (GS_IS_MANAGER (manager), FALSE); - if (manager->priv->active) - { + if (manager->priv->active) { gs_debug ("Trying to activate manager when already active"); return FALSE; } res = gs_grab_grab_root (manager->priv->grab, FALSE, FALSE); - if (! res) - { + if (!res) { return FALSE; } - if (manager->priv->windows == NULL) - { + if (manager->priv->windows == NULL) { gs_manager_create_windows (GS_MANAGER (manager)); } @@ -1826,8 +1607,7 @@ gs_manager_activate (GSManager *manager) /* fade to black and show windows */ do_fade = TRUE; - if (do_fade) - { + if (do_fade) { manager->priv->fading = TRUE; gs_debug ("fading out"); gs_fade_async (manager->priv->fade, @@ -1835,13 +1615,10 @@ gs_manager_activate (GSManager *manager) (GSFadeDoneFunc)fade_done_cb, manager); - while (manager->priv->fading) - { + while (manager->priv->fading) { gtk_main_iteration (); } - } - else - { + } else { show_windows (manager->priv->windows); } @@ -1849,13 +1626,11 @@ gs_manager_activate (GSManager *manager) } static gboolean -gs_manager_deactivate (GSManager *manager) -{ +gs_manager_deactivate (GSManager *manager) { g_return_val_if_fail (manager != NULL, FALSE); g_return_val_if_fail (GS_IS_MANAGER (manager), FALSE); - if (! manager->priv->active) - { + if (!manager->priv->active) { gs_debug ("Trying to deactivate a screensaver that is not active"); return FALSE; } @@ -1882,16 +1657,12 @@ gs_manager_deactivate (GSManager *manager) gboolean gs_manager_set_active (GSManager *manager, - gboolean active) -{ + gboolean active) { gboolean res; - if (active) - { + if (active) { res = gs_manager_activate (manager); - } - else - { + } else { res = gs_manager_deactivate (manager); } @@ -1899,8 +1670,7 @@ gs_manager_set_active (GSManager *manager, } gboolean -gs_manager_get_active (GSManager *manager) -{ +gs_manager_get_active (GSManager *manager) { g_return_val_if_fail (manager != NULL, FALSE); g_return_val_if_fail (GS_IS_MANAGER (manager), FALSE); @@ -1908,33 +1678,28 @@ gs_manager_get_active (GSManager *manager) } gboolean -gs_manager_request_unlock (GSManager *manager) -{ +gs_manager_request_unlock (GSManager *manager) { GSWindow *window; g_return_val_if_fail (manager != NULL, FALSE); g_return_val_if_fail (GS_IS_MANAGER (manager), FALSE); - if (! manager->priv->active) - { + if (!manager->priv->active) { gs_debug ("Request unlock but manager is not active"); return FALSE; } - if (manager->priv->dialog_up) - { + if (manager->priv->dialog_up) { gs_debug ("Request unlock but dialog is already up"); return FALSE; } - if (manager->priv->fading) - { + if (manager->priv->fading) { gs_debug ("Request unlock so finishing fade"); gs_fade_finish (manager->priv->fade); } - if (manager->priv->windows == NULL) - { + if (manager->priv->windows == NULL) { gs_debug ("We don't have any windows!"); return FALSE; } @@ -1948,11 +1713,9 @@ gs_manager_request_unlock (GSManager *manager) } void -gs_manager_cancel_unlock_request (GSManager *manager) -{ +gs_manager_cancel_unlock_request (GSManager *manager) { GSList *l; - for (l = manager->priv->windows; l; l = l->next) - { + for (l = manager->priv->windows; l; l = l->next) { gs_window_cancel_unlock_request (l->data); } } diff --git a/src/gs-monitor.c b/src/gs-monitor.c index 9b20f4a477cd4bfbc6ab791f1df359c351f81d9d..1fae0ec320f9ea4fff6b657f1db04cee32c07fc6 100644 --- a/src/gs-monitor.c +++ b/src/gs-monitor.c @@ -21,28 +21,28 @@ * */ -#include "config.h" -#include <stdlib.h> +#include <config.h> + #include <stdio.h> -#include <unistd.h> +#include <stdlib.h> #include <string.h> +#include <unistd.h> + #include <X11/extensions/scrnsaver.h> #include <glib.h> #include <glib-object.h> #include <gdk/gdkx.h> -#include "xfce4-screensaver.h" - -#include "gs-manager.h" -#include "gs-fade.h" -#include "gs-grab.h" - -#include "gs-listener-dbus.h" -#include "gs-listener-x11.h" -#include "gs-monitor.h" -#include "gs-prefs.h" -#include "gs-debug.h" +#include "src/gs-debug.h" +#include "src/gs-fade.h" +#include "src/gs-grab.h" +#include "src/gs-listener-dbus.h" +#include "src/gs-listener-x11.h" +#include "src/gs-manager.h" +#include "src/gs-monitor.h" +#include "src/gs-prefs.h" +#include "src/xfce4-screensaver.h" static void gs_monitor_class_init(GSMonitorClass* klass); static void gs_monitor_init(GSMonitor* monitor); @@ -62,25 +62,21 @@ struct GSMonitorPrivate { G_DEFINE_TYPE_WITH_PRIVATE(GSMonitor, gs_monitor, G_TYPE_OBJECT) -static void gs_monitor_class_init(GSMonitorClass* klass) -{ +static void gs_monitor_class_init(GSMonitorClass* klass) { GObjectClass* object_class = G_OBJECT_CLASS(klass); object_class->finalize = gs_monitor_finalize; } -static void manager_activated_cb(GSManager* manager, GSMonitor* monitor) -{ +static void manager_activated_cb(GSManager* manager, GSMonitor* monitor) { /* Nothing */ } -static void manager_deactivated_cb(GSManager* manager, GSMonitor* monitor) -{ +static void manager_deactivated_cb(GSManager* manager, GSMonitor* monitor) { gs_listener_set_active (monitor->priv->listener, FALSE); } -static void gs_monitor_lock_screen(GSMonitor* monitor) -{ +static void gs_monitor_lock_screen(GSMonitor* monitor) { gboolean res; gboolean locked; gboolean active; @@ -94,8 +90,7 @@ static void gs_monitor_lock_screen(GSMonitor* monitor) if (!active) { res = gs_listener_set_active(monitor->priv->listener, TRUE); - if (!res) - { + if (!res) { /* if we've failed then restore lock status */ gs_manager_set_lock_active(monitor->priv->manager, locked); gs_debug("Unable to lock the screen"); @@ -103,8 +98,7 @@ static void gs_monitor_lock_screen(GSMonitor* monitor) } } -static void gs_monitor_simulate_user_activity(GSMonitor* monitor) -{ +static void gs_monitor_simulate_user_activity(GSMonitor* monitor) { Display *display = gdk_x11_display_get_xdisplay (gdk_display_get_default ()); XScreenSaverSuspend (display, TRUE); XSync (display, FALSE); @@ -116,48 +110,42 @@ static void gs_monitor_simulate_user_activity(GSMonitor* monitor) gs_manager_request_unlock(monitor->priv->manager); } -static void listener_lock_cb(GSListener* listener, GSMonitor* monitor) -{ - if (monitor->priv->prefs->lock_enabled) - { +static void listener_lock_cb(GSListener* listener, GSMonitor* monitor) { + if (monitor->priv->prefs->lock_enabled) { gs_monitor_lock_screen(monitor); - } - else - { + } else { gs_debug("Locking disabled by the administrator"); } } -static void listener_x11_lock_cb(GSListenerX11* listener, GSMonitor* monitor) -{ +static void listener_x11_lock_cb(GSListenerX11* listener, GSMonitor* monitor) { gs_monitor_lock_screen(monitor); } -static void listener_quit_cb(GSListener* listener, GSMonitor* monitor) -{ +static void listener_quit_cb(GSListener* listener, GSMonitor* monitor) { gs_listener_set_active(monitor->priv->listener, FALSE); xfce4_screensaver_quit(); } -static void listener_cycle_cb(GSListener* listener, GSMonitor* monitor) -{ +static void listener_cycle_cb(GSListener* listener, GSMonitor* monitor) { gs_manager_cycle(monitor->priv->manager); } -static void listener_show_message_cb(GSListener* listener, const char* summary, const char* body, const char* icon, GSMonitor* monitor) -{ +static void listener_show_message_cb(GSListener* listener, + const char* summary, + const char* body, + const char* icon, + GSMonitor* monitor) { gs_manager_show_message(monitor->priv->manager, summary, body, icon); } -static gboolean listener_active_changed_cb(GSListener* listener, gboolean active, GSMonitor* monitor) -{ +static gboolean listener_active_changed_cb(GSListener* listener, gboolean active, GSMonitor* monitor) { gboolean res; gboolean ret; res = gs_manager_set_active(monitor->priv->manager, active); - if (! res) - { + if (!res) { gs_debug("Unable to set manager active: %d", active); ret = FALSE; goto done; @@ -170,18 +158,15 @@ static gboolean listener_active_changed_cb(GSListener* listener, gboolean active return ret; } -static void listener_throttle_changed_cb(GSListener* listener, gboolean throttled, GSMonitor* monitor) -{ +static void listener_throttle_changed_cb(GSListener* listener, gboolean throttled, GSMonitor* monitor) { gs_manager_set_throttled(monitor->priv->manager, throttled); } -static void listener_simulate_user_activity_cb(GSListener* listener, GSMonitor* monitor) -{ +static void listener_simulate_user_activity_cb(GSListener* listener, GSMonitor* monitor) { gs_monitor_simulate_user_activity(monitor); } -static void _gs_monitor_update_from_prefs(GSMonitor* monitor, GSPrefs* prefs) -{ +static void _gs_monitor_update_from_prefs(GSMonitor* monitor, GSPrefs* prefs) { gboolean lock_enabled; gboolean user_switch_enabled; @@ -205,8 +190,7 @@ static void _gs_monitor_update_from_prefs(GSMonitor* monitor, GSPrefs* prefs) gs_listener_x11_set_lock_after(monitor->priv->listener_x11, monitor->priv->prefs->timeout); } -static void disconnect_listener_signals(GSMonitor* monitor) -{ +static void disconnect_listener_signals(GSMonitor* monitor) { g_signal_handlers_disconnect_by_func(monitor->priv->listener, listener_lock_cb, monitor); g_signal_handlers_disconnect_by_func(monitor->priv->listener, listener_quit_cb, monitor); g_signal_handlers_disconnect_by_func(monitor->priv->listener, listener_cycle_cb, monitor); @@ -218,45 +202,45 @@ static void disconnect_listener_signals(GSMonitor* monitor) g_signal_handlers_disconnect_by_func(monitor->priv->listener_x11, listener_x11_lock_cb, monitor); } -static void connect_listener_signals(GSMonitor* monitor) -{ - g_signal_connect(monitor->priv->listener, "lock", G_CALLBACK(listener_lock_cb), monitor); - g_signal_connect(monitor->priv->listener, "quit", G_CALLBACK(listener_quit_cb), monitor); - g_signal_connect(monitor->priv->listener, "cycle", G_CALLBACK(listener_cycle_cb), monitor); - g_signal_connect(monitor->priv->listener, "active-changed", G_CALLBACK(listener_active_changed_cb), monitor); - g_signal_connect(monitor->priv->listener, "throttle-changed", G_CALLBACK(listener_throttle_changed_cb), monitor); - g_signal_connect(monitor->priv->listener, "simulate-user-activity", G_CALLBACK(listener_simulate_user_activity_cb), monitor); - g_signal_connect(monitor->priv->listener, "show-message", G_CALLBACK(listener_show_message_cb), monitor); +static void connect_listener_signals(GSMonitor* monitor) { + g_signal_connect(monitor->priv->listener, "lock", + G_CALLBACK(listener_lock_cb), monitor); + g_signal_connect(monitor->priv->listener, "quit", + G_CALLBACK(listener_quit_cb), monitor); + g_signal_connect(monitor->priv->listener, "cycle", + G_CALLBACK(listener_cycle_cb), monitor); + g_signal_connect(monitor->priv->listener, "active-changed", + G_CALLBACK(listener_active_changed_cb), monitor); + g_signal_connect(monitor->priv->listener, "throttle-changed", + G_CALLBACK(listener_throttle_changed_cb), monitor); + g_signal_connect(monitor->priv->listener, "simulate-user-activity", + G_CALLBACK(listener_simulate_user_activity_cb), monitor); + g_signal_connect(monitor->priv->listener, "show-message", + G_CALLBACK(listener_show_message_cb), monitor); g_signal_connect(monitor->priv->listener_x11, "lock", G_CALLBACK(listener_x11_lock_cb), monitor); } -static void disconnect_manager_signals(GSMonitor* monitor) -{ +static void disconnect_manager_signals(GSMonitor* monitor) { g_signal_handlers_disconnect_by_func(monitor->priv->manager, manager_activated_cb, monitor); g_signal_handlers_disconnect_by_func(monitor->priv->manager, manager_deactivated_cb, monitor); } -static void connect_manager_signals(GSMonitor* monitor) -{ +static void connect_manager_signals(GSMonitor* monitor) { g_signal_connect(monitor->priv->manager, "activated", G_CALLBACK(manager_activated_cb), monitor); g_signal_connect(monitor->priv->manager, "deactivated", G_CALLBACK(manager_deactivated_cb), monitor); } -static void disconnect_prefs_signals(GSMonitor* monitor) -{ +static void disconnect_prefs_signals(GSMonitor* monitor) { g_signal_handlers_disconnect_by_func(monitor->priv->prefs, _gs_monitor_update_from_prefs, monitor); } -static void connect_prefs_signals(GSMonitor* monitor) -{ +static void connect_prefs_signals(GSMonitor* monitor) { g_signal_connect_swapped(monitor->priv->prefs, "changed", G_CALLBACK(_gs_monitor_update_from_prefs), monitor); } -static void gs_monitor_init(GSMonitor* monitor) -{ - +static void gs_monitor_init(GSMonitor* monitor) { monitor->priv = gs_monitor_get_instance_private (monitor); monitor->priv->prefs = gs_prefs_new(); @@ -275,8 +259,7 @@ static void gs_monitor_init(GSMonitor* monitor) _gs_monitor_update_from_prefs(monitor, monitor->priv->prefs); } -static void gs_monitor_finalize(GObject* object) -{ +static void gs_monitor_finalize(GObject* object) { GSMonitor* monitor; g_return_if_fail(object != NULL); @@ -300,8 +283,7 @@ static void gs_monitor_finalize(GObject* object) G_OBJECT_CLASS(gs_monitor_parent_class)->finalize(object); } -GSMonitor* gs_monitor_new(void) -{ +GSMonitor* gs_monitor_new(void) { GSMonitor* monitor; monitor = g_object_new(GS_TYPE_MONITOR, NULL); @@ -309,12 +291,10 @@ GSMonitor* gs_monitor_new(void) return GS_MONITOR(monitor); } -gboolean gs_monitor_start(GSMonitor* monitor, GError** error) -{ +gboolean gs_monitor_start(GSMonitor* monitor, GError** error) { g_return_val_if_fail(GS_IS_MONITOR(monitor), FALSE); - if (!gs_listener_acquire(monitor->priv->listener, error)) - { + if (!gs_listener_acquire(monitor->priv->listener, error)) { return FALSE; } diff --git a/src/gs-prefs.c b/src/gs-prefs.c index cf85b7425dd79671b4ad88f3440d8d6fa95df5e6..f6d9f02a6efe2cb2c51031ac8b45fb1e37b6f88f 100644 --- a/src/gs-prefs.c +++ b/src/gs-prefs.c @@ -21,39 +21,36 @@ * */ -#include "config.h" +#include <config.h> #include <string.h> +#include <gio/gio.h> #include <glib.h> #include <glib-object.h> -#include <gio/gio.h> #include <xfconf/xfconf.h> -#include "gs-prefs.h" +#include "src/gs-prefs.h" static void gs_prefs_class_init (GSPrefsClass *klass); static void gs_prefs_init (GSPrefs *prefs); static void gs_prefs_finalize (GObject *object); -struct GSPrefsPrivate -{ +struct GSPrefsPrivate { XfconfChannel *channel; }; -enum -{ +enum { CHANGED, LAST_SIGNAL }; -enum -{ +enum { PROP_0 }; -static guint signals [LAST_SIGNAL] = { 0, }; +static guint signals[LAST_SIGNAL] = { 0, }; G_DEFINE_TYPE_WITH_PRIVATE (GSPrefs, gs_prefs, G_TYPE_OBJECT) @@ -61,13 +58,11 @@ static void gs_prefs_set_property (GObject *object, guint prop_id, const GValue *value, - GParamSpec *pspec) -{ - switch (prop_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; + GParamSpec *pspec) { + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; } } @@ -75,19 +70,16 @@ static void gs_prefs_get_property (GObject *object, guint prop_id, GValue *value, - GParamSpec *pspec) -{ - switch (prop_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; + GParamSpec *pspec) { + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; } } static void -gs_prefs_class_init (GSPrefsClass *klass) -{ +gs_prefs_class_init (GSPrefsClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gs_prefs_finalize; @@ -95,7 +87,7 @@ gs_prefs_class_init (GSPrefsClass *klass) object_class->set_property = gs_prefs_set_property; - signals [CHANGED] = + signals[CHANGED] = g_signal_new ("changed", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -109,8 +101,7 @@ gs_prefs_class_init (GSPrefsClass *klass) static void _gs_prefs_set_timeout (GSPrefs *prefs, - int value) -{ + int value) { if (value < 1) value = 10; @@ -124,8 +115,7 @@ _gs_prefs_set_timeout (GSPrefs *prefs, static void _gs_prefs_set_power_timeout (GSPrefs *prefs, - int value) -{ + int value) { if (value < 1) value = 60; @@ -140,8 +130,7 @@ _gs_prefs_set_power_timeout (GSPrefs *prefs, static void _gs_prefs_set_lock_timeout (GSPrefs *prefs, - int value) -{ + int value) { if (value < 0) value = 0; @@ -155,8 +144,7 @@ _gs_prefs_set_lock_timeout (GSPrefs *prefs, static void _gs_prefs_set_cycle_timeout (GSPrefs *prefs, - int value) -{ + int value) { if (value < 1) value = 1; @@ -170,18 +158,15 @@ _gs_prefs_set_cycle_timeout (GSPrefs *prefs, static void _gs_prefs_set_mode (GSPrefs *prefs, - gint mode) -{ + gint mode) { prefs->mode = mode; } static void _gs_prefs_set_themes (GSPrefs *prefs, - gchar **values) -{ + gchar **values) { guint i; - if (prefs->themes) - { + if (prefs->themes) { g_slist_foreach (prefs->themes, (GFunc)g_free, NULL); g_slist_free (prefs->themes); } @@ -197,34 +182,29 @@ _gs_prefs_set_themes (GSPrefs *prefs, static void _gs_prefs_set_idle_activation_enabled (GSPrefs *prefs, - gboolean value) -{ + gboolean value) { prefs->idle_activation_enabled = value; } static void _gs_prefs_set_lock_enabled (GSPrefs *prefs, - gboolean value) -{ + gboolean value) { prefs->lock_enabled = value; } static void _gs_prefs_set_keyboard_enabled (GSPrefs *prefs, - gboolean value) -{ + gboolean value) { prefs->keyboard_enabled = value; } static void _gs_prefs_set_keyboard_command (GSPrefs *prefs, - const char *value) -{ + const char *value) { g_free (prefs->keyboard_command); prefs->keyboard_command = NULL; - if (value) - { + if (value) { /* FIXME: check command */ prefs->keyboard_command = g_strdup (value); @@ -233,27 +213,23 @@ _gs_prefs_set_keyboard_command (GSPrefs *prefs, static void _gs_prefs_set_status_message_enabled (GSPrefs *prefs, - gboolean enabled) -{ + gboolean enabled) { prefs->status_message_enabled = enabled; } static void _gs_prefs_set_logout_enabled (GSPrefs *prefs, - gboolean value) -{ + gboolean value) { prefs->logout_enabled = value; } static void _gs_prefs_set_logout_command (GSPrefs *prefs, - const char *value) -{ + const char *value) { g_free (prefs->logout_command); prefs->logout_command = NULL; - if (value) - { + if (value) { /* FIXME: check command */ prefs->logout_command = g_strdup (value); @@ -262,8 +238,7 @@ _gs_prefs_set_logout_command (GSPrefs *prefs, static void _gs_prefs_set_logout_timeout (GSPrefs *prefs, - int value) -{ + int value) { if (value < 0) value = 0; @@ -277,39 +252,51 @@ _gs_prefs_set_logout_timeout (GSPrefs *prefs, static void _gs_prefs_set_user_switch_enabled (GSPrefs *prefs, - gboolean value) -{ + gboolean value) { prefs->user_switch_enabled = value; } static void -gs_prefs_load_from_settings (GSPrefs *prefs) -{ +gs_prefs_load_from_settings (GSPrefs *prefs) { glong value; gboolean bvalue; char *string; gchar **strv; gint mode; - bvalue = xfconf_channel_get_bool (prefs->priv->channel, KEY_IDLE_ACTIVATION_ENABLED, DEFAULT_KEY_IDLE_ACTIVATION_ENABLED); + bvalue = xfconf_channel_get_bool (prefs->priv->channel, + KEY_IDLE_ACTIVATION_ENABLED, + DEFAULT_KEY_IDLE_ACTIVATION_ENABLED); _gs_prefs_set_idle_activation_enabled (prefs, bvalue); - bvalue = xfconf_channel_get_bool (prefs->priv->channel, KEY_LOCK_ENABLED, DEFAULT_KEY_LOCK_ENABLED); + bvalue = xfconf_channel_get_bool (prefs->priv->channel, + KEY_LOCK_ENABLED, + DEFAULT_KEY_LOCK_ENABLED); _gs_prefs_set_lock_enabled (prefs, bvalue); - value = xfconf_channel_get_int (prefs->priv->channel, KEY_IDLE_DELAY, DEFAULT_KEY_IDLE_DELAY); + value = xfconf_channel_get_int (prefs->priv->channel, + KEY_IDLE_DELAY, + DEFAULT_KEY_IDLE_DELAY); _gs_prefs_set_timeout (prefs, value); - value = xfconf_channel_get_int (prefs->priv->channel, KEY_POWER_DELAY, DEFAULT_KEY_POWER_DELAY); + value = xfconf_channel_get_int (prefs->priv->channel, + KEY_POWER_DELAY, + DEFAULT_KEY_POWER_DELAY); _gs_prefs_set_power_timeout (prefs, value); - value = xfconf_channel_get_int (prefs->priv->channel, KEY_LOCK_DELAY, DEFAULT_KEY_LOCK_DELAY); + value = xfconf_channel_get_int (prefs->priv->channel, + KEY_LOCK_DELAY, + DEFAULT_KEY_LOCK_DELAY); _gs_prefs_set_lock_timeout (prefs, value); - value = xfconf_channel_get_int (prefs->priv->channel, KEY_CYCLE_DELAY, DEFAULT_KEY_CYCLE_DELAY); + value = xfconf_channel_get_int (prefs->priv->channel, + KEY_CYCLE_DELAY, + DEFAULT_KEY_CYCLE_DELAY); _gs_prefs_set_cycle_timeout (prefs, value); - mode = xfconf_channel_get_int (prefs->priv->channel, KEY_MODE, DEFAULT_KEY_MODE); + mode = xfconf_channel_get_int (prefs->priv->channel, + KEY_MODE, + DEFAULT_KEY_MODE); _gs_prefs_set_mode (prefs, mode); strv = xfconf_channel_get_string_list (prefs->priv->channel, KEY_THEMES); @@ -318,31 +305,45 @@ gs_prefs_load_from_settings (GSPrefs *prefs) /* Embedded keyboard options */ - bvalue = xfconf_channel_get_bool (prefs->priv->channel, KEY_KEYBOARD_ENABLED, DEFAULT_KEY_KEYBOARD_ENABLED); + bvalue = xfconf_channel_get_bool (prefs->priv->channel, + KEY_KEYBOARD_ENABLED, + DEFAULT_KEY_KEYBOARD_ENABLED); _gs_prefs_set_keyboard_enabled (prefs, bvalue); - string = xfconf_channel_get_string (prefs->priv->channel, KEY_KEYBOARD_COMMAND, DEFAULT_KEY_KEYBOARD_COMMAND); + string = xfconf_channel_get_string (prefs->priv->channel, + KEY_KEYBOARD_COMMAND, + DEFAULT_KEY_KEYBOARD_COMMAND); _gs_prefs_set_keyboard_command (prefs, string); g_free (string); - bvalue = xfconf_channel_get_bool (prefs->priv->channel, KEY_STATUS_MESSAGE_ENABLED, DEFAULT_KEY_STATUS_MESSAGE_ENABLED); + bvalue = xfconf_channel_get_bool (prefs->priv->channel, + KEY_STATUS_MESSAGE_ENABLED, + DEFAULT_KEY_STATUS_MESSAGE_ENABLED); _gs_prefs_set_status_message_enabled (prefs, bvalue); /* Logout options */ - bvalue = xfconf_channel_get_bool (prefs->priv->channel, KEY_LOGOUT_ENABLED, DEFAULT_KEY_LOGOUT_ENABLED); + bvalue = xfconf_channel_get_bool (prefs->priv->channel, + KEY_LOGOUT_ENABLED, + DEFAULT_KEY_LOGOUT_ENABLED); _gs_prefs_set_logout_enabled (prefs, bvalue); - string = xfconf_channel_get_string (prefs->priv->channel, KEY_LOGOUT_COMMAND, DEFAULT_KEY_LOGOUT_COMMAND); + string = xfconf_channel_get_string (prefs->priv->channel, + KEY_LOGOUT_COMMAND, + DEFAULT_KEY_LOGOUT_COMMAND); _gs_prefs_set_logout_command (prefs, string); g_free (string); - value = xfconf_channel_get_int (prefs->priv->channel, KEY_LOGOUT_DELAY, DEFAULT_KEY_LOGOUT_DELAY); + value = xfconf_channel_get_int (prefs->priv->channel, + KEY_LOGOUT_DELAY, + DEFAULT_KEY_LOGOUT_DELAY); _gs_prefs_set_logout_timeout (prefs, value); /* User switching options */ - bvalue = xfconf_channel_get_bool (prefs->priv->channel, KEY_USER_SWITCH_ENABLED, DEFAULT_KEY_USER_SWITCH_ENABLED); + bvalue = xfconf_channel_get_bool (prefs->priv->channel, + KEY_USER_SWITCH_ENABLED, + DEFAULT_KEY_USER_SWITCH_ENABLED); _gs_prefs_set_user_switch_enabled (prefs, bvalue); } @@ -350,127 +351,94 @@ static void key_changed_cb (XfconfChannel *channel, gchar *property, GValue *value, - GSPrefs *prefs) -{ - if (strcmp (property, KEY_MODE) == 0) - { + GSPrefs *prefs) { + if (strcmp (property, KEY_MODE) == 0) { gint mode; mode = xfconf_channel_get_int (channel, property, DEFAULT_KEY_MODE); _gs_prefs_set_mode (prefs, mode); - } - else if (strcmp (property, KEY_THEMES) == 0) - { + } else if (strcmp (property, KEY_THEMES) == 0) { gchar **strv = NULL; strv = xfconf_channel_get_string_list (channel, property); _gs_prefs_set_themes (prefs, strv); g_strfreev (strv); - } - else if (strcmp (property, KEY_IDLE_DELAY) == 0) - { + } else if (strcmp (property, KEY_IDLE_DELAY) == 0) { int delay; delay = xfconf_channel_get_int (channel, property, DEFAULT_KEY_IDLE_DELAY); _gs_prefs_set_timeout (prefs, delay); - } - else if (strcmp (property, KEY_POWER_DELAY) == 0) - { + } else if (strcmp (property, KEY_POWER_DELAY) == 0) { int delay; delay = xfconf_channel_get_int (channel, property, DEFAULT_KEY_POWER_DELAY); _gs_prefs_set_power_timeout (prefs, delay); - } - else if (strcmp (property, KEY_LOCK_DELAY) == 0) - { + } else if (strcmp (property, KEY_LOCK_DELAY) == 0) { int delay; delay = xfconf_channel_get_int (channel, property, DEFAULT_KEY_LOCK_DELAY); _gs_prefs_set_lock_timeout (prefs, delay); - } - else if (strcmp (property, KEY_IDLE_ACTIVATION_ENABLED) == 0) - { + } else if (strcmp (property, KEY_IDLE_ACTIVATION_ENABLED) == 0) { gboolean enabled; enabled = xfconf_channel_get_bool (channel, property, DEFAULT_KEY_IDLE_ACTIVATION_ENABLED); _gs_prefs_set_idle_activation_enabled (prefs, enabled); - } - else if (strcmp (property, KEY_LOCK_ENABLED) == 0) - { + } else if (strcmp (property, KEY_LOCK_ENABLED) == 0) { gboolean enabled; enabled = xfconf_channel_get_bool (channel, property, DEFAULT_KEY_LOCK_ENABLED); _gs_prefs_set_lock_enabled (prefs, enabled); - } - else if (strcmp (property, KEY_CYCLE_DELAY) == 0) - { + } else if (strcmp (property, KEY_CYCLE_DELAY) == 0) { int delay; delay = xfconf_channel_get_int (channel, property, DEFAULT_KEY_CYCLE_DELAY); _gs_prefs_set_cycle_timeout (prefs, delay); - } - else if (strcmp (property, KEY_KEYBOARD_ENABLED) == 0) - { + } else if (strcmp (property, KEY_KEYBOARD_ENABLED) == 0) { gboolean enabled; enabled = xfconf_channel_get_bool (channel, property, DEFAULT_KEY_KEYBOARD_ENABLED); _gs_prefs_set_keyboard_enabled (prefs, enabled); - } - else if (strcmp (property, KEY_KEYBOARD_COMMAND) == 0) - { + } else if (strcmp (property, KEY_KEYBOARD_COMMAND) == 0) { char *command; command = xfconf_channel_get_string (channel, property, DEFAULT_KEY_KEYBOARD_COMMAND); _gs_prefs_set_keyboard_command (prefs, command); g_free (command); - } - else if (strcmp (property, KEY_STATUS_MESSAGE_ENABLED) == 0) - { + } else if (strcmp (property, KEY_STATUS_MESSAGE_ENABLED) == 0) { gboolean enabled; enabled = xfconf_channel_get_bool (channel, property, DEFAULT_KEY_STATUS_MESSAGE_ENABLED); _gs_prefs_set_status_message_enabled (prefs, enabled); - } - else if (strcmp (property, KEY_LOGOUT_ENABLED) == 0) - { + } else if (strcmp (property, KEY_LOGOUT_ENABLED) == 0) { gboolean enabled; enabled = xfconf_channel_get_bool (channel, property, DEFAULT_KEY_LOGOUT_ENABLED); _gs_prefs_set_logout_enabled (prefs, enabled); - } - else if (strcmp (property, KEY_LOGOUT_DELAY) == 0) - { + } else if (strcmp (property, KEY_LOGOUT_DELAY) == 0) { int delay; delay = xfconf_channel_get_int (channel, property, DEFAULT_KEY_LOGOUT_DELAY); _gs_prefs_set_logout_timeout (prefs, delay); - } - else if (strcmp (property, KEY_LOGOUT_COMMAND) == 0) - { + } else if (strcmp (property, KEY_LOGOUT_COMMAND) == 0) { char *command; command = xfconf_channel_get_string (channel, property, DEFAULT_KEY_LOGOUT_COMMAND); _gs_prefs_set_logout_command (prefs, command); g_free (command); - } - else if (strcmp (property, KEY_USER_SWITCH_ENABLED) == 0) - { + } else if (strcmp (property, KEY_USER_SWITCH_ENABLED) == 0) { gboolean enabled; enabled = xfconf_channel_get_bool (channel, property, DEFAULT_KEY_USER_SWITCH_ENABLED); _gs_prefs_set_user_switch_enabled (prefs, enabled); - } - else - { + } else { g_warning ("Config key not handled: %s", property); } - g_signal_emit (prefs, signals [CHANGED], 0); + g_signal_emit (prefs, signals[CHANGED], 0); } static void -gs_prefs_init (GSPrefs *prefs) -{ +gs_prefs_init (GSPrefs *prefs) { prefs->priv = gs_prefs_get_instance_private (prefs); prefs->priv->channel = xfconf_channel_get (SETTINGS_XFCONF_CHANNEL); @@ -496,8 +464,7 @@ gs_prefs_init (GSPrefs *prefs) } static void -gs_prefs_finalize (GObject *object) -{ +gs_prefs_finalize (GObject *object) { GSPrefs *prefs; g_return_if_fail (object != NULL); @@ -507,14 +474,12 @@ gs_prefs_finalize (GObject *object) g_return_if_fail (prefs->priv != NULL); - if (prefs->priv->channel) - { + if (prefs->priv->channel) { g_object_unref (prefs->priv->channel); prefs->priv->channel = NULL; } - if (prefs->themes) - { + if (prefs->themes) { g_slist_foreach (prefs->themes, (GFunc)g_free, NULL); g_slist_free (prefs->themes); } @@ -526,8 +491,7 @@ gs_prefs_finalize (GObject *object) } GSPrefs * -gs_prefs_new (void) -{ +gs_prefs_new (void) { GObject *prefs; prefs = g_object_new (GS_TYPE_PREFS, NULL); diff --git a/src/gs-theme-manager.c b/src/gs-theme-manager.c index 6249027ee3a47562428135576757cae11add43ec..567836f9f00533ce6e99e77b5aa5ef4aedd0e443 100644 --- a/src/gs-theme-manager.c +++ b/src/gs-theme-manager.c @@ -21,36 +21,35 @@ * */ -#include "config.h" +#include <config.h> -#include <stdlib.h> #include <stdio.h> - +#include <stdlib.h> #include <string.h> + #ifdef HAVE_UNISTD_H #include <unistd.h> #endif /* HAVE_UNISTD_H */ #include <glib-object.h> + #include <garcon/garcon.h> -#include "gs-theme-manager.h" -#include "gs-debug.h" +#include "src/gs-theme-manager.h" +#include "src/gs-debug.h" static void gs_theme_manager_class_init (GSThemeManagerClass *klass); static void gs_theme_manager_init (GSThemeManager *theme_manager); static void gs_theme_manager_finalize (GObject *object); -struct _GSThemeInfo -{ +struct _GSThemeInfo { char *name; char *exec; char *file_id; guint refcount; }; -struct GSThemeManagerPrivate -{ +struct GSThemeManagerPrivate { GarconMenu *menu; }; @@ -58,8 +57,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (GSThemeManager, gs_theme_manager, G_TYPE_OBJECT) static gpointer theme_manager_object = NULL; -static const char *known_engine_locations [] = -{ +static const char *known_engine_locations[] = { SAVERDIR, #ifdef XSCREENSAVER_HACK_DIR XSCREENSAVER_HACK_DIR, @@ -71,40 +69,31 @@ static const char *known_engine_locations [] = /* Returns the full path to the queried command */ static char * -find_command (const char *command) -{ +find_command (const char *command) { int i; - if (g_path_is_absolute (command)) - { + if (g_path_is_absolute (command)) { char *dirname; dirname = g_path_get_dirname (command); - for (i = 0; known_engine_locations [i]; i++) - { - if (strcmp (dirname, known_engine_locations [i]) == 0) - { + for (i = 0; known_engine_locations[i]; i++) { + if (strcmp (dirname, known_engine_locations[i]) == 0) { if (g_file_test (command, G_FILE_TEST_IS_EXECUTABLE) - && ! g_file_test (command, G_FILE_TEST_IS_DIR)) - { + && !g_file_test (command, G_FILE_TEST_IS_DIR)) { g_free (dirname); return g_strdup (command); } } } g_free (dirname); - } - else - { - for (i = 0; known_engine_locations [i]; i++) - { + } else { + for (i = 0; known_engine_locations[i]; i++) { char *path; - path = g_build_filename (known_engine_locations [i], command, NULL); + path = g_build_filename (known_engine_locations[i], command, NULL); if (g_file_test (path, G_FILE_TEST_IS_EXECUTABLE) - && ! g_file_test (path, G_FILE_TEST_IS_DIR)) - { + && !g_file_test (path, G_FILE_TEST_IS_DIR)) { return path; } @@ -116,19 +105,17 @@ find_command (const char *command) } static gboolean -check_command (const char *command) -{ +check_command (const char *command) { char *path; char **argv; g_return_val_if_fail (command != NULL, FALSE); g_shell_parse_argv (command, NULL, &argv, NULL); - path = find_command (argv [0]); + path = find_command (argv[0]); g_strfreev (argv); - if (path != NULL) - { + if (path != NULL) { g_free (path); return TRUE; } @@ -137,15 +124,13 @@ check_command (const char *command) } static void -add_known_engine_locations_to_path (void) -{ +add_known_engine_locations_to_path (void) { static gboolean already_added; int i; GString *str; /* We only want to add the items to the path once */ - if (already_added) - { + if (already_added) { return; } @@ -154,12 +139,10 @@ add_known_engine_locations_to_path (void) /* TODO: set a default PATH ? */ str = g_string_new (g_getenv ("PATH")); - for (i = 0; known_engine_locations [i]; i++) - { + for (i = 0; known_engine_locations[i]; i++) { /* TODO: check that permissions are safe */ - if (g_file_test (known_engine_locations [i], G_FILE_TEST_IS_DIR)) - { - g_string_append_printf (str, ":%s", known_engine_locations [i]); + if (g_file_test (known_engine_locations[i], G_FILE_TEST_IS_DIR)) { + g_string_append_printf (str, ":%s", known_engine_locations[i]); } } @@ -168,8 +151,7 @@ add_known_engine_locations_to_path (void) } GSThemeInfo * -gs_theme_info_ref (GSThemeInfo *info) -{ +gs_theme_info_ref (GSThemeInfo *info) { g_return_val_if_fail (info != NULL, NULL); g_return_val_if_fail (info->refcount > 0, NULL); @@ -179,13 +161,11 @@ gs_theme_info_ref (GSThemeInfo *info) } void -gs_theme_info_unref (GSThemeInfo *info) -{ +gs_theme_info_unref (GSThemeInfo *info) { g_return_if_fail (info != NULL); g_return_if_fail (info->refcount > 0); - if (--info->refcount == 0) - { + if (--info->refcount == 0) { g_free (info->name); g_free (info->exec); g_free (info->file_id); @@ -195,34 +175,28 @@ gs_theme_info_unref (GSThemeInfo *info) } const char * -gs_theme_info_get_id (GSThemeInfo *info) -{ +gs_theme_info_get_id (GSThemeInfo *info) { g_return_val_if_fail (info != NULL, NULL); return info->file_id; } const char * -gs_theme_info_get_name (GSThemeInfo *info) -{ +gs_theme_info_get_name (GSThemeInfo *info) { g_return_val_if_fail (info != NULL, NULL); return info->name; } const char * -gs_theme_info_get_exec (GSThemeInfo *info) -{ +gs_theme_info_get_exec (GSThemeInfo *info) { const char *exec; g_return_val_if_fail (info != NULL, NULL); - if (check_command (info->exec)) - { + if (check_command (info->exec)) { exec = info->exec; - } - else - { + } else { exec = NULL; } @@ -230,8 +204,7 @@ gs_theme_info_get_exec (GSThemeInfo *info) } static GSThemeInfo * -gs_theme_info_new_from_garcon_menu_item(GarconMenuItem *item) -{ +gs_theme_info_new_from_garcon_menu_item(GarconMenuItem *item) { GSThemeInfo *info; const char *str; char *pos; @@ -245,12 +218,9 @@ gs_theme_info_new_from_garcon_menu_item(GarconMenuItem *item) /* remove the .desktop suffix */ str = garcon_menu_item_get_desktop_id (item); pos = g_strrstr (str, ".desktop"); - if (pos) - { + if (pos) { info->file_id = g_strndup (str, pos - str); - } - else - { + } else { info->file_id = g_strdup (str); } @@ -259,8 +229,7 @@ gs_theme_info_new_from_garcon_menu_item(GarconMenuItem *item) static GSThemeInfo * find_info_for_id (GarconMenu *menu, - const char *id) -{ + const char *id) { GSThemeInfo *info; GList *items; GList *l; @@ -269,16 +238,13 @@ find_info_for_id (GarconMenu *menu, info = NULL; - for (l = items; l; l = l->next) - { - if (info == NULL) - { + for (l = items; l; l = l->next) { + if (info == NULL) { GarconMenuItem *item = l->data; const char *file_id; file_id = garcon_menu_item_get_desktop_id (item); - if (file_id && id && strcmp (file_id, id) == 0) - { + if (file_id && id && strcmp (file_id, id) == 0) { info = gs_theme_info_new_from_garcon_menu_item (item); } } @@ -291,8 +257,7 @@ find_info_for_id (GarconMenu *menu, GSThemeInfo * gs_theme_manager_lookup_theme_info (GSThemeManager *theme_manager, - const char *name) -{ + const char *name) { GSThemeInfo *info; char *id; @@ -308,8 +273,7 @@ gs_theme_manager_lookup_theme_info (GSThemeManager *theme_manager, static void theme_prepend_item (GSList **parent_list, - GarconMenuItem *item) -{ + GarconMenuItem *item) { GSThemeInfo *info; info = gs_theme_info_new_from_garcon_menu_item (item); @@ -319,15 +283,13 @@ theme_prepend_item (GSList **parent_list, static void make_theme_list (GSList **parent_list, - GarconMenu *menu) -{ + GarconMenu *menu) { GList *items; GList *l; items = garcon_menu_get_items (menu); - for (l = items; l; l = l->next) - { + for (l = items; l; l = l->next) { theme_prepend_item (parent_list, l->data); } @@ -337,8 +299,7 @@ make_theme_list (GSList **parent_list, } GSList * -gs_theme_manager_get_info_list (GSThemeManager *theme_manager) -{ +gs_theme_manager_get_info_list (GSThemeManager *theme_manager) { GSList *l = NULL; g_return_val_if_fail (GS_IS_THEME_MANAGER (theme_manager), NULL); @@ -349,16 +310,14 @@ gs_theme_manager_get_info_list (GSThemeManager *theme_manager) } static void -gs_theme_manager_class_init (GSThemeManagerClass *klass) -{ +gs_theme_manager_class_init (GSThemeManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gs_theme_manager_finalize; } static GarconMenu * -get_themes_menu (void) -{ +get_themes_menu (void) { GarconMenu *menu = NULL; gchar *menu_file = g_strconcat(SYSCONFDIR, "/xdg/menus/xfce4-screensavers.menu", NULL); @@ -367,8 +326,7 @@ get_themes_menu (void) add_known_engine_locations_to_path (); menu = garcon_menu_new_for_path (menu_file); - if (!garcon_menu_load (menu, NULL, NULL)) - { + if (!garcon_menu_load (menu, NULL, NULL)) { g_warning("Failed to load menu."); } @@ -376,16 +334,14 @@ get_themes_menu (void) } static void -gs_theme_manager_init (GSThemeManager *theme_manager) -{ +gs_theme_manager_init (GSThemeManager *theme_manager) { theme_manager->priv = gs_theme_manager_get_instance_private (theme_manager); theme_manager->priv->menu = get_themes_menu (); } static void -gs_theme_manager_finalize (GObject *object) -{ +gs_theme_manager_finalize (GObject *object) { GSThemeManager *theme_manager; g_return_if_fail (object != NULL); @@ -395,8 +351,7 @@ gs_theme_manager_finalize (GObject *object) g_return_if_fail (theme_manager->priv != NULL); - if (theme_manager->priv->menu != NULL) - { + if (theme_manager->priv->menu != NULL) { g_object_unref (G_OBJECT(theme_manager->priv->menu)); } @@ -404,14 +359,10 @@ gs_theme_manager_finalize (GObject *object) } GSThemeManager * -gs_theme_manager_new (void) -{ - if (theme_manager_object) - { +gs_theme_manager_new (void) { + if (theme_manager_object) { g_object_ref (theme_manager_object); - } - else - { + } else { theme_manager_object = g_object_new (GS_TYPE_THEME_MANAGER, NULL); g_object_add_weak_pointer (theme_manager_object, (gpointer *) &theme_manager_object); diff --git a/src/gs-visual-gl.c b/src/gs-visual-gl.c index 3f279766ff5a9c2b639ff21279209633f8bb0a7f..e71f48c741a50ea1a5497091f1aed233f0fda847 100644 --- a/src/gs-visual-gl.c +++ b/src/gs-visual-gl.c @@ -21,11 +21,11 @@ * */ -#include "config.h" +#include <config.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> +#include <unistd.h> #include <gdk/gdk.h> #include <gdk/gdkx.h> @@ -35,12 +35,11 @@ #include <GL/glx.h> #endif /* HAVE_GL */ -#include "gs-visual-gl.h" -#include "gs-debug.h" +#include "src/gs-visual-gl.h" +#include "src/gs-debug.h" GdkVisual * -gs_visual_gl_get_best_for_display (GdkDisplay *display) -{ +gs_visual_gl_get_best_for_display (GdkDisplay *display) { GdkVisual *visual; #ifdef HAVE_LIBGL Display *xdisplay; @@ -56,22 +55,21 @@ gs_visual_gl_get_best_for_display (GdkDisplay *display) # define DB GLX_DOUBLEBUFFER # define ST GLX_STENCIL_SIZE - static int attrs [][20] = - { - { GLX_RGBA, R, 8, G, 8, B, 8, D, 8, DB, ST,1, 0 }, /* rgb double, stencil */ - { GLX_RGBA, R, 4, G, 4, B, 4, D, 4, DB, ST,1, 0 }, - { GLX_RGBA, R, 2, G, 2, B, 2, D, 2, DB, ST,1, 0 }, - { GLX_RGBA, R, 8, G, 8, B, 8, D, 8, DB, 0 }, /* rgb double */ - { GLX_RGBA, R, 4, G, 4, B, 4, D, 4, DB, 0 }, - { GLX_RGBA, R, 2, G, 2, B, 2, D, 2, DB, 0 }, - { GLX_RGBA, R, 8, G, 8, B, 8, D, 8, 0 }, /* rgb single */ - { GLX_RGBA, R, 4, G, 4, B, 4, D, 4, 0 }, - { GLX_RGBA, R, 2, G, 2, B, 2, D, 2, 0 }, - { I, 8, D, 8, DB, 0 }, /* cmap double */ - { I, 4, D, 4, DB, 0 }, - { I, 8, D, 8, 0 }, /* cmap single */ - { I, 4, D, 4, 0 }, - { GLX_RGBA, R, 1, G, 1, B, 1, D, 1, 0 } /* monochrome */ + static int attrs[][20] = { + { GLX_RGBA, R, 8, G, 8, B, 8, D, 8, DB, ST, 1, 0 }, /* rgb double, stencil */ + { GLX_RGBA, R, 4, G, 4, B, 4, D, 4, DB, ST, 1, 0 }, + { GLX_RGBA, R, 2, G, 2, B, 2, D, 2, DB, ST, 1, 0 }, + { GLX_RGBA, R, 8, G, 8, B, 8, D, 8, DB, 0 }, /* rgb double */ + { GLX_RGBA, R, 4, G, 4, B, 4, D, 4, DB, 0 }, + { GLX_RGBA, R, 2, G, 2, B, 2, D, 2, DB, 0 }, + { GLX_RGBA, R, 8, G, 8, B, 8, D, 8, 0 }, /* rgb single */ + { GLX_RGBA, R, 4, G, 4, B, 4, D, 4, 0 }, + { GLX_RGBA, R, 2, G, 2, B, 2, D, 2, 0 }, + { I, 8, D, 8, DB, 0 }, /* cmap double */ + { I, 4, D, 4, DB, 0 }, + { I, 8, D, 8, 0 }, /* cmap single */ + { I, 4, D, 4, 0 }, + { GLX_RGBA, R, 1, G, 1, B, 1, D, 1, 0 } /* monochrome */ }; g_return_val_if_fail (display != NULL, NULL); @@ -83,14 +81,12 @@ gs_visual_gl_get_best_for_display (GdkDisplay *display) gdk_x11_display_error_trap_push (display); visual = NULL; - for (i = 0; i < G_N_ELEMENTS (attrs); i++) - { + for (i = 0; i < G_N_ELEMENTS (attrs); i++) { XVisualInfo *vi; - vi = glXChooseVisual (xdisplay, screen_num, attrs [i]); + vi = glXChooseVisual (xdisplay, screen_num, attrs[i]); - if (vi != NULL) - { + if (vi != NULL) { VisualID vid; vid = XVisualIDFromVisual (vi->visual); @@ -99,8 +95,7 @@ gs_visual_gl_get_best_for_display (GdkDisplay *display) XFree (vi); - if (visual != NULL) - { + if (visual != NULL) { break; } } diff --git a/src/gs-window-x11.c b/src/gs-window-x11.c index a1d25f01f2ed095379e665797949fa9c5cd4fc8c..9dfeb9169ea6dd00410b1320b1482c1c05e1bc47 100644 --- a/src/gs-window-x11.c +++ b/src/gs-window-x11.c @@ -21,27 +21,27 @@ * */ -#include "config.h" +#include <config.h> -#include <sys/types.h> #include <errno.h> -#include <sys/wait.h> #include <string.h> +#include <sys/types.h> +#include <sys/wait.h> #include <gdk/gdkx.h> #include <gdk/gdkkeysyms.h> #include <gtk/gtk.h> #include <gtk/gtkx.h> -#include "gs-window.h" -#include "gs-marshal.h" -#include "subprocs.h" -#include "gs-debug.h" - #ifdef HAVE_SHAPE_EXT #include <X11/extensions/shape.h> #endif +#include "src/gs-debug.h" +#include "src/gs-marshal.h" +#include "src/gs-window.h" +#include "src/subprocs.h" + static void gs_window_class_init (GSWindowClass *klass); static void gs_window_init (GSWindow *window); static void gs_window_finalize (GObject *object); @@ -50,8 +50,7 @@ static gboolean popup_dialog_idle (GSWindow *window); static void gs_window_dialog_finish (GSWindow *window); static void remove_command_watches (GSWindow *window); -enum -{ +enum { DIALOG_RESPONSE_CANCEL, DIALOG_RESPONSE_OK }; @@ -59,19 +58,18 @@ enum #define MAX_QUEUED_EVENTS 16 #define INFO_BAR_SECONDS 30 -struct GSWindowPrivate -{ +struct GSWindowPrivate { GdkMonitor *monitor; GdkRectangle geometry; guint obscured : 1; guint dialog_up : 1; - + guint lock_enabled : 1; guint user_switch_enabled : 1; guint logout_enabled : 1; guint keyboard_enabled : 1; - + guint64 logout_timeout; char *logout_command; char *keyboard_command; @@ -117,15 +115,13 @@ struct GSWindowPrivate #endif }; -enum -{ +enum { ACTIVITY, DEACTIVATED, LAST_SIGNAL }; -enum -{ +enum { PROP_0, PROP_OBSCURED, PROP_DIALOG_UP, @@ -139,42 +135,36 @@ enum PROP_STATUS_MESSAGE }; -static guint signals [LAST_SIGNAL] = { 0, }; +static guint signals[LAST_SIGNAL] = { 0, }; G_DEFINE_TYPE_WITH_PRIVATE (GSWindow, gs_window, GTK_TYPE_WINDOW) static void set_invisible_cursor (GdkWindow *window, - gboolean invisible) -{ + gboolean invisible) { GdkDisplay *display; GdkCursor *cursor = NULL; - if (invisible) - { + if (invisible) { display = gdk_window_get_display (window); cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR); } gdk_window_set_cursor (window, cursor); - if (cursor) - { + if (cursor) { g_object_unref (cursor); } } /* derived from tomboy */ static void -gs_window_override_user_time (GSWindow *window) -{ +gs_window_override_user_time (GSWindow *window) { guint32 ev_time = gtk_get_current_event_time (); - if (ev_time == 0) - { + if (ev_time == 0) { gint ev_mask = gtk_widget_get_events (GTK_WIDGET (window)); - if (!(ev_mask & GDK_PROPERTY_CHANGE_MASK)) - { + if (!(ev_mask & GDK_PROPERTY_CHANGE_MASK)) { gtk_widget_add_events (GTK_WIDGET (window), GDK_PROPERTY_CHANGE_MASK); } @@ -190,8 +180,7 @@ gs_window_override_user_time (GSWindow *window) } static void -clear_children (Window window) -{ +clear_children (Window window) { Window root; Window parent; Window *children; @@ -199,24 +188,21 @@ clear_children (Window window) int status; children = NULL; - status = XQueryTree (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), window, &root, &parent, &children, &n_children); + status = XQueryTree (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), + window, &root, &parent, &children, &n_children); - if (status == 0) - { - if (children) - { + if (status == 0) { + if (children) { XFree (children); } return; } - if (children) - { - while (n_children) - { + if (children) { + while (n_children) { Window child; - child = children [--n_children]; + child = children[--n_children]; XClearWindow (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), child); @@ -228,8 +214,7 @@ clear_children (Window window) } static void -widget_clear_all_children (GtkWidget *widget) -{ +widget_clear_all_children (GtkWidget *widget) { GdkWindow *w; GdkDisplay *display; @@ -247,18 +232,15 @@ widget_clear_all_children (GtkWidget *widget) void gs_window_set_background_surface (GSWindow *window, - cairo_surface_t *surface) -{ + cairo_surface_t *surface) { g_return_if_fail (GS_IS_WINDOW (window)); - if (window->priv->background_surface != NULL) - { + if (window->priv->background_surface != NULL) { cairo_surface_destroy (window->priv->background_surface); } window->priv->background_surface = NULL; - if (surface != NULL) - { + if (surface != NULL) { window->priv->background_surface = cairo_surface_reference (surface); } @@ -266,23 +248,20 @@ gs_window_set_background_surface (GSWindow *window, } void -gs_window_clear (GSWindow *window) -{ +gs_window_clear (GSWindow *window) { GdkDisplay *display; g_return_if_fail (GS_IS_WINDOW (window)); gs_debug ("Clearing widgets"); - if (gtk_widget_get_realized (GTK_WIDGET (window))) - { + if (gtk_widget_get_realized (GTK_WIDGET (window))) { gtk_widget_queue_draw (GTK_WIDGET (window)); /* If a screensaver theme adds child windows we need to clear them too */ widget_clear_all_children (GTK_WIDGET (window)); } - if (gtk_widget_get_realized (window->priv->drawing_area)) - { + if (gtk_widget_get_realized (window->priv->drawing_area)) { gtk_widget_queue_draw (window->priv->drawing_area); widget_clear_all_children (window->priv->drawing_area); } @@ -292,8 +271,7 @@ gs_window_clear (GSWindow *window) } static cairo_region_t * -get_outside_region (GSWindow *window) -{ +get_outside_region (GSWindow *window) { GdkDisplay *display; int i; int num_monitors; @@ -304,12 +282,10 @@ get_outside_region (GSWindow *window) region = cairo_region_create (); num_monitors = gdk_display_get_n_monitors (display); - for (i = 0; i < num_monitors; i++) - { + for (i = 0; i < num_monitors; i++) { GdkMonitor *mon = gdk_display_get_monitor (display, i); - if (mon != window->priv->monitor) - { + if (mon != window->priv->monitor) { GdkRectangle geometry; cairo_rectangle_int_t rectangle; @@ -319,9 +295,7 @@ get_outside_region (GSWindow *window) rectangle.width = geometry.width; rectangle.height = geometry.height; cairo_region_union_rectangle (region, &rectangle); - } - else - { + } else { break; } } @@ -330,8 +304,7 @@ get_outside_region (GSWindow *window) } static void -update_geometry (GSWindow *window) -{ +update_geometry (GSWindow *window) { GdkRectangle geometry; cairo_region_t *outside_region; cairo_region_t *monitor_region; @@ -366,8 +339,7 @@ update_geometry (GSWindow *window) static void monitor_geometry_notify (GdkMonitor *monitor, GParamSpec *pspec, - GSWindow *window) -{ + GSWindow *window) { gs_debug ("Got monitor geometry notify signal"); gtk_widget_queue_resize (GTK_WIDGET (window)); } @@ -376,8 +348,7 @@ monitor_geometry_notify (GdkMonitor *monitor, static void gs_window_move_resize_window (GSWindow *window, gboolean move, - gboolean resize) -{ + gboolean resize) { GtkWidget *widget; GdkWindow *gdkwindow; @@ -392,22 +363,17 @@ gs_window_move_resize_window (GSWindow *window, window->priv->geometry.width, window->priv->geometry.height); - if (move && resize) - { + if (move && resize) { gdk_window_move_resize (gdkwindow, window->priv->geometry.x, window->priv->geometry.y, window->priv->geometry.width, window->priv->geometry.height); - } - else if (move) - { + } else if (move) { gdk_window_move (gdkwindow, window->priv->geometry.x, window->priv->geometry.y); - } - else if (resize) - { + } else if (resize) { gdk_window_resize (gdkwindow, window->priv->geometry.width, window->priv->geometry.height); @@ -415,15 +381,13 @@ gs_window_move_resize_window (GSWindow *window, } static void -gs_window_real_unrealize (GtkWidget *widget) -{ +gs_window_real_unrealize (GtkWidget *widget) { GdkMonitor *monitor = GS_WINDOW (widget)->priv->monitor; g_signal_handlers_disconnect_by_func (monitor, monitor_geometry_notify, widget); - if (GTK_WIDGET_CLASS (gs_window_parent_class)->unrealize) - { + if (GTK_WIDGET_CLASS (gs_window_parent_class)->unrealize) { GTK_WIDGET_CLASS (gs_window_parent_class)->unrealize (widget); } } @@ -433,8 +397,7 @@ extern char **environ; static gchar ** spawn_make_environment_for_display (GdkDisplay *display, - gchar **envp) -{ + gchar **envp) { gchar **retval = NULL; const gchar *display_name; gint display_index = -1; @@ -471,16 +434,14 @@ spawn_command_line_on_display_sync (GdkDisplay *display, char **standard_output, char **standard_error, int *exit_status, - GError **error) -{ + GError **error) { char **argv = NULL; char **envp = NULL; gboolean retval; g_return_val_if_fail (command_line != NULL, FALSE); - if (! g_shell_parse_argv (command_line, NULL, &argv, error)) - { + if (!g_shell_parse_argv (command_line, NULL, &argv, error)) { return FALSE; } @@ -504,8 +465,7 @@ spawn_command_line_on_display_sync (GdkDisplay *display, } static GdkVisual * -get_best_visual_for_display (GdkDisplay *display) -{ +get_best_visual_for_display (GdkDisplay *display) { GdkScreen *screen; char *command; char *std_output; @@ -529,17 +489,14 @@ get_best_visual_for_display (GdkDisplay *display) NULL, &exit_status, &error); - if (! res) - { + if (!res) { gs_debug ("Could not run command '%s': %s", command, error->message); g_error_free (error); goto out; } - if (1 == sscanf (std_output, "0x%lx %c", &v, &c)) - { - if (v != 0) - { + if (1 == sscanf (std_output, "0x%lx %c", &v, &c)) { + if (v != 0) { VisualID visual_id; visual_id = (VisualID) v; @@ -558,29 +515,25 @@ out: } static void -widget_set_best_visual (GtkWidget *widget) -{ +widget_set_best_visual (GtkWidget *widget) { GdkVisual *visual; g_return_if_fail (widget != NULL); visual = get_best_visual_for_display (gtk_widget_get_display (widget)); - if (visual != NULL) - { + if (visual != NULL) { gtk_widget_set_visual (widget, visual); g_object_unref (visual); } } static void -gs_window_real_realize (GtkWidget *widget) -{ +gs_window_real_realize (GtkWidget *widget) { GdkMonitor *monitor = GS_WINDOW (widget)->priv->monitor; widget_set_best_visual (widget); - if (GTK_WIDGET_CLASS (gs_window_parent_class)->realize) - { + if (GTK_WIDGET_CLASS (gs_window_parent_class)->realize) { GTK_WIDGET_CLASS (gs_window_parent_class)->realize (widget); } @@ -597,8 +550,7 @@ gs_window_real_realize (GtkWidget *widget) /* every so often we should raise the window in case another window has somehow gotten on top */ static gboolean -watchdog_timer (GSWindow *window) -{ +watchdog_timer (GSWindow *window) { GtkWidget *widget = GTK_WIDGET (window); gdk_window_focus (gtk_widget_get_window (widget), GDK_CURRENT_TIME); @@ -607,10 +559,8 @@ watchdog_timer (GSWindow *window) } static void -remove_watchdog_timer (GSWindow *window) -{ - if (window->priv->watchdog_timer_id != 0) - { +remove_watchdog_timer (GSWindow *window) { + if (window->priv->watchdog_timer_id != 0) { g_source_remove (window->priv->watchdog_timer_id); window->priv->watchdog_timer_id = 0; } @@ -618,46 +568,39 @@ remove_watchdog_timer (GSWindow *window) static void add_watchdog_timer (GSWindow *window, - glong timeout) -{ + glong timeout) { window->priv->watchdog_timer_id = g_timeout_add (timeout, (GSourceFunc)watchdog_timer, window); } static void -remove_popup_dialog_idle (GSWindow *window) -{ - if (window->priv->popup_dialog_idle_id != 0) - { +remove_popup_dialog_idle (GSWindow *window) { + if (window->priv->popup_dialog_idle_id != 0) { g_source_remove (window->priv->popup_dialog_idle_id); window->priv->popup_dialog_idle_id = 0; } } static void -add_popup_dialog_idle (GSWindow *window) -{ +add_popup_dialog_idle (GSWindow *window) { window->priv->popup_dialog_idle_id = g_idle_add ((GSourceFunc)popup_dialog_idle, window); } static gboolean -emit_deactivated_idle (GSWindow *window) -{ - g_signal_emit (window, signals [DEACTIVATED], 0); +emit_deactivated_idle (GSWindow *window) { + g_signal_emit (window, signals[DEACTIVATED], 0); return FALSE; } static void -add_emit_deactivated_idle (GSWindow *window) -{ +add_emit_deactivated_idle (GSWindow *window) { g_idle_add ((GSourceFunc)emit_deactivated_idle, window); } static void -gs_window_raise (GSWindow *window) -{ +gs_window_raise (GSWindow *window) { GdkWindow *win; g_return_if_fail (GS_IS_WINDOW (window)); @@ -670,16 +613,14 @@ gs_window_raise (GSWindow *window) } static gboolean -x11_window_is_ours (Window window) -{ +x11_window_is_ours (Window window) { GdkWindow *gwindow; gboolean ret; ret = FALSE; gwindow = gdk_x11_window_lookup_for_display (gdk_display_get_default (), window); - if (gwindow && (window != GDK_ROOT_WINDOW ())) - { + if (gwindow && (window != GDK_ROOT_WINDOW ())) { ret = TRUE; } @@ -688,8 +629,7 @@ x11_window_is_ours (Window window) #ifdef HAVE_SHAPE_EXT static void -unshape_window (GSWindow *window) -{ +unshape_window (GSWindow *window) { gdk_window_shape_combine_region (gtk_widget_get_window (GTK_WIDGET (window)), NULL, 0, @@ -699,26 +639,21 @@ unshape_window (GSWindow *window) static void gs_window_xevent (GSWindow *window, - GdkXEvent *xevent) -{ + GdkXEvent *xevent) { XEvent *ev; ev = xevent; /* MapNotify is used to tell us when new windows are mapped. ConfigureNofify is used to tell us when windows are raised. */ - switch (ev->xany.type) - { + switch (ev->xany.type) { case MapNotify: { XMapEvent *xme = &ev->xmap; - if (! x11_window_is_ours (xme->window)) - { + if (!x11_window_is_ours (xme->window)) { gs_window_raise (window); - } - else - { + } else { gs_debug ("not raising our windows"); } @@ -728,12 +663,9 @@ gs_window_xevent (GSWindow *window, { XConfigureEvent *xce = &ev->xconfigure; - if (! x11_window_is_ours (xce->window)) - { + if (!x11_window_is_ours (xce->window)) { gs_window_raise (window); - } - else - { + } else { gs_debug ("not raising our windows"); } @@ -742,8 +674,7 @@ gs_window_xevent (GSWindow *window, default: /* extension events */ #ifdef HAVE_SHAPE_EXT - if (ev->xany.type == (window->priv->shape_event_base + ShapeNotify)) - { + if (ev->xany.type == (window->priv->shape_event_base + ShapeNotify)) { /*XShapeEvent *xse = (XShapeEvent *) ev;*/ unshape_window (window); gs_debug ("Window was reshaped!"); @@ -752,22 +683,19 @@ gs_window_xevent (GSWindow *window, break; } - } static GdkFilterReturn xevent_filter (GdkXEvent *xevent, GdkEvent *event, - GSWindow *window) -{ + GSWindow *window) { gs_window_xevent (window, xevent); return GDK_FILTER_CONTINUE; } static void -select_popup_events (void) -{ +select_popup_events (void) { XWindowAttributes attr; unsigned long events; GdkDisplay *display; @@ -786,8 +714,7 @@ select_popup_events (void) } static void -window_select_shape_events (GSWindow *window) -{ +window_select_shape_events (GSWindow *window) { #ifdef HAVE_SHAPE_EXT unsigned long events; int shape_error_base; @@ -799,7 +726,9 @@ window_select_shape_events (GSWindow *window) if (XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display), &window->priv->shape_event_base, &shape_error_base)) { events = ShapeNotifyMask; - XShapeSelectInput (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (window))), events); + XShapeSelectInput (GDK_DISPLAY_XDISPLAY (display), + GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (window))), + events); } gdk_x11_display_error_trap_pop_ignored (display); @@ -808,18 +737,14 @@ window_select_shape_events (GSWindow *window) static gboolean gs_window_real_draw (GtkWidget *widget, - cairo_t *cr) -{ + cairo_t *cr) { GSWindow *window = GS_WINDOW (widget); cairo_surface_t *bg_surface = window->priv->background_surface; cairo_set_operator (cr, CAIRO_OPERATOR_OVER); - if (bg_surface != NULL) - { + if (bg_surface != NULL) { cairo_set_source_surface (cr, bg_surface, 0, 0); - } - else - { + } else { cairo_set_source_rgb (cr, 0, 0, 0); } cairo_paint (cr); @@ -828,12 +753,10 @@ gs_window_real_draw (GtkWidget *widget, } static void -gs_window_real_show (GtkWidget *widget) -{ +gs_window_real_show (GtkWidget *widget) { GSWindow *window; - if (GTK_WIDGET_CLASS (gs_window_parent_class)->show) - { + if (GTK_WIDGET_CLASS (gs_window_parent_class)->show) { GTK_WIDGET_CLASS (gs_window_parent_class)->show (widget); } @@ -842,8 +765,7 @@ gs_window_real_show (GtkWidget *widget) set_invisible_cursor (gtk_widget_get_window (widget), TRUE); window = GS_WINDOW (widget); - if (window->priv->timer) - { + if (window->priv->timer) { g_timer_destroy (window->priv->timer); } window->priv->timer = g_timer_new (); @@ -860,8 +782,7 @@ static void set_info_text_and_icon (GSWindow *window, const char *icon_name, const char *primary_text, - const char *secondary_text) -{ + const char *secondary_text) { GtkWidget *content_area; GtkWidget *hbox_content; GtkWidget *image; @@ -892,8 +813,7 @@ set_info_text_and_icon (GSWindow *window, gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); gtk_widget_set_halign (primary_label, GTK_ALIGN_START); - if (secondary_text != NULL) - { + if (secondary_text != NULL) { secondary_markup = g_strdup_printf ("<small>%s</small>", secondary_text); secondary_label = gtk_label_new (secondary_markup); @@ -907,8 +827,7 @@ set_info_text_and_icon (GSWindow *window, /* remove old content */ content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (window->priv->info_bar)); - if (window->priv->info_content != NULL) - { + if (window->priv->info_content != NULL) { gtk_container_remove (GTK_CONTAINER (content_area), window->priv->info_content); } gtk_box_pack_start (GTK_BOX (content_area), @@ -918,8 +837,7 @@ set_info_text_and_icon (GSWindow *window, } static gboolean -info_bar_timeout (GSWindow *window) -{ +info_bar_timeout (GSWindow *window) { window->priv->info_bar_timer_id = 0; gtk_widget_hide (window->priv->info_bar); return FALSE; @@ -929,8 +847,7 @@ void gs_window_show_message (GSWindow *window, const char *summary, const char *body, - const char *icon) -{ + const char *icon) { g_return_if_fail (GS_IS_WINDOW (window)); set_info_text_and_icon (window, @@ -939,8 +856,7 @@ gs_window_show_message (GSWindow *window, body); gtk_widget_show (window->priv->info_bar); - if (window->priv->info_bar_timer_id > 0) - { + if (window->priv->info_bar_timer_id > 0) { g_source_remove (window->priv->info_bar_timer_id); } @@ -950,16 +866,14 @@ gs_window_show_message (GSWindow *window, } void -gs_window_show (GSWindow *window) -{ +gs_window_show (GSWindow *window) { g_return_if_fail (GS_IS_WINDOW (window)); gtk_widget_show (GTK_WIDGET (window)); } static void -gs_window_real_hide (GtkWidget *widget) -{ +gs_window_real_hide (GtkWidget *widget) { GSWindow *window; window = GS_WINDOW (widget); @@ -968,15 +882,13 @@ gs_window_real_hide (GtkWidget *widget) remove_watchdog_timer (window); - if (GTK_WIDGET_CLASS (gs_window_parent_class)->hide) - { + if (GTK_WIDGET_CLASS (gs_window_parent_class)->hide) { GTK_WIDGET_CLASS (gs_window_parent_class)->hide (widget); } } void -gs_window_destroy (GSWindow *window) -{ +gs_window_destroy (GSWindow *window) { g_return_if_fail (GS_IS_WINDOW (window)); gs_window_cancel_unlock_request (window); @@ -985,16 +897,14 @@ gs_window_destroy (GSWindow *window) } GdkWindow * -gs_window_get_gdk_window (GSWindow *window) -{ +gs_window_get_gdk_window (GSWindow *window) { g_return_val_if_fail (GS_IS_WINDOW (window), NULL); return gtk_widget_get_window (GTK_WIDGET (window)); } GtkWidget * -gs_window_get_drawing_area (GSWindow *window) -{ +gs_window_get_drawing_area (GSWindow *window) { g_return_val_if_fail (GS_IS_WINDOW (window), NULL); return window->priv->drawing_area; @@ -1004,12 +914,10 @@ gs_window_get_drawing_area (GSWindow *window) static gboolean error_watch (GIOChannel *source, GIOCondition condition, - gpointer data) -{ + gpointer data) { gboolean finished = FALSE; - if (condition & G_IO_IN) - { + if (condition & G_IO_IN) { GIOStatus status; GError *error = NULL; char *line; @@ -1017,8 +925,7 @@ error_watch (GIOChannel *source, line = NULL; status = g_io_channel_read_line (source, &line, NULL, NULL, &error); - switch (status) - { + switch (status) { case G_IO_STATUS_NORMAL: gs_debug ("command error output: %s", line); break; @@ -1035,14 +942,11 @@ error_watch (GIOChannel *source, break; } g_free (line); - } - else if (condition & G_IO_HUP) - { + } else if (condition & G_IO_HUP) { finished = TRUE; } - if (finished) - { + if (finished) { return FALSE; } @@ -1055,8 +959,7 @@ spawn_on_window (GSWindow *window, int *pid, GIOFunc watch_func, gpointer user_data, - gint *watch_id) -{ + gint *watch_id) { int argc; char **argv; char **envp; @@ -1069,8 +972,7 @@ spawn_on_window (GSWindow *window, int id; error = NULL; - if (! g_shell_parse_argv (command, &argc, &argv, &error)) - { + if (!g_shell_parse_argv (command, &argc, &argv, &error)) { gs_debug ("Could not parse command: %s", error->message); g_error_free (error); return FALSE; @@ -1090,20 +992,16 @@ spawn_on_window (GSWindow *window, &standard_error, &error); - if (! result) - { + if (!result) { gs_debug ("Could not start command '%s': %s", command, error->message); g_error_free (error); g_strfreev (argv); return FALSE; } - if (pid != NULL) - { + if (pid != NULL) { *pid = child_pid; - } - else - { + } else { g_spawn_close_pid (child_pid); } @@ -1117,8 +1015,7 @@ spawn_on_window (GSWindow *window, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, watch_func, user_data); - if (watch_id != NULL) - { + if (watch_id != NULL) { *watch_id = id; } g_io_channel_unref (channel); @@ -1143,15 +1040,13 @@ spawn_on_window (GSWindow *window, static void lock_plug_added (GtkWidget *widget, - GSWindow *window) -{ + GSWindow *window) { gtk_widget_show (widget); } static gboolean lock_plug_removed (GtkWidget *widget, - GSWindow *window) -{ + GSWindow *window) { gtk_widget_hide (widget); gtk_container_remove (GTK_CONTAINER (window->priv->vbox), GTK_WIDGET (window->priv->lock_box)); window->priv->lock_box = NULL; @@ -1161,15 +1056,13 @@ lock_plug_removed (GtkWidget *widget, static void keyboard_plug_added (GtkWidget *widget, - GSWindow *window) -{ + GSWindow *window) { gtk_widget_show (widget); } static gboolean keyboard_plug_removed (GtkWidget *widget, - GSWindow *window) -{ + GSWindow *window) { gtk_widget_hide (widget); gtk_container_remove (GTK_CONTAINER (window->priv->vbox), GTK_WIDGET (window->priv->keyboard_socket)); @@ -1178,8 +1071,7 @@ keyboard_plug_removed (GtkWidget *widget, static void keyboard_socket_destroyed (GtkWidget *widget, - GSWindow *window) -{ + GSWindow *window) { g_signal_handlers_disconnect_by_func (widget, keyboard_socket_destroyed, window); g_signal_handlers_disconnect_by_func (widget, keyboard_plug_added, window); g_signal_handlers_disconnect_by_func (widget, keyboard_plug_removed, window); @@ -1188,12 +1080,10 @@ keyboard_socket_destroyed (GtkWidget *widget, } static void -forward_key_events (GSWindow *window) -{ +forward_key_events (GSWindow *window) { window->priv->key_events = g_list_reverse (window->priv->key_events); - while (window->priv->key_events != NULL) - { + while (window->priv->key_events != NULL) { GdkEventKey *event = window->priv->key_events->data; gtk_window_propagate_key_event (GTK_WINDOW (window), event); @@ -1205,12 +1095,10 @@ forward_key_events (GSWindow *window) } static void -remove_key_events (GSWindow *window) -{ +remove_key_events (GSWindow *window) { window->priv->key_events = g_list_reverse (window->priv->key_events); - while (window->priv->key_events) - { + while (window->priv->key_events) { GdkEventKey *event = window->priv->key_events->data; gdk_event_free ((GdkEvent *)event); @@ -1221,8 +1109,7 @@ remove_key_events (GSWindow *window) static void lock_socket_show (GtkWidget *widget, - GSWindow *window) -{ + GSWindow *window) { gtk_widget_child_focus (window->priv->lock_socket, GTK_DIR_TAB_FORWARD); /* send queued events to the dialog */ @@ -1231,8 +1118,7 @@ lock_socket_show (GtkWidget *widget, static void lock_socket_destroyed (GtkWidget *widget, - GSWindow *window) -{ + GSWindow *window) { g_signal_handlers_disconnect_by_func (widget, lock_socket_show, window); g_signal_handlers_disconnect_by_func (widget, lock_socket_destroyed, window); g_signal_handlers_disconnect_by_func (widget, lock_plug_added, window); @@ -1243,8 +1129,7 @@ lock_socket_destroyed (GtkWidget *widget, static void create_keyboard_socket (GSWindow *window, - guint32 id) -{ + guint32 id) { int height; height = (HeightOfScreen (gdk_x11_screen_get_xscreen (gtk_widget_get_screen (GTK_WIDGET (window))))) / 4; @@ -1264,23 +1149,16 @@ create_keyboard_socket (GSWindow *window, /* adapted from gspawn.c */ static int -wait_on_child (int pid) -{ +wait_on_child (int pid) { int status; wait_again: - if (waitpid (pid, &status, 0) < 0) - { - if (errno == EINTR) - { + if (waitpid (pid, &status, 0) < 0) { + if (errno == EINTR) { goto wait_again; - } - else if (errno == ECHILD) - { - ; /* do nothing, child already reaped */ - } - else - { + } else if (errno == ECHILD) { + /* do nothing, child already reaped */ + } else { gs_debug ("waitpid () should not fail in 'GSWindow'"); } } @@ -1289,28 +1167,23 @@ wait_again: } static void -kill_keyboard_command (GSWindow *window) -{ - if (window->priv->keyboard_pid > 0) - { +kill_keyboard_command (GSWindow *window) { + if (window->priv->keyboard_pid > 0) { signal_pid (window->priv->keyboard_pid, SIGTERM); } } static void -kill_dialog_command (GSWindow *window) -{ +kill_dialog_command (GSWindow *window) { /* If a dialog is up we need to signal it and wait on it */ - if (window->priv->lock_pid > 0) - { + if (window->priv->lock_pid > 0) { signal_pid (window->priv->lock_pid, SIGTERM); } } static void -keyboard_command_finish (GSWindow *window) -{ +keyboard_command_finish (GSWindow *window) { g_return_if_fail (GS_IS_WINDOW (window)); /* send a signal just in case */ @@ -1318,8 +1191,7 @@ keyboard_command_finish (GSWindow *window) gs_debug ("Keyboard finished"); - if (window->priv->keyboard_pid > 0) - { + if (window->priv->keyboard_pid > 0) { wait_on_child (window->priv->keyboard_pid); g_spawn_close_pid (window->priv->keyboard_pid); @@ -1330,14 +1202,12 @@ keyboard_command_finish (GSWindow *window) static gboolean keyboard_command_watch (GIOChannel *source, GIOCondition condition, - GSWindow *window) -{ + GSWindow *window) { gboolean finished = FALSE; g_return_val_if_fail (GS_IS_WINDOW (window), FALSE); - if (condition & G_IO_IN) - { + if (condition & G_IO_IN) { GIOStatus status; GError *error = NULL; char *line; @@ -1345,15 +1215,13 @@ keyboard_command_watch (GIOChannel *source, line = NULL; status = g_io_channel_read_line (source, &line, NULL, NULL, &error); - switch (status) - { + switch (status) { case G_IO_STATUS_NORMAL: { guint32 id; char c; gs_debug ("keyboard command output: %s", line); - if (1 == sscanf (line, " %" G_GUINT32_FORMAT " %c", &id, &c)) - { + if (1 == sscanf (line, " %" G_GUINT32_FORMAT " %c", &id, &c)) { create_keyboard_socket (window, id); } } @@ -1372,14 +1240,11 @@ keyboard_command_watch (GIOChannel *source, } g_free (line); - } - else if (condition & G_IO_HUP) - { + } else if (condition & G_IO_HUP) { finished = TRUE; } - if (finished) - { + if (finished) { window->priv->keyboard_watch_id = 0; keyboard_command_finish (window); return FALSE; @@ -1389,11 +1254,10 @@ keyboard_command_watch (GIOChannel *source, } static void -embed_keyboard (GSWindow *window) -{ +embed_keyboard (GSWindow *window) { gboolean res; - if (! window->priv->keyboard_enabled + if (!window->priv->keyboard_enabled || window->priv->keyboard_command == NULL) return; @@ -1409,16 +1273,14 @@ embed_keyboard (GSWindow *window) (GIOFunc)keyboard_command_watch, window, &window->priv->keyboard_watch_id); - if (! res) - { + if (!res) { gs_debug ("Could not start command: %s", window->priv->keyboard_command); } } static void create_lock_socket (GSWindow *window, - guint32 id) -{ + guint32 id) { window->priv->lock_socket = gtk_socket_new (); window->priv->lock_box = gtk_grid_new (); gtk_widget_set_halign (GTK_WIDGET (window->priv->lock_box), @@ -1441,15 +1303,13 @@ create_lock_socket (GSWindow *window, gtk_socket_add_id (GTK_SOCKET (window->priv->lock_socket), id); - if (window->priv->keyboard_enabled) - { + if (window->priv->keyboard_enabled) { embed_keyboard (window); } } static void -gs_window_dialog_finish (GSWindow *window) -{ +gs_window_dialog_finish (GSWindow *window) { g_return_if_fail (GS_IS_WINDOW (window)); gs_debug ("Dialog finished"); @@ -1460,8 +1320,7 @@ gs_window_dialog_finish (GSWindow *window) /* send a signal just in case */ kill_dialog_command (window); - if (window->priv->lock_pid > 0) - { + if (window->priv->lock_pid > 0) { wait_on_child (window->priv->lock_pid); g_spawn_close_pid (window->priv->lock_pid); @@ -1473,40 +1332,32 @@ gs_window_dialog_finish (GSWindow *window) } static void -maybe_kill_dialog (GSWindow *window) -{ +maybe_kill_dialog (GSWindow *window) { if (!window->priv->dialog_shake_in_progress && window->priv->dialog_quit_requested - && window->priv->lock_pid > 0) - { + && window->priv->lock_pid > 0) { kill (window->priv->lock_pid, SIGTERM); } } /* very rudimentary animation for indicating an auth failure */ static void -shake_dialog (GSWindow *window) -{ +shake_dialog (GSWindow *window) { int i; guint start, end; window->priv->dialog_shake_in_progress = TRUE; - for (i = 0; i < 8; i++) - { - if (i % 2 == 0) - { + for (i = 0; i < 8; i++) { + if (i % 2 == 0) { start = 30; end = 0; - } - else - { + } else { start = 0; end = 30; } - if (! window->priv->lock_box) - { + if (!window->priv->lock_box) { break; } @@ -1515,8 +1366,7 @@ shake_dialog (GSWindow *window) gtk_widget_set_margin_end (GTK_WIDGET (window->priv->lock_box), end); - while (gtk_events_pending ()) - { + while (gtk_events_pending ()) { gtk_main_iteration (); } @@ -1529,10 +1379,8 @@ shake_dialog (GSWindow *window) static void window_set_dialog_up (GSWindow *window, - gboolean dialog_up) -{ - if (window->priv->dialog_up == dialog_up) - { + gboolean dialog_up) { + if (window->priv->dialog_up == dialog_up) { return; } @@ -1541,8 +1389,7 @@ window_set_dialog_up (GSWindow *window, } static void -popdown_dialog (GSWindow *window) -{ +popdown_dialog (GSWindow *window) { gs_window_dialog_finish (window); gtk_widget_show (window->priv->drawing_area); @@ -1556,8 +1403,7 @@ popdown_dialog (GSWindow *window) window->priv->last_x = -1; window->priv->last_y = -1; - if (window->priv->lock_box != NULL) - { + if (window->priv->lock_box != NULL) { gtk_container_remove (GTK_CONTAINER (window->priv->vbox), GTK_WIDGET (window->priv->lock_box)); window->priv->lock_box = NULL; } @@ -1569,14 +1415,12 @@ popdown_dialog (GSWindow *window) static gboolean lock_command_watch (GIOChannel *source, GIOCondition condition, - GSWindow *window) -{ + GSWindow *window) { gboolean finished = FALSE; g_return_val_if_fail (GS_IS_WINDOW (window), FALSE); - if (condition & G_IO_IN) - { + if (condition & G_IO_IN) { GIOStatus status; GError *error = NULL; char *line; @@ -1584,43 +1428,30 @@ lock_command_watch (GIOChannel *source, line = NULL; status = g_io_channel_read_line (source, &line, NULL, NULL, &error); - switch (status) - { + switch (status) { case G_IO_STATUS_NORMAL: gs_debug ("command output: %s", line); - if (strstr (line, "WINDOW ID=") != NULL) - { + if (strstr (line, "WINDOW ID=") != NULL) { guint32 id; char c; - if (1 == sscanf (line, " WINDOW ID= %" G_GUINT32_FORMAT " %c", &id, &c)) - { + if (1 == sscanf (line, " WINDOW ID= %" G_GUINT32_FORMAT " %c", &id, &c)) { create_lock_socket (window, id); } - } - else if (strstr (line, "NOTICE=") != NULL) - { - if (strstr (line, "NOTICE=AUTH FAILED") != NULL) - { + } else if (strstr (line, "NOTICE=") != NULL) { + if (strstr (line, "NOTICE=AUTH FAILED") != NULL) { shake_dialog (window); } - } - else if (strstr (line, "RESPONSE=") != NULL) - { - if (strstr (line, "RESPONSE=OK") != NULL) - { + } else if (strstr (line, "RESPONSE=") != NULL) { + if (strstr (line, "RESPONSE=OK") != NULL) { gs_debug ("Got OK response"); window->priv->dialog_response = DIALOG_RESPONSE_OK; - } - else - { + } else { gs_debug ("Got CANCEL response"); window->priv->dialog_response = DIALOG_RESPONSE_CANCEL; } finished = TRUE; - } - else if (strstr (line, "REQUEST QUIT") != NULL) - { + } else if (strstr (line, "REQUEST QUIT") != NULL) { gs_debug ("Got request for quit"); window->priv->dialog_quit_requested = TRUE; maybe_kill_dialog (window); @@ -1640,18 +1471,14 @@ lock_command_watch (GIOChannel *source, } g_free (line); - } - else if (condition & G_IO_HUP) - { + } else if (condition & G_IO_HUP) { finished = TRUE; } - if (finished) - { + if (finished) { popdown_dialog (window); - if (window->priv->dialog_response == DIALOG_RESPONSE_OK) - { + if (window->priv->dialog_response == DIALOG_RESPONSE_OK) { add_emit_deactivated_idle (window); } @@ -1664,24 +1491,20 @@ lock_command_watch (GIOChannel *source, } static gboolean -is_logout_enabled (GSWindow *window) -{ +is_logout_enabled (GSWindow *window) { double elapsed; - if (! window->priv->logout_enabled) - { + if (!window->priv->logout_enabled) { return FALSE; } - if (! window->priv->logout_command) - { + if (!window->priv->logout_command) { return FALSE; } elapsed = g_timer_elapsed (window->priv->timer, NULL); - if (window->priv->logout_timeout < (elapsed * 1000)) - { + if (window->priv->logout_timeout < (elapsed * 1000)) { return TRUE; } @@ -1689,14 +1512,12 @@ is_logout_enabled (GSWindow *window) } static gboolean -is_user_switch_enabled (GSWindow *window) -{ +is_user_switch_enabled (GSWindow *window) { return window->priv->user_switch_enabled; } static gint -get_monitor_index (GSWindow *window) -{ +get_monitor_index (GSWindow *window) { GdkDisplay *display = gs_window_get_display (window); GdkMonitor *monitor; gint idx; @@ -1712,8 +1533,7 @@ get_monitor_index (GSWindow *window) } static void -popup_dialog (GSWindow *window) -{ +popup_dialog (GSWindow *window) { gboolean result; char *tmp; GString *command; @@ -1728,14 +1548,12 @@ popup_dialog (GSWindow *window) g_string_append_printf(command, " --height='%i'", window->priv->geometry.height); g_string_append_printf(command, " --width='%i'", window->priv->geometry.width); - if (is_logout_enabled(window)) - { + if (is_logout_enabled(window)) { command = g_string_append (command, " --enable-logout"); g_string_append_printf (command, " --logout-command='%s'", window->priv->logout_command); } - if (window->priv->status_message) - { + if (window->priv->status_message) { char *quoted; quoted = g_shell_quote (window->priv->status_message); @@ -1743,13 +1561,11 @@ popup_dialog (GSWindow *window) g_free (quoted); } - if (is_user_switch_enabled (window)) - { + if (is_user_switch_enabled (window)) { command = g_string_append (command, " --enable-switch"); } - if (gs_debug_enabled ()) - { + if (gs_debug_enabled ()) { command = g_string_append (command, " --verbose"); } @@ -1767,8 +1583,7 @@ popup_dialog (GSWindow *window) (GIOFunc)lock_command_watch, window, &window->priv->lock_watch_id); - if (! result) - { + if (!result) { gs_debug ("Could not start command: %s", command->str); } @@ -1776,8 +1591,7 @@ popup_dialog (GSWindow *window) } static gboolean -popup_dialog_idle (GSWindow *window) -{ +popup_dialog_idle (GSWindow *window) { popup_dialog (window); window->priv->popup_dialog_idle_id = 0; @@ -1786,32 +1600,27 @@ popup_dialog_idle (GSWindow *window) } void -gs_window_request_unlock (GSWindow *window) -{ +gs_window_request_unlock (GSWindow *window) { g_return_if_fail (GS_IS_WINDOW (window)); gs_debug ("Requesting unlock"); - if (! gtk_widget_get_visible (GTK_WIDGET (window))) - { + if (!gtk_widget_get_visible (GTK_WIDGET (window))) { gs_debug ("Request unlock but window is not visible!"); return; } - if (window->priv->lock_watch_id > 0) - { + if (window->priv->lock_watch_id > 0) { return; } - if (! window->priv->lock_enabled) - { + if (!window->priv->lock_enabled) { add_emit_deactivated_idle (window); return; } - if (window->priv->popup_dialog_idle_id == 0) - { + if (window->priv->popup_dialog_idle_id == 0) { add_popup_dialog_idle (window); } @@ -1819,8 +1628,7 @@ gs_window_request_unlock (GSWindow *window) } void -gs_window_cancel_unlock_request (GSWindow *window) -{ +gs_window_cancel_unlock_request (GSWindow *window) { /* FIXME: This is a bit of a hammer approach... * Maybe we should send a delete-event to the plug? */ @@ -1831,12 +1639,10 @@ gs_window_cancel_unlock_request (GSWindow *window) void gs_window_set_lock_enabled (GSWindow *window, - gboolean lock_enabled) -{ + gboolean lock_enabled) { g_return_if_fail (GS_IS_WINDOW (window)); - if (window->priv->lock_enabled == lock_enabled) - { + if (window->priv->lock_enabled == lock_enabled) { return; } @@ -1845,8 +1651,7 @@ gs_window_set_lock_enabled (GSWindow *window, } GdkDisplay * -gs_window_get_display (GSWindow *window) -{ +gs_window_get_display (GSWindow *window) { g_return_val_if_fail (GS_IS_WINDOW (window), NULL); return gtk_widget_get_display (GTK_WIDGET (window)); @@ -1854,8 +1659,7 @@ gs_window_get_display (GSWindow *window) void gs_window_set_keyboard_enabled (GSWindow *window, - gboolean enabled) -{ + gboolean enabled) { g_return_if_fail (GS_IS_WINDOW (window)); window->priv->keyboard_enabled = enabled; @@ -1863,26 +1667,21 @@ gs_window_set_keyboard_enabled (GSWindow *window, void gs_window_set_keyboard_command (GSWindow *window, - const char *command) -{ + const char *command) { g_return_if_fail (GS_IS_WINDOW (window)); g_free (window->priv->keyboard_command); - if (command != NULL) - { + if (command != NULL) { window->priv->keyboard_command = g_strdup (command); - } - else - { + } else { window->priv->keyboard_command = NULL; } } void gs_window_set_logout_enabled (GSWindow *window, - gboolean logout_enabled) -{ + gboolean logout_enabled) { g_return_if_fail (GS_IS_WINDOW (window)); window->priv->logout_enabled = logout_enabled; @@ -1890,8 +1689,7 @@ gs_window_set_logout_enabled (GSWindow *window, void gs_window_set_user_switch_enabled (GSWindow *window, - gboolean user_switch_enabled) -{ + gboolean user_switch_enabled) { g_return_if_fail (GS_IS_WINDOW (window)); window->priv->user_switch_enabled = user_switch_enabled; @@ -1899,42 +1697,33 @@ gs_window_set_user_switch_enabled (GSWindow *window, void gs_window_set_logout_timeout (GSWindow *window, - glong logout_timeout) -{ + glong logout_timeout) { g_return_if_fail (GS_IS_WINDOW (window)); - if (logout_timeout < 0) - { + if (logout_timeout < 0) { window->priv->logout_timeout = 0; - } - else - { + } else { window->priv->logout_timeout = logout_timeout; } } void gs_window_set_logout_command (GSWindow *window, - const char *command) -{ + const char *command) { g_return_if_fail (GS_IS_WINDOW (window)); g_free (window->priv->logout_command); - if (command) - { + if (command) { window->priv->logout_command = g_strdup (command); - } - else - { + } else { window->priv->logout_command = NULL; } } void gs_window_set_status_message (GSWindow *window, - const char *status_message) -{ + const char *status_message) { g_return_if_fail (GS_IS_WINDOW (window)); g_free (window->priv->status_message); @@ -1943,12 +1732,10 @@ gs_window_set_status_message (GSWindow *window, void gs_window_set_monitor (GSWindow *window, - GdkMonitor *monitor) -{ + GdkMonitor *monitor) { g_return_if_fail (GS_IS_WINDOW (window)); - if (window->priv->monitor == monitor) - { + if (window->priv->monitor == monitor) { return; } @@ -1960,8 +1747,7 @@ gs_window_set_monitor (GSWindow *window, } GdkMonitor * -gs_window_get_monitor (GSWindow *window) -{ +gs_window_get_monitor (GSWindow *window) { g_return_val_if_fail (GS_IS_WINDOW (window), NULL); return window->priv->monitor; @@ -1971,14 +1757,12 @@ static void gs_window_set_property (GObject *object, guint prop_id, const GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GSWindow *self; self = GS_WINDOW (object); - switch (prop_id) - { + switch (prop_id) { case PROP_LOCK_ENABLED: gs_window_set_lock_enabled (self, g_value_get_boolean (value)); break; @@ -2013,14 +1797,12 @@ static void gs_window_get_property (GObject *object, guint prop_id, GValue *value, - GParamSpec *pspec) -{ + GParamSpec *pspec) { GSWindow *self; self = GS_WINDOW (object); - switch (prop_id) - { + switch (prop_id) { case PROP_LOCK_ENABLED: g_value_set_boolean (value, self->priv->lock_enabled); break; @@ -2059,15 +1841,13 @@ gs_window_get_property (GObject *object, static void queue_key_event (GSWindow *window, - GdkEventKey *event) -{ + GdkEventKey *event) { /* Eat the first return, enter, escape, or space */ if (window->priv->key_events == NULL && (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter || event->keyval == GDK_KEY_Escape - || event->keyval == GDK_KEY_space)) - { + || event->keyval == GDK_KEY_space)) { return; } @@ -2077,25 +1857,22 @@ queue_key_event (GSWindow *window, if (g_list_length (window->priv->key_events) < MAX_QUEUED_EVENTS && event->keyval != GDK_KEY_Tab && event->keyval != GDK_KEY_Up - && event->keyval != GDK_KEY_Down) - { + && event->keyval != GDK_KEY_Down) { window->priv->key_events = g_list_prepend (window->priv->key_events, gdk_event_copy ((GdkEvent *)event)); } } static gboolean -maybe_handle_activity (GSWindow *window) -{ +maybe_handle_activity (GSWindow *window) { gboolean handled; handled = FALSE; /* if we already have a socket then don't bother */ - if (! window->priv->lock_socket - && gtk_widget_get_sensitive (GTK_WIDGET (window))) - { - g_signal_emit (window, signals [ACTIVITY], 0, &handled); + if (!window->priv->lock_socket + && gtk_widget_get_sensitive (GTK_WIDGET (window))) { + g_signal_emit (window, signals[ACTIVITY], 0, &handled); } return handled; @@ -2103,13 +1880,11 @@ maybe_handle_activity (GSWindow *window) static gboolean gs_window_real_key_press_event (GtkWidget *widget, - GdkEventKey *event) -{ + GdkEventKey *event) { /*g_message ("KEY PRESS state: %u keyval %u", event->state, event->keyval);*/ /* Ignore brightness keys */ - if (event->hardware_keycode == 101 || event->hardware_keycode == 212) - { + if (event->hardware_keycode == 101 || event->hardware_keycode == 212) { gs_debug ("Ignoring brightness keys"); return TRUE; } @@ -2118,8 +1893,7 @@ gs_window_real_key_press_event (GtkWidget *widget, queue_key_event (GS_WINDOW (widget), event); - if (GTK_WIDGET_CLASS (gs_window_parent_class)->key_press_event) - { + if (GTK_WIDGET_CLASS (gs_window_parent_class)->key_press_event) { GTK_WIDGET_CLASS (gs_window_parent_class)->key_press_event (widget, event); } @@ -2128,8 +1902,7 @@ gs_window_real_key_press_event (GtkWidget *widget, static gboolean gs_window_real_motion_notify_event (GtkWidget *widget, - GdkEventMotion *event) -{ + GdkEventMotion *event) { GSWindow *window; gdouble distance; gdouble min_distance; @@ -2144,8 +1917,7 @@ gs_window_real_motion_notify_event (GtkWidget *widget, min_distance = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) * min_percentage; /* if the last position was not set then don't detect motion */ - if (window->priv->last_x < 0 || window->priv->last_y < 0) - { + if (window->priv->last_x < 0 || window->priv->last_y < 0) { window->priv->last_x = event->x; window->priv->last_y = event->y; @@ -2156,8 +1928,7 @@ gs_window_real_motion_notify_event (GtkWidget *widget, distance = MAX (ABS (window->priv->last_x - event->x), ABS (window->priv->last_y - event->y)); - if (distance > min_distance) - { + if (distance > min_distance) { maybe_handle_activity (window); window->priv->last_x = -1; @@ -2169,8 +1940,7 @@ gs_window_real_motion_notify_event (GtkWidget *widget, static gboolean gs_window_real_button_press_event (GtkWidget *widget, - GdkEventButton *event) -{ + GdkEventButton *event) { GSWindow *window; window = GS_WINDOW (widget); @@ -2181,8 +1951,7 @@ gs_window_real_button_press_event (GtkWidget *widget, static gboolean gs_window_real_scroll_event (GtkWidget *widget, - GdkEventScroll *event) -{ + GdkEventScroll *event) { GSWindow *window; window = GS_WINDOW (widget); @@ -2193,8 +1962,7 @@ gs_window_real_scroll_event (GtkWidget *widget, static void gs_window_real_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ + GtkRequisition *requisition) { GSWindow *window; GtkBin *bin; GtkWidget *child; @@ -2206,8 +1974,7 @@ gs_window_real_size_request (GtkWidget *widget, bin = GTK_BIN (widget); child = gtk_bin_get_child (bin); - if (child && gtk_widget_get_visible (child)) - { + if (child && gtk_widget_get_visible (child)) { gtk_widget_get_preferred_size (child, requisition, NULL); } @@ -2218,20 +1985,17 @@ gs_window_real_size_request (GtkWidget *widget, requisition->width = window->priv->geometry.width; requisition->height = window->priv->geometry.height; - if (! gtk_widget_get_realized (widget)) - { + if (!gtk_widget_get_realized (widget)) { return; } if (old_geometry.width != window->priv->geometry.width || - old_geometry.height != window->priv->geometry.height) - { + old_geometry.height != window->priv->geometry.height) { size_changed = TRUE; } if (old_geometry.x != window->priv->geometry.x || - old_geometry.y != window->priv->geometry.y) - { + old_geometry.y != window->priv->geometry.y) { position_changed = TRUE; } @@ -2241,8 +2005,7 @@ gs_window_real_size_request (GtkWidget *widget, static void gs_window_real_get_preferred_width (GtkWidget *widget, gint *minimal_width, - gint *natural_width) -{ + gint *natural_width) { GtkRequisition requisition; gs_window_real_size_request (widget, &requisition); *minimal_width = *natural_width = requisition.width; @@ -2251,8 +2014,7 @@ gs_window_real_get_preferred_width (GtkWidget *widget, static void gs_window_real_get_preferred_height (GtkWidget *widget, gint *minimal_height, - gint *natural_height) -{ + gint *natural_height) { GtkRequisition requisition; gs_window_real_size_request (widget, &requisition); *minimal_height = *natural_height = requisition.height; @@ -2260,17 +2022,13 @@ gs_window_real_get_preferred_height (GtkWidget *widget, static gboolean gs_window_real_grab_broken (GtkWidget *widget, - GdkEventGrabBroken *event) -{ - if (event->grab_window != NULL) - { + GdkEventGrabBroken *event) { + if (event->grab_window != NULL) { gs_debug ("Grab broken on window %X %s, new grab on window %X", (guint32) GDK_WINDOW_XID (event->window), event->keyboard ? "keyboard" : "pointer", (guint32) GDK_WINDOW_XID (event->grab_window)); - } - else - { + } else { gs_debug ("Grab broken on window %X %s, new grab is outside application", (guint32) GDK_WINDOW_XID (event->window), event->keyboard ? "keyboard" : "pointer"); @@ -2280,16 +2038,14 @@ gs_window_real_grab_broken (GtkWidget *widget, } gboolean -gs_window_is_obscured (GSWindow *window) -{ +gs_window_is_obscured (GSWindow *window) { g_return_val_if_fail (GS_IS_WINDOW (window), FALSE); return window->priv->obscured; } gboolean -gs_window_is_dialog_up (GSWindow *window) -{ +gs_window_is_dialog_up (GSWindow *window) { g_return_val_if_fail (GS_IS_WINDOW (window), FALSE); return window->priv->dialog_up; @@ -2297,10 +2053,8 @@ gs_window_is_dialog_up (GSWindow *window) static void window_set_obscured (GSWindow *window, - gboolean obscured) -{ - if (window->priv->obscured == obscured) - { + gboolean obscured) { + if (window->priv->obscured == obscured) { return; } @@ -2310,10 +2064,8 @@ window_set_obscured (GSWindow *window, static gboolean gs_window_real_visibility_notify_event (GtkWidget *widget, - GdkEventVisibility *event) -{ - switch (event->state) - { + GdkEventVisibility *event) { + switch (event->state) { case GDK_VISIBILITY_FULLY_OBSCURED: window_set_obscured (GS_WINDOW (widget), TRUE); break; @@ -2330,8 +2082,7 @@ gs_window_real_visibility_notify_event (GtkWidget *widget, } static void -gs_window_class_init (GSWindowClass *klass) -{ +gs_window_class_init (GSWindowClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); @@ -2353,7 +2104,7 @@ gs_window_class_init (GSWindowClass *klass) widget_class->grab_broken_event = gs_window_real_grab_broken; widget_class->visibility_notify_event = gs_window_real_visibility_notify_event; - signals [ACTIVITY] = + signals[ACTIVITY] = g_signal_new ("activity", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -2363,7 +2114,7 @@ gs_window_class_init (GSWindowClass *klass) gs_marshal_BOOLEAN__VOID, G_TYPE_BOOLEAN, 0); - signals [DEACTIVATED] = + signals[DEACTIVATED] = g_signal_new ("deactivated", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, @@ -2449,8 +2200,7 @@ gs_window_class_init (GSWindowClass *klass) } static void -create_info_bar (GSWindow *window) -{ +create_info_bar (GSWindow *window) { window->priv->info_bar = gtk_info_bar_new (); gtk_widget_set_no_show_all (window->priv->info_bar, TRUE); gtk_box_pack_end (GTK_BOX (window->priv->vbox), window->priv->info_bar, FALSE, FALSE, 0); @@ -2458,8 +2208,7 @@ create_info_bar (GSWindow *window) static gboolean on_drawing_area_draw (GtkWidget *widget, - cairo_t *cr) -{ + cairo_t *cr) { cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgb (cr, 0, 0, 0); cairo_paint (cr); @@ -2468,8 +2217,7 @@ on_drawing_area_draw (GtkWidget *widget, } static void -gs_window_init (GSWindow *window) -{ +gs_window_init (GSWindow *window) { window->priv = gs_window_get_instance_private (window); window->priv->geometry.x = -1; @@ -2518,23 +2266,19 @@ gs_window_init (GSWindow *window) } static void -remove_command_watches (GSWindow *window) -{ - if (window->priv->lock_watch_id != 0) - { +remove_command_watches (GSWindow *window) { + if (window->priv->lock_watch_id != 0) { g_source_remove (window->priv->lock_watch_id); window->priv->lock_watch_id = 0; } - if (window->priv->keyboard_watch_id != 0) - { + if (window->priv->keyboard_watch_id != 0) { g_source_remove (window->priv->keyboard_watch_id); window->priv->keyboard_watch_id = 0; } } static void -gs_window_finalize (GObject *object) -{ +gs_window_finalize (GObject *object) { GSWindow *window; g_return_if_fail (object != NULL); @@ -2547,8 +2291,7 @@ gs_window_finalize (GObject *object) g_free (window->priv->logout_command); g_free (window->priv->keyboard_command); - if (window->priv->info_bar_timer_id > 0) - { + if (window->priv->info_bar_timer_id > 0) { g_source_remove (window->priv->info_bar_timer_id); window->priv->info_bar_timer_id = 0; } @@ -2556,8 +2299,7 @@ gs_window_finalize (GObject *object) remove_watchdog_timer (window); remove_popup_dialog_idle (window); - if (window->priv->timer) - { + if (window->priv->timer) { g_timer_destroy (window->priv->timer); } @@ -2567,8 +2309,7 @@ gs_window_finalize (GObject *object) gs_window_dialog_finish (window); - if (window->priv->background_surface) - { + if (window->priv->background_surface) { cairo_surface_destroy (window->priv->background_surface); } @@ -2577,8 +2318,7 @@ gs_window_finalize (GObject *object) GSWindow * gs_window_new (GdkMonitor *monitor, - gboolean lock_enabled) -{ + gboolean lock_enabled) { GObject *result; GdkDisplay *display = gdk_monitor_get_display (monitor); GdkScreen *screen = gdk_display_get_default_screen (display); diff --git a/src/setuid.c b/src/setuid.c index c4763e9e9ce061d5e4a65a72721808367c69b10c..5c5a25a0bd89f30d38aa71d482e94f3d24cf7679 100644 --- a/src/setuid.c +++ b/src/setuid.c @@ -13,26 +13,26 @@ * implied warranty. */ -#include "config.h" - -#ifndef EPERM -#include <errno.h> -#endif +#include <config.h> +#include <grp.h> /* for getgrgid() and struct group */ +#include <pwd.h> /* for getpwnam() and struct passwd */ #include <stdio.h> #include <string.h> #include <sys/types.h> #include <unistd.h> -#include <pwd.h> /* for getpwnam() and struct passwd */ -#include <grp.h> /* for getgrgid() and struct group */ + #include <glib.h> -#include "setuid.h" +#ifndef EPERM +#include <errno.h> +#endif + +#include "src/setuid.h" static char * uid_gid_string (uid_t uid, - gid_t gid) -{ + gid_t gid) { static char *buf; struct passwd *p = NULL; struct group *g = NULL; @@ -51,8 +51,7 @@ uid_gid_string (uid_t uid, static gboolean set_ids_by_number (uid_t uid, gid_t gid, - char **message_ret) -{ + char **message_ret) { int uid_errno = 0; int gid_errno = 0; int sgs_errno = 0; @@ -85,8 +84,7 @@ set_ids_by_number (uid_t uid, if (setuid (uid) != 0) uid_errno = errno ? errno : -1; - if (uid_errno == 0 && gid_errno == 0 && sgs_errno == 0) - { + if (uid_errno == 0 && gid_errno == 0 && sgs_errno == 0) { static char *reason; reason = g_strdup_printf ("changed uid/gid to %s/%s (%ld/%ld).", (p && p->pw_name ? p->pw_name : "???"), @@ -98,20 +96,16 @@ set_ids_by_number (uid_t uid, g_free (reason); return TRUE; - } - else - { + } else { char *reason = NULL; - if (sgs_errno) - { + if (sgs_errno) { reason = g_strdup_printf ("couldn't setgroups to %s (%ld)", (g && g->gr_name ? g->gr_name : "???"), (long) gid); - if (sgs_errno == -1) + if (sgs_errno == -1) { fprintf (stderr, "%s: unknown error\n", reason); - else - { + } else { errno = sgs_errno; perror (reason); } @@ -119,15 +113,13 @@ set_ids_by_number (uid_t uid, reason = NULL; } - if (gid_errno) - { + if (gid_errno) { reason = g_strdup_printf ("couldn't set gid to %s (%ld)", (g && g->gr_name ? g->gr_name : "???"), (long) gid); - if (gid_errno == -1) + if (gid_errno == -1) { fprintf (stderr, "%s: unknown error\n", reason); - else - { + } else { errno = gid_errno; perror (reason); } @@ -135,15 +127,13 @@ set_ids_by_number (uid_t uid, reason = NULL; } - if (uid_errno) - { + if (uid_errno) { reason = g_strdup_printf ("couldn't set uid to %s (%ld)", (p && p->pw_name ? p->pw_name : "???"), (long) uid); - if (uid_errno == -1) + if (uid_errno == -1) { fprintf (stderr, "%s: unknown error\n", reason); - else - { + } else { errno = uid_errno; perror (reason); } @@ -172,24 +162,20 @@ set_ids_by_number (uid_t uid, gboolean hack_uid (char **nolock_reason, char **orig_uid, - char **uid_message) -{ + char **uid_message) { char *reason; gboolean ret; ret = TRUE; reason = NULL; - if (nolock_reason != NULL) - { + if (nolock_reason != NULL) { *nolock_reason = NULL; } - if (orig_uid != NULL) - { + if (orig_uid != NULL) { *orig_uid = NULL; } - if (uid_message != NULL) - { + if (uid_message != NULL) { *uid_message = NULL; } @@ -202,13 +188,11 @@ hack_uid (char **nolock_reason, uid_t uid = getuid (); gid_t gid = getgid (); - if (orig_uid != NULL) - { + if (orig_uid != NULL) { *orig_uid = uid_gid_string (euid, egid); } - if (uid != euid || gid != egid) - { + if (uid != euid || gid != egid) { #ifdef HAVE_BSDAUTH /* we need to setgid auth to run the bsd_auth(3) login_* helpers */ struct group *authg = getgrnam("auth"); if (!authg || !authg->gr_name || !*authg->gr_name) { @@ -218,8 +202,7 @@ hack_uid (char **nolock_reason, } gid = authg->gr_gid; #endif /* !HAVE_BSDAUTH */ - if (! set_ids_by_number (uid, gid, uid_message)) - { + if (!set_ids_by_number (uid, gid, uid_message)) { reason = g_strdup ("unable to discard privileges."); ret = FALSE; @@ -238,16 +221,14 @@ hack_uid (char **nolock_reason, of the xscreensaver manual titled "LOCKING AND ROOT LOGINS", and "USING XDM". */ - if (getuid () == (uid_t) 0) - { + if (getuid () == (uid_t) 0) { reason = g_strdup ("running as root"); ret = FALSE; goto out; } out: - if (nolock_reason != NULL) - { + if (nolock_reason != NULL) { *nolock_reason = g_strdup (reason); } g_free (reason); diff --git a/src/subprocs.c b/src/subprocs.c index caa1a263d3c60156cdc20833f38d3148e7aa53d3..1f4ea0e907f70d87b0b750f52d51e6042f87d01b 100644 --- a/src/subprocs.c +++ b/src/subprocs.c @@ -14,32 +14,31 @@ * implied warranty. */ -#include "config.h" +#include <config.h> -#include <stdlib.h> #include <ctype.h> +#include <signal.h> /* for the signal names */ #include <stdio.h> +#include <stdlib.h> #include <string.h> +#include <sys/time.h> /* sys/resource.h needs this for timeval */ +#include <sys/wait.h> /* for waitpid() and associated macros */ + +#include <glib.h> #ifndef ESRCH -# include <errno.h> +#include <errno.h> #endif -#include <sys/time.h> /* sys/resource.h needs this for timeval */ -# include <sys/wait.h> /* for waitpid() and associated macros */ - #ifdef VMS -# include <processes.h> -# include <unixio.h> /* for close */ -# include <unixlib.h> /* for getpid */ -# define pid_t int -# define fork vfork +#include <processes.h> +#include <unixio.h> /* for close */ +#include <unixlib.h> /* for getpid */ +#define pid_t int +#define fork vfork #endif /* VMS */ -#include <signal.h> /* for the signal names */ - -#include <glib.h> -#include "subprocs.h" +#include "src/subprocs.h" #if !defined(SIGCHLD) && defined(SIGCLD) # define SIGCHLD SIGCLD @@ -56,8 +55,7 @@ sigset_t #else /* !HAVE_SIGACTION */ int #endif /* !HAVE_SIGACTION */ -block_sigchld (void) -{ +block_sigchld (void) { #ifdef HAVE_SIGACTION sigset_t child_set; sigemptyset (&child_set); @@ -76,8 +74,7 @@ block_sigchld (void) } void -unblock_sigchld (void) -{ +unblock_sigchld (void) { #ifdef HAVE_SIGACTION sigset_t child_set; sigemptyset (&child_set); @@ -91,8 +88,7 @@ unblock_sigchld (void) int signal_pid (int pid, - int signal) -{ + int signal) { int status = -1; gboolean verbose = TRUE; @@ -104,14 +100,12 @@ signal_pid (int pid, status = kill (pid, signal); - if (verbose && status < 0) - { - if (errno == ESRCH) + if (verbose && status < 0) { + if (errno == ESRCH) { g_message ("Child process %lu was already dead.", (unsigned long) pid); - else - { - char buf [1024]; + } else { + char buf[1024]; snprintf (buf, sizeof (buf), "Couldn't kill child process %lu", (unsigned long) pid); perror (buf); @@ -130,18 +124,15 @@ signal_pid (int pid, void await_dying_children (int pid, - gboolean debug) -{ - while (1) - { + gboolean debug) { + while (1) { int wait_status = 0; pid_t kid; errno = 0; kid = waitpid (-1, &wait_status, WNOHANG|WUNTRACED); - if (debug) - { + if (debug) { if (kid < 0 && errno) g_message ("waitpid(%d) ==> %ld (%d)", pid, (long) kid, errno); else if (kid != 0) @@ -158,8 +149,7 @@ await_dying_children (int pid, #else /* VMS */ -static void await_dying_children (saver_info *si) -{ +static void await_dying_children (saver_info *si) { return; } #endif /* VMS */ diff --git a/src/test-fade.c b/src/test-fade.c index ef8963bb11597cdc70ef7ab1bc5c474f8663daf6..a09ee04acdde9baf2e828b571ac3ab2b308704a3 100644 --- a/src/test-fade.c +++ b/src/test-fade.c @@ -21,7 +21,7 @@ * */ -#include "config.h" +#include <config.h> #include <stdlib.h> #include <string.h> @@ -31,30 +31,29 @@ #include <termios.h> #include <unistd.h> -#include <libxfce4util/libxfce4util.h> #include <gdk/gdkx.h> #include <gtk/gtk.h> -#include "gs-fade.h" -#include "gs-debug.h" +#include <libxfce4util/libxfce4util.h> #ifdef HAVE_XF86VMODE_GAMMA -# include <X11/extensions/xf86vmode.h> +#include <X11/extensions/xf86vmode.h> #endif +#include "src/gs-fade.h" +#include "src/gs-debug.h" + #define XF86_VIDMODE_NAME "XFree86-VidModeExtension" static void -test_fade (void) -{ +test_fade (void) { GSFade *fade; int reps = 2; int delay = 2; fade = gs_fade_new (); - while (reps-- > 0) - { + while (reps-- > 0) { g_print ("fading out..."); gs_fade_sync (fade, 1000); g_print ("done.\n"); @@ -63,8 +62,7 @@ test_fade (void) gs_fade_reset (fade); g_print ("done.\n"); - if (delay) - { + if (delay) { sleep (delay); } } @@ -74,8 +72,7 @@ test_fade (void) int main (int argc, - char **argv) -{ + char **argv) { GError *error = NULL; int op, event, err; @@ -87,35 +84,27 @@ main (int argc, textdomain (GETTEXT_PACKAGE); #endif - if (error) - { + if (error) { fprintf (stderr, "%s\n", error->message); exit (1); } - if (! gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) - { + if (!gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) { fprintf (stderr, "%s", error->message); g_error_free (error); exit (1); } - if (! XQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XF86_VIDMODE_NAME, &op, &event, &err)) - { + if (!XQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XF86_VIDMODE_NAME, &op, &event, &err)) { g_message ("no " XF86_VIDMODE_NAME " extension"); - } - else - { + } else { # ifdef HAVE_XF86VMODE_GAMMA int major; int minor; - if (! XF86VidModeQueryVersion (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &major, &minor)) - { + if (!XF86VidModeQueryVersion (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &major, &minor)) { g_message ("unable to get " XF86_VIDMODE_NAME " version"); - } - else - { + } else { g_message (XF86_VIDMODE_NAME " version %d.%d", major, minor); } # else /* !HAVE_XF86VMODE_GAMMA */ diff --git a/src/test-passwd.c b/src/test-passwd.c index 96f23c2839de9cdd647eb807f48c8f405dca918e..7f98eafbf76ed723583f38c19651de7112d42691 100644 --- a/src/test-passwd.c +++ b/src/test-passwd.c @@ -21,7 +21,7 @@ * */ -#include "config.h" +#include <config.h> #include <stdlib.h> #include <string.h> @@ -30,19 +30,19 @@ #include <sys/wait.h> #include <termios.h> -#include <libxfce4util/libxfce4util.h> #include <gtk/gtk.h> -#include "gs-auth.h" -#include "setuid.h" +#include <libxfce4util/libxfce4util.h> + +#include "src/gs-auth.h" +#include "src/setuid.h" /* Initializations that potentially take place as a priveleged user: If the executable is setuid root, then these initializations are run as root, before discarding privileges. */ static gboolean -privileged_initialization (void) -{ +privileged_initialization (void) { gboolean ret; char *nolock_reason; char *orig_uid; @@ -56,12 +56,10 @@ privileged_initialization (void) ret = hack_uid (&nolock_reason, &orig_uid, &uid_message); - if (nolock_reason) - { + if (nolock_reason) { g_warning ("Locking disabled: %s", nolock_reason); } - if (uid_message && gs_auth_get_verbose ()) - { + if (uid_message && gs_auth_get_verbose ()) { g_print ("Modified UID: %s", uid_message); } @@ -72,30 +70,24 @@ privileged_initialization (void) return ret; } - /* Figure out what locking mechanisms are supported. */ static gboolean -lock_initialization (char **nolock_reason) -{ - if (nolock_reason) - { +lock_initialization (char **nolock_reason) { + if (nolock_reason) { *nolock_reason = NULL; } #ifdef NO_LOCKING - if (nolock_reason) - { + if (nolock_reason) { *nolock_reason = g_strdup ("not compiled with locking support"); } return FALSE; #else /* !NO_LOCKING */ /* Finish initializing locking, now that we're out of privileged code. */ - if (! gs_auth_init ()) - { - if (nolock_reason) - { + if (!gs_auth_init ()) { + if (nolock_reason) { *nolock_reason = g_strdup ("error getting password"); } return FALSE; @@ -105,10 +97,8 @@ lock_initialization (char **nolock_reason) we have been launched as MDM's "Background" program, then disable locking just in case. */ - if (getenv ("RUNNING_UNDER_MDM")) - { - if (nolock_reason) - { + if (getenv ("RUNNING_UNDER_MDM")) { + if (nolock_reason) { *nolock_reason = g_strdup ("running under MDM"); } return FALSE; @@ -130,10 +120,8 @@ lock_initialization (char **nolock_reason) macos = TRUE; #endif - if (macos) - { - if (nolock_reason) - { + if (macos) { + if (nolock_reason) { *nolock_reason = g_strdup ("Cannot lock securely on MacOS X"); } return FALSE; @@ -146,9 +134,8 @@ lock_initialization (char **nolock_reason) } static char * -request_password (const char *prompt) -{ - char buf [255]; +request_password (const char *prompt) { + char buf[255]; char *pass; char *password; struct termios ts0; @@ -160,8 +147,7 @@ request_password (const char *prompt) printf ("%s", prompt); - if (tcsetattr (fileno (stdin), TCSAFLUSH, &ts1) != 0) - { + if (tcsetattr (fileno (stdin), TCSAFLUSH, &ts1) != 0) { fprintf (stderr, "Could not set terminal attributes\n"); exit (1); } @@ -170,14 +156,12 @@ request_password (const char *prompt) tcsetattr (fileno (stdin), TCSANOW, &ts0); - if (!pass || !*pass) - { + if (!pass || !*pass) { exit (0); } - if (pass [strlen (pass) - 1] == '\n') - { - pass [strlen (pass) - 1] = 0; + if (pass[strlen (pass) - 1] == '\n') { + pass[strlen (pass) - 1] = 0; } password = g_strdup (pass); @@ -191,31 +175,29 @@ static gboolean auth_message_handler (GSAuthMessageStyle style, const char *msg, char **response, - gpointer data) -{ + gpointer data) { gboolean ret; g_message ("Got message style %d: '%s'", style, msg); ret = TRUE; - switch (style) - { - case GS_AUTH_MESSAGE_PROMPT_ECHO_ON: - break; - case GS_AUTH_MESSAGE_PROMPT_ECHO_OFF: - { - char *password; - password = request_password (msg); - *response = password; - } - break; - case GS_AUTH_MESSAGE_ERROR_MSG: - break; - case GS_AUTH_MESSAGE_TEXT_INFO: - break; - default: - g_assert_not_reached (); + switch (style) { + case GS_AUTH_MESSAGE_PROMPT_ECHO_ON: + break; + case GS_AUTH_MESSAGE_PROMPT_ECHO_OFF: + { + char *password; + password = request_password (msg); + *response = password; + } + break; + case GS_AUTH_MESSAGE_ERROR_MSG: + break; + case GS_AUTH_MESSAGE_TEXT_INFO: + break; + default: + g_assert_not_reached (); } return ret; @@ -223,8 +205,7 @@ auth_message_handler (GSAuthMessageStyle style, int main (int argc, - char **argv) -{ + char **argv) { GError *error = NULL; gboolean verbose = TRUE; char *nolock_reason = NULL; @@ -238,22 +219,18 @@ main (int argc, #endif gs_auth_set_verbose (verbose); - if (! privileged_initialization ()) - { + if (!privileged_initialization ()) { exit (1); } - if (! gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) - { + if (!gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) { fprintf (stderr, "%s", error->message); g_error_free (error); exit (1); } - if (! lock_initialization (&nolock_reason)) - { - if (nolock_reason) - { + if (!lock_initialization (&nolock_reason)) { + if (nolock_reason) { g_warning ("Screen locking disabled: %s", nolock_reason); g_free (nolock_reason); } @@ -264,14 +241,10 @@ main (int argc, again: error = NULL; - if (gs_auth_verify_user (g_get_user_name (), g_getenv ("DISPLAY"), auth_message_handler, NULL, &error)) - { + if (gs_auth_verify_user (g_get_user_name (), g_getenv ("DISPLAY"), auth_message_handler, NULL, &error)) { printf ("Correct!\n"); - } - else - { - if (error != NULL) - { + } else { + if (error != NULL) { fprintf (stderr, "ERROR: %s\n", error->message); g_error_free (error); } diff --git a/src/test-window.c b/src/test-window.c index 580f0ce5f159fa7223ccd3e479421ae2d6fe76bd..c5e76958e773d486e8354158c0a83ed86585d345 100644 --- a/src/test-window.c +++ b/src/test-window.c @@ -21,42 +21,39 @@ * */ -#include "config.h" +#include <config.h> #include <stdlib.h> -#include <libxfce4util/libxfce4util.h> #include <gtk/gtk.h> -#include "gs-window.h" -#include "gs-grab.h" -#include "gs-debug.h" +#include <libxfce4util/libxfce4util.h> + +#include "src/gs-debug.h" +#include "src/gs-grab.h" +#include "src/gs-window.h" static GSGrab *grab = NULL; static void window_deactivated_cb (GSWindow *window, - gpointer data) -{ + gpointer data) { gs_window_destroy (window); } static void window_dialog_up_cb (GSWindow *window, - gpointer data) -{ + gpointer data) { } static void window_dialog_down_cb (GSWindow *window, - gpointer data) -{ + gpointer data) { } static void window_show_cb (GSWindow *window, - gpointer data) -{ + gpointer data) { /* move devices grab so that dialog can be used */ gs_grab_move_to_window (grab, gs_window_get_gdk_window (window), @@ -66,16 +63,14 @@ window_show_cb (GSWindow *window, static gboolean window_activity_cb (GSWindow *window, - gpointer data) -{ + gpointer data) { gs_window_request_unlock (window); return TRUE; } static void -disconnect_window_signals (GSWindow *window) -{ +disconnect_window_signals (GSWindow *window) { gpointer data; data = NULL; @@ -88,16 +83,14 @@ disconnect_window_signals (GSWindow *window) static void window_destroyed_cb (GtkWindow *window, - gpointer data) -{ + gpointer data) { disconnect_window_signals (GS_WINDOW (window)); gs_grab_release (grab, TRUE); gtk_main_quit (); } static void -connect_window_signals (GSWindow *window) -{ +connect_window_signals (GSWindow *window) { gpointer data; data = NULL; @@ -117,8 +110,7 @@ connect_window_signals (GSWindow *window) } static void -test_window (void) -{ +test_window (void) { GSWindow *window; gboolean lock_active; gboolean user_switch_enabled; @@ -141,8 +133,7 @@ test_window (void) int main (int argc, - char **argv) -{ + char **argv) { GError *error = NULL; #ifdef ENABLE_NLS @@ -153,8 +144,7 @@ main (int argc, textdomain (GETTEXT_PACKAGE); #endif - if (! gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) - { + if (!gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) { fprintf (stderr, "%s", error->message); g_error_free (error); exit (1); diff --git a/src/xfce-bg.c b/src/xfce-bg.c index 17e73ea205006ac06cddc67636313015e5148bd9..cea9f8e3b5cdac621e56cd00cf0c45beb21594a5 100644 --- a/src/xfce-bg.c +++ b/src/xfce-bg.c @@ -30,29 +30,28 @@ Authors: Soren Sandmann <sandmann@redhat.com> */ -#include <string.h> +#include <fcntl.h> #include <math.h> #include <stdarg.h> #include <stdlib.h> -#include <fcntl.h> -#include <sys/types.h> +#include <string.h> #include <sys/stat.h> +#include <sys/types.h> +#include <gio/gio.h> #include <glib/gprintf.h> #include <glib/gstdio.h> -#include <gio/gio.h> +#include <cairo.h> +#include <cairo-xlib.h> #include <gdk/gdkx.h> + #include <X11/Xlib.h> #include <X11/Xatom.h> -#include <cairo.h> - #include <xfce-bg.h> #include <xfconf/xfconf.h> -#include <cairo-xlib.h> - #define XFCE_BG_CACHE_DIR "xfce/background" #define XFCE_BG_FALLBACK_IMG "xfce-teal.jpg" @@ -202,8 +201,7 @@ static void xfce_bg_set_filename (XfceBG *bg, static void color_from_rgba_array (XfconfChannel *channel, const gchar *property, - GdkRGBA *colorp) -{ + GdkRGBA *colorp) { gdouble r, g, b, a; /* If all else fails use Xfdesktop's default */ @@ -228,8 +226,7 @@ static void color_from_rgba_array (XfconfChannel *channel, static void color_from_color_array (XfconfChannel *channel, const gchar *property, - GdkRGBA *colorp) -{ + GdkRGBA *colorp) { guint rc, gc, bc, ac; /* If all else fails use Xfdesktop's default */ @@ -253,8 +250,7 @@ static void color_from_color_array (XfconfChannel *channel, } static gboolean -do_changed (XfceBG *bg) -{ +do_changed (XfceBG *bg) { bg->changed_id = 0; g_signal_emit (G_OBJECT (bg), signals[CHANGED], 0); @@ -263,8 +259,7 @@ do_changed (XfceBG *bg) } static void -queue_changed (XfceBG *bg) -{ +queue_changed (XfceBG *bg) { if (bg->changed_id > 0) { g_source_remove (bg->changed_id); } @@ -277,8 +272,7 @@ queue_changed (XfceBG *bg) } static gboolean -do_transitioned (XfceBG *bg) -{ +do_transitioned (XfceBG *bg) { bg->transitioned_id = 0; if (bg->pixbuf_cache) { @@ -292,8 +286,7 @@ do_transitioned (XfceBG *bg) } static void -queue_transitioned (XfceBG *bg) -{ +queue_transitioned (XfceBG *bg) { if (bg->transitioned_id > 0) { g_source_remove (bg->transitioned_id); } @@ -306,30 +299,28 @@ queue_transitioned (XfceBG *bg) } static gchar * -find_system_backgrounds (void) -{ - const gchar * const *dirs; - gchar *path; - gint i; - - dirs = g_get_system_data_dirs (); - for (i = 0; dirs[i]; i++) { - path = g_build_path (G_DIR_SEPARATOR_S, dirs[i], +find_system_backgrounds (void) { + const gchar * const *dirs; + gchar *path; + gint i; + + dirs = g_get_system_data_dirs (); + for (i = 0; dirs[i]; i++) { + path = g_build_path (G_DIR_SEPARATOR_S, dirs[i], "backgrounds", "xfce", NULL); - if (g_file_test (path, G_FILE_TEST_IS_DIR)) - return path; - else - g_free (path); - } + if (g_file_test (path, G_FILE_TEST_IS_DIR)) + return path; + else + g_free (path); + } - return NULL; + return NULL; } /* This function loads the user's preferences */ void xfce_bg_load_from_preferences (XfceBG *bg, - GdkMonitor *monitor) -{ + GdkMonitor *monitor) { XfconfChannel *channel; channel = xfconf_channel_get ("xfce4-desktop"); @@ -341,8 +332,7 @@ xfce_bg_load_from_preferences (XfceBG *bg, static gboolean xfce_bg_check_property_prefix (XfconfChannel *channel, - gchar *prefix) -{ + gchar *prefix) { gchar *property; property = g_strconcat (prefix, "/last-image", NULL); @@ -392,30 +382,26 @@ xfce_bg_check_property_prefix (XfconfChannel *channel, static gchar* xfce_bg_get_property_prefix (XfconfChannel *channel, - const gchar *monitor_name) -{ + const gchar *monitor_name) { gchar *prefix; /* Check for workspace usage */ prefix = g_strconcat("/backdrop/screen0/monitor", monitor_name, "/workspace0", NULL); - if (xfce_bg_check_property_prefix (channel, prefix)) - { + if (xfce_bg_check_property_prefix (channel, prefix)) { return prefix; } g_free(prefix); /* Check for non-workspace usage */ prefix = g_strconcat("/backdrop/screen0/monitor", monitor_name, NULL); - if (xfce_bg_check_property_prefix (channel, prefix)) - { + if (xfce_bg_check_property_prefix (channel, prefix)) { return prefix; } g_free(prefix); /* Check defaults */ prefix = g_strdup("/backdrop/screen0/monitor0/workspace0"); - if (xfce_bg_check_property_prefix (channel, prefix)) - { + if (xfce_bg_check_property_prefix (channel, prefix)) { return prefix; } g_free(prefix); @@ -427,8 +413,7 @@ xfce_bg_get_property_prefix (XfconfChannel *channel, static void xfce_bg_load_from_xfconf (XfceBG *bg, XfconfChannel *channel, - GdkMonitor *monitor) -{ + GdkMonitor *monitor) { char *tmp; char *filename; XfceBGColorType ctype; @@ -441,17 +426,13 @@ xfce_bg_load_from_xfconf (XfceBG *bg, g_return_if_fail(XFCE_IS_BG(bg)); - if (monitor == NULL) - { + if (monitor == NULL) { GdkDisplay *display = gdk_display_get_default(); mon = gdk_display_get_primary_monitor(display); - if (mon == NULL) - { + if (mon == NULL) { mon = gdk_display_get_monitor(display, 0); } - } - else - { + } else { mon = monitor; } @@ -547,13 +528,11 @@ xfce_bg_load_from_xfconf (XfceBG *bg, } static void -xfce_bg_init (XfceBG *bg) -{ +xfce_bg_init (XfceBG *bg) { } static void -xfce_bg_dispose (GObject *object) -{ +xfce_bg_dispose (GObject *object) { XfceBG *bg = XFCE_BG (object); if (bg->file_monitor) { @@ -567,8 +546,7 @@ xfce_bg_dispose (GObject *object) } static void -xfce_bg_finalize (GObject *object) -{ +xfce_bg_finalize (GObject *object) { XfceBG *bg = XFCE_BG (object); if (bg->changed_id != 0) { @@ -593,8 +571,7 @@ xfce_bg_finalize (GObject *object) } static void -xfce_bg_class_init (XfceBGClass *klass) -{ +xfce_bg_class_init (XfceBGClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = xfce_bg_dispose; @@ -618,8 +595,7 @@ xfce_bg_class_init (XfceBGClass *klass) } XfceBG * -xfce_bg_new (void) -{ +xfce_bg_new (void) { return g_object_new (XFCE_TYPE_BG, NULL); } @@ -627,15 +603,13 @@ static void xfce_bg_set_color (XfceBG *bg, XfceBGColorType type, GdkRGBA *primary, - GdkRGBA *secondary) -{ + GdkRGBA *secondary) { g_return_if_fail (bg != NULL); g_return_if_fail (primary != NULL); if (bg->color_type != type || !gdk_rgba_equal (&bg->primary, primary) || - (secondary && !gdk_rgba_equal (&bg->secondary, secondary))) - { + (secondary && !gdk_rgba_equal (&bg->secondary, secondary))) { bg->color_type = type; bg->primary = *primary; if (secondary) { @@ -648,8 +622,7 @@ xfce_bg_set_color (XfceBG *bg, static void xfce_bg_set_placement (XfceBG *bg, - XfceBGPlacement placement) -{ + XfceBGPlacement placement) { g_return_if_fail (bg != NULL); if (bg->placement != placement) { @@ -660,8 +633,7 @@ xfce_bg_set_placement (XfceBG *bg, } static inline gchar * -get_wallpaper_cache_dir () -{ +get_wallpaper_cache_dir () { return g_build_filename (g_get_user_cache_dir(), XFCE_BG_CACHE_DIR, NULL); } @@ -669,8 +641,7 @@ static inline gchar * get_wallpaper_cache_prefix_name (gint num_monitor, XfceBGPlacement placement, gint width, - gint height) -{ + gint height) { return g_strdup_printf ("%i_%i_%i_%i", num_monitor, (gint) placement, width, height); } @@ -679,8 +650,7 @@ get_wallpaper_cache_filename (const char *filename, gint num_monitor, XfceBGPlacement placement, gint width, - gint height) -{ + gint height) { gchar *cache_filename; gchar *cache_prefix_name; gchar *md5_filename; @@ -704,8 +674,7 @@ get_wallpaper_cache_filename (const char *filename, static void cleanup_cache_for_monitor (gchar *cache_dir, - gint num_monitor) -{ + gint num_monitor) { GDir *g_cache_dir; gchar *monitor_prefix; const gchar *file; @@ -733,8 +702,7 @@ cleanup_cache_for_monitor (gchar *cache_dir, static gboolean cache_file_is_valid (const char *filename, - const char *cache_filename) -{ + const char *cache_filename) { time_t mtime; time_t cache_mtime; @@ -752,8 +720,7 @@ refresh_cache_file (XfceBG *bg, GdkPixbuf *new_pixbuf, gint num_monitor, gint width, - gint height) -{ + gint height) { gchar *cache_filename; gchar *cache_dir; GdkPixbufFormat *format; @@ -799,8 +766,7 @@ file_changed (GFileMonitor *file_monitor, GFile *child, GFile *other_file, GFileMonitorEvent event_type, - gpointer user_data) -{ + gpointer user_data) { XfceBG *bg = XFCE_BG (user_data); clear_cache (bg); @@ -809,8 +775,7 @@ file_changed (GFileMonitor *file_monitor, static void xfce_bg_set_filename (XfceBG *bg, - const char *filename) -{ + const char *filename) { g_return_if_fail (bg != NULL); if (is_different (bg, filename)) { @@ -843,8 +808,7 @@ xfce_bg_set_filename (XfceBG *bg, static void draw_color_area (XfceBG *bg, GdkPixbuf *dest, - GdkRectangle *rect) -{ + GdkRectangle *rect) { guint32 pixel; GdkRectangle extent; @@ -881,8 +845,7 @@ draw_color_area (XfceBG *bg, static void draw_color (XfceBG *bg, - GdkPixbuf *dest) -{ + GdkPixbuf *dest) { GdkRectangle rect; rect.x = 0; @@ -895,8 +858,7 @@ draw_color (XfceBG *bg, static GdkPixbuf * pixbuf_clip_to_fit (GdkPixbuf *src, int max_width, - int max_height) -{ + int max_height) { int src_width, src_height; int w, h; int src_x, src_y; @@ -933,8 +895,7 @@ get_scaled_pixbuf (XfceBGPlacement placement, int *x, int *y, int *w, - int *h) -{ + int *h) { GdkPixbuf *new; #if 0 @@ -981,8 +942,7 @@ draw_image_area (XfceBG *bg, gint num_monitor, GdkPixbuf *pixbuf, GdkPixbuf *dest, - GdkRectangle *area) -{ + GdkRectangle *area) { int dest_width = area->width; int dest_height = area->height; int x, y, w, h; @@ -1018,8 +978,7 @@ draw_image_area (XfceBG *bg, static void draw_once (XfceBG *bg, - GdkPixbuf *dest) -{ + GdkPixbuf *dest) { GdkRectangle rect; GdkPixbuf *pixbuf; gint monitor; @@ -1041,8 +1000,7 @@ draw_once (XfceBG *bg, static void xfce_bg_draw (XfceBG *bg, - GdkPixbuf *dest) -{ + GdkPixbuf *dest) { if (!bg) return; @@ -1057,8 +1015,7 @@ xfce_bg_get_pixmap_size (XfceBG *bg, int width, int height, int *pixmap_width, - int *pixmap_height) -{ + int *pixmap_height) { int dummy; if (!pixmap_width) @@ -1101,8 +1058,7 @@ xfce_bg_create_surface (XfceBG *bg, int screen_width, int screen_height, int monitor_width, - int monitor_height) -{ + int monitor_height) { return xfce_bg_create_surface_scale (bg, window, screen_width, @@ -1117,19 +1073,15 @@ xfce_bg_get_pixbuf(XfceBG *bg, int screen_width, int screen_height, int monitor_width, - int monitor_height) -{ + int monitor_height) { GdkPixbuf *pixbuf; gint width; gint height; - if (bg->placement == XFCE_BG_PLACEMENT_SPANNED) - { + if (bg->placement == XFCE_BG_PLACEMENT_SPANNED) { width = screen_width; height = screen_height; - } - else - { + } else { width = monitor_width; height = monitor_height; } @@ -1159,8 +1111,7 @@ xfce_bg_create_surface_scale (XfceBG *bg, int screen_height, int monitor_width, int monitor_height, - int scale) -{ + int scale) { int pm_width, pm_height; int width, height; @@ -1180,8 +1131,7 @@ xfce_bg_create_surface_scale (XfceBG *bg, if (bg->pixbuf_cache && (gdk_pixbuf_get_width(bg->pixbuf_cache) != width || - gdk_pixbuf_get_height(bg->pixbuf_cache) != height)) - { + gdk_pixbuf_get_height(bg->pixbuf_cache) != height)) { g_object_unref(bg->pixbuf_cache); bg->pixbuf_cache = NULL; } @@ -1196,9 +1146,7 @@ xfce_bg_create_surface_scale (XfceBG *bg, if (!bg->filename && bg->color_type == XFCE_BG_COLOR_SOLID) { gdk_cairo_set_source_rgba (cr, &(bg->primary)); - } - else - { + } else { GdkPixbuf *pixbuf = xfce_bg_get_pixbuf(bg, screen_width, screen_height, monitor_width, monitor_height); gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); g_object_unref (pixbuf); @@ -1212,8 +1160,7 @@ xfce_bg_create_surface_scale (XfceBG *bg, } /* Implementation of the pixbuf cache */ -struct _SlideShow -{ +struct _SlideShow { gint ref_count; double start_time; double total_duration; @@ -1228,8 +1175,7 @@ struct _SlideShow }; static double -now (void) -{ +now (void) { GTimeVal tv; g_get_current_time (&tv); @@ -1239,8 +1185,7 @@ now (void) static Slide * get_current_slide (SlideShow *show, - double *alpha) -{ + double *alpha) { double delta = fmod (now() - show->start_time, show->total_duration); GList *list; double elapsed; @@ -1275,8 +1220,7 @@ get_current_slide (SlideShow *show, static GdkPixbuf * blend (GdkPixbuf *p1, GdkPixbuf *p2, - double alpha) -{ + double alpha) { GdkPixbuf *result = gdk_pixbuf_copy (p1); GdkPixbuf *tmp; @@ -1286,8 +1230,7 @@ blend (GdkPixbuf *p1, gdk_pixbuf_get_width (p1), gdk_pixbuf_get_height (p1), GDK_INTERP_BILINEAR); - } - else { + } else { tmp = g_object_ref (p2); } @@ -1304,8 +1247,7 @@ typedef enum { THUMBNAIL } FileType; -struct FileCacheEntry -{ +struct FileCacheEntry { FileType type; char *filename; union { @@ -1316,8 +1258,7 @@ struct FileCacheEntry }; static void -file_cache_entry_delete (FileCacheEntry *ent) -{ +file_cache_entry_delete (FileCacheEntry *ent) { g_free (ent->filename); switch (ent->type) { @@ -1336,8 +1277,7 @@ file_cache_entry_delete (FileCacheEntry *ent) } static void -bound_cache (XfceBG *bg) -{ +bound_cache (XfceBG *bg) { while (g_list_length (bg->file_cache) >= CACHE_SIZE) { GList *last_link = g_list_last (bg->file_cache); FileCacheEntry *ent = last_link->data; @@ -1351,8 +1291,7 @@ bound_cache (XfceBG *bg) static const FileCacheEntry * file_cache_lookup (XfceBG *bg, FileType type, - const char *filename) -{ + const char *filename) { GList *list; for (list = bg->file_cache; list != NULL; list = list->next) { @@ -1370,8 +1309,7 @@ file_cache_lookup (XfceBG *bg, static FileCacheEntry * file_cache_entry_new (XfceBG *bg, FileType type, - const char *filename) -{ + const char *filename) { FileCacheEntry *ent = g_new0 (FileCacheEntry, 1); g_assert (!file_cache_lookup (bg, type, filename)); @@ -1389,8 +1327,7 @@ file_cache_entry_new (XfceBG *bg, static void file_cache_add_pixbuf (XfceBG *bg, const char *filename, - GdkPixbuf *pixbuf) -{ + GdkPixbuf *pixbuf) { FileCacheEntry *ent = file_cache_entry_new (bg, PIXBUF, filename); ent->u.pixbuf = g_object_ref (pixbuf); } @@ -1398,8 +1335,7 @@ file_cache_add_pixbuf (XfceBG *bg, static void file_cache_add_slide_show (XfceBG *bg, const char *filename, - SlideShow *show) -{ + SlideShow *show) { FileCacheEntry *ent = file_cache_entry_new (bg, SLIDESHOW, filename); ent->u.slideshow = slideshow_ref (show); } @@ -1409,8 +1345,7 @@ load_from_cache_file (XfceBG *bg, const char *filename, gint num_monitor, gint best_width, - gint best_height) -{ + gint best_height) { GdkPixbuf *pixbuf = NULL; gchar *cache_filename; @@ -1430,8 +1365,7 @@ get_as_pixbuf_for_size (XfceBG *bg, const char *filename, gint monitor, gint best_width, - gint best_height) -{ + gint best_height) { const FileCacheEntry *ent; if ((ent = file_cache_lookup (bg, PIXBUF, filename))) { @@ -1457,8 +1391,7 @@ get_as_pixbuf_for_size (XfceBG *bg, (best_width > 0 && best_height > 0) && (bg->placement == XFCE_BG_PLACEMENT_FILL_SCREEN || bg->placement == XFCE_BG_PLACEMENT_SCALED || - bg->placement == XFCE_BG_PLACEMENT_ZOOMED)) - { + bg->placement == XFCE_BG_PLACEMENT_ZOOMED)) { pixbuf = gdk_pixbuf_new_from_file_at_size (filename, best_width, best_height, NULL); @@ -1483,13 +1416,11 @@ get_as_pixbuf_for_size (XfceBG *bg, static SlideShow * get_as_slideshow (XfceBG *bg, - const char *filename) -{ + const char *filename) { const FileCacheEntry *ent; if ((ent = file_cache_lookup (bg, SLIDESHOW, filename))) { return slideshow_ref (ent->u.slideshow); - } - else { + } else { SlideShow *show = read_slideshow_file (filename, NULL); if (show) @@ -1500,8 +1431,7 @@ get_as_slideshow (XfceBG *bg, } static gboolean -blow_expensive_caches (gpointer data) -{ +blow_expensive_caches (gpointer data) { XfceBG *bg = data; GList *list; @@ -1528,8 +1458,7 @@ blow_expensive_caches (gpointer data) } static void -blow_expensive_caches_in_idle (XfceBG *bg) -{ +blow_expensive_caches_in_idle (XfceBG *bg) { if (bg->blow_caches_id == 0) { bg->blow_caches_id = g_idle_add (blow_expensive_caches, @@ -1539,8 +1468,7 @@ blow_expensive_caches_in_idle (XfceBG *bg) static gboolean -on_timeout (gpointer data) -{ +on_timeout (gpointer data) { XfceBG *bg = data; bg->timeout_id = 0; @@ -1551,8 +1479,7 @@ on_timeout (gpointer data) } static double -get_slide_timeout (Slide *slide) -{ +get_slide_timeout (Slide *slide) { double timeout; if (slide->fixed) { timeout = slide->duration; @@ -1576,8 +1503,7 @@ get_slide_timeout (Slide *slide) static void ensure_timeout (XfceBG *bg, - Slide *slide) -{ + Slide *slide) { if (!bg->timeout_id) { double timeout = get_slide_timeout (slide); @@ -1587,13 +1513,11 @@ ensure_timeout (XfceBG *bg, G_PRIORITY_LOW, timeout * 1000, on_timeout, bg, NULL); } - } } static time_t -get_mtime (const char *filename) -{ +get_mtime (const char *filename) { GFile *file; GFileInfo *info; time_t mtime; @@ -1626,8 +1550,7 @@ get_mtime (const char *filename) static FileSize * find_best_size (GSList *sizes, gint width, - gint height) -{ + gint height) { GSList *s; gdouble a, d, distance; FileSize *best = NULL; @@ -1647,8 +1570,7 @@ find_best_size (GSList *sizes, if (d < distance) { distance = d; best = size; - } - else if (d == distance) { + } else if (d == distance) { if (abs (size->width - width) < abs (best->width - width)) { best = size; } @@ -1666,8 +1588,7 @@ static GdkPixbuf * get_pixbuf_for_size (XfceBG *bg, gint monitor, gint best_width, - gint best_height) -{ + gint best_height) { guint time_until_next_change; gboolean hit_cache = FALSE; @@ -1749,18 +1670,14 @@ get_pixbuf_for_size (XfceBG *bg, static gboolean is_different (XfceBG *bg, - const char *filename) -{ + const char *filename) { if (!filename && bg->filename) { return TRUE; - } - else if (filename && !bg->filename) { + } else if (filename && !bg->filename) { return TRUE; - } - else if (!filename && !bg->filename) { + } else if (!filename && !bg->filename) { return FALSE; - } - else { + } else { time_t mtime = get_mtime (filename); if (mtime != bg->file_mtime) @@ -1774,8 +1691,7 @@ is_different (XfceBG *bg, } static void -clear_cache (XfceBG *bg) -{ +clear_cache (XfceBG *bg) { GList *list; if (bg->file_cache) { @@ -1804,8 +1720,7 @@ clear_cache (XfceBG *bg) static GdkPixbuf * pixbuf_scale_to_fit (GdkPixbuf *src, int max_width, - int max_height) -{ + int max_height) { double factor; int src_width, src_height; int new_width, new_height; @@ -1824,8 +1739,7 @@ pixbuf_scale_to_fit (GdkPixbuf *src, static GdkPixbuf * pixbuf_scale_to_min (GdkPixbuf *src, int min_width, - int min_height) -{ + int min_height) { double factor; int src_width, src_height; int new_width, new_height; @@ -1860,8 +1774,7 @@ pixbuf_scale_to_min (GdkPixbuf *src, static guchar * create_gradient (const GdkRGBA *primary, const GdkRGBA *secondary, - int n_pixels) -{ + int n_pixels) { guchar *result = g_malloc (n_pixels * 3); int i; @@ -1881,8 +1794,7 @@ pixbuf_draw_gradient (GdkPixbuf *pixbuf, gboolean horizontal, GdkRGBA *primary, GdkRGBA *secondary, - GdkRectangle *rect) -{ + GdkRectangle *rect) { int width; int height; int rowstride; @@ -1938,8 +1850,7 @@ pixbuf_blend (GdkPixbuf *src, int src_height, int dest_x, int dest_y, - double alpha) -{ + double alpha) { int dest_width = gdk_pixbuf_get_width (dest); int dest_height = gdk_pixbuf_get_height (dest); int offset_x = dest_x - src_x; @@ -1975,8 +1886,7 @@ pixbuf_blend (GdkPixbuf *src, static void pixbuf_tile (GdkPixbuf *src, - GdkPixbuf *dest) -{ + GdkPixbuf *dest) { int x, y; int tile_width, tile_height; int dest_width = gdk_pixbuf_get_width (dest); @@ -2004,8 +1914,7 @@ handle_start_element (GMarkupParseContext *context, const gchar **attr_names, const gchar **attr_values, gpointer user_data, - GError **err) -{ + GError **err) { SlideShow *parser = user_data; gint i; @@ -2016,8 +1925,7 @@ handle_start_element (GMarkupParseContext *context, slide->fixed = TRUE; g_queue_push_tail (parser->slides, slide); - } - else if (strcmp (name, "size") == 0) { + } else if (strcmp (name, "size") == 0) { Slide *slide = parser->slides->tail->data; FileSize *size = g_new0 (FileSize, 1); for (i = 0; attr_names[i]; i++) { @@ -2030,8 +1938,7 @@ handle_start_element (GMarkupParseContext *context, (strcmp (parser->stack->tail->data, "file") == 0 || strcmp (parser->stack->tail->data, "from") == 0)) { slide->file1 = g_slist_prepend (slide->file1, size); - } - else if (parser->stack->tail && + } else if (parser->stack->tail && strcmp (parser->stack->tail->data, "to") == 0) { slide->file2 = g_slist_prepend (slide->file2, size); } @@ -2043,8 +1950,7 @@ static void handle_end_element (GMarkupParseContext *context, const gchar *name, gpointer user_data, - GError **err) -{ + GError **err) { SlideShow *parser = user_data; g_free (g_queue_pop_tail (parser->stack)); @@ -2053,8 +1959,7 @@ handle_end_element (GMarkupParseContext *context, static gboolean stack_is (SlideShow *parser, const char *s1, - ...) -{ + ...) { GList *stack = NULL; const char *s; GList *l1, *l2; @@ -2091,8 +1996,7 @@ stack_is (SlideShow *parser, } static int -parse_int (const char *text) -{ +parse_int (const char *text) { return strtol (text, NULL, 0); } @@ -2101,8 +2005,7 @@ handle_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, - GError **err) -{ + GError **err) { SlideShow *parser = user_data; FileSize *fs; gint i; @@ -2114,30 +2017,23 @@ handle_text (GMarkupParseContext *context, if (stack_is (parser, "year", "starttime", "background", NULL)) { parser->start_tm.tm_year = parse_int (text) - 1900; - } - else if (stack_is (parser, "month", "starttime", "background", NULL)) { + } else if (stack_is (parser, "month", "starttime", "background", NULL)) { parser->start_tm.tm_mon = parse_int (text) - 1; - } - else if (stack_is (parser, "day", "starttime", "background", NULL)) { + } else if (stack_is (parser, "day", "starttime", "background", NULL)) { parser->start_tm.tm_mday = parse_int (text); - } - else if (stack_is (parser, "hour", "starttime", "background", NULL)) { + } else if (stack_is (parser, "hour", "starttime", "background", NULL)) { parser->start_tm.tm_hour = parse_int (text) - 1; - } - else if (stack_is (parser, "minute", "starttime", "background", NULL)) { + } else if (stack_is (parser, "minute", "starttime", "background", NULL)) { parser->start_tm.tm_min = parse_int (text); - } - else if (stack_is (parser, "second", "starttime", "background", NULL)) { + } else if (stack_is (parser, "second", "starttime", "background", NULL)) { parser->start_tm.tm_sec = parse_int (text); - } - else if (stack_is (parser, "duration", "static", "background", NULL) || + } else if (stack_is (parser, "duration", "static", "background", NULL) || stack_is (parser, "duration", "transition", "background", NULL)) { g_return_if_fail (slide != NULL); slide->duration = g_strtod (text, NULL); parser->total_duration += slide->duration; - } - else if (stack_is (parser, "file", "static", "background", NULL) || + } else if (stack_is (parser, "file", "static", "background", NULL) || stack_is (parser, "from", "transition", "background", NULL)) { g_return_if_fail (slide != NULL); @@ -2154,8 +2050,7 @@ handle_text (GMarkupParseContext *context, slide->file1 = g_slist_prepend (slide->file1, fs); if (slide->file1->next != NULL) parser->has_multiple_sizes = TRUE; - } - else if (stack_is (parser, "size", "file", "static", "background", NULL) || + } else if (stack_is (parser, "size", "file", "static", "background", NULL) || stack_is (parser, "size", "from", "transition", "background", NULL)) { g_return_if_fail (slide != NULL); @@ -2163,8 +2058,7 @@ handle_text (GMarkupParseContext *context, fs->file = g_strdup (text); if (slide->file1->next != NULL) parser->has_multiple_sizes = TRUE; - } - else if (stack_is (parser, "to", "transition", "background", NULL)) { + } else if (stack_is (parser, "to", "transition", "background", NULL)) { g_return_if_fail (slide != NULL); for (i = 0; text[i]; i++) { @@ -2180,8 +2074,7 @@ handle_text (GMarkupParseContext *context, slide->file2 = g_slist_prepend (slide->file2, fs); if (slide->file2->next != NULL) parser->has_multiple_sizes = TRUE; - } - else if (stack_is (parser, "size", "to", "transition", "background", NULL)) { + } else if (stack_is (parser, "size", "to", "transition", "background", NULL)) { g_return_if_fail (slide != NULL); fs = slide->file2->data; @@ -2192,15 +2085,13 @@ handle_text (GMarkupParseContext *context, } static SlideShow * -slideshow_ref (SlideShow *show) -{ +slideshow_ref (SlideShow *show) { show->ref_count++; return show; } static void -slideshow_unref (SlideShow *show) -{ +slideshow_unref (SlideShow *show) { GList *list; GSList *slist; FileSize *size; @@ -2238,14 +2129,12 @@ slideshow_unref (SlideShow *show) } static void -dump_bg (SlideShow *show) -{ +dump_bg (SlideShow *show) { #if 0 GList *list; GSList *slist; - for (list = show->slides->head; list != NULL; list = list->next) - { + for (list = show->slides->head; list != NULL; list = list->next) { Slide *slide = list->data; g_print ("\nSlide: %s\n", slide->fixed? "fixed" : "transition"); @@ -2268,8 +2157,7 @@ dump_bg (SlideShow *show) static void threadsafe_localtime (time_t time, - struct tm *tm) -{ + struct tm *tm) { struct tm *res; G_LOCK_DEFINE_STATIC (localtime_mutex); @@ -2286,8 +2174,7 @@ threadsafe_localtime (time_t time, static SlideShow * read_slideshow_file (const char *filename, - GError **err) -{ + GError **err) { GMarkupParser parser = { handle_start_element, handle_end_element, diff --git a/src/xfce-desktop-utils.c b/src/xfce-desktop-utils.c index 1bce5170d10fad5b29e40b255812e705e7ee3bdd..cfd7388176b1d427b283c4735c074adea0737d64 100644 --- a/src/xfce-desktop-utils.c +++ b/src/xfce-desktop-utils.c @@ -24,12 +24,14 @@ */ #include <config.h> -#include <glib.h> + #include <gio/gio.h> -#include <libxfce4util/libxfce4util.h> +#include <glib.h> #include <gdk/gdk.h> #include <gtk/gtk.h> +#include <libxfce4util/libxfce4util.h> + #include <xfce-desktop-utils.h> /** @@ -56,8 +58,7 @@ gboolean xfce_gdk_spawn_command_line_on_screen (GdkScreen *screen, const gchar *command, - GError **error) -{ + GError **error) { GAppInfo *appinfo = NULL; GdkAppLaunchContext *context = NULL; gboolean res = FALSE; diff --git a/src/xfce-rr.c b/src/xfce-rr.c index 81fcfe1dc8e17faafecead88af2d8d439c2b73f1..0d6d09f81577a7d821cce315996fcb6fae0090d5 100644 --- a/src/xfce-rr.c +++ b/src/xfce-rr.c @@ -22,8 +22,10 @@ */ #include <config.h> -#include <libxfce4util/libxfce4util.h> + #include <string.h> + +#include <X11/Xatom.h> #include <X11/Xlib.h> #ifdef HAVE_RANDR @@ -32,11 +34,11 @@ #include <gtk/gtk.h> #include <gdk/gdkx.h> -#include <X11/Xatom.h> -#include "xfce-rr.h" +#include <libxfce4util/libxfce4util.h> -#include "xfce-rr-private.h" +#include "src/xfce-rr.h" +#include "src/xfce-rr-private.h" #define DISPLAY(o) ((o)->info->screen->priv->xdisplay) @@ -67,8 +69,7 @@ enum { gint screen_signals[SCREEN_SIGNAL_LAST]; -struct XfceRROutput -{ +struct XfceRROutput { ScreenInfo *info; RROutput id; @@ -86,13 +87,11 @@ struct XfceRROutput char *connector_type; }; -struct XfceRROutputWrap -{ +struct XfceRROutputWrap { RROutput id; }; -struct XfceRRCrtc -{ +struct XfceRRCrtc { ScreenInfo *info; RRCrtc id; @@ -107,8 +106,7 @@ struct XfceRRCrtc int gamma_size; }; -struct XfceRRMode -{ +struct XfceRRMode { ScreenInfo *info; RRMode id; char *name; @@ -197,22 +195,19 @@ G_DEFINE_BOXED_TYPE (XfceRRMode, xfce_rr_mode, mode_copy, mode_free) * Return value: a #GQuark used to identify errors coming from the XfceRR API. */ GQuark -xfce_rr_error_quark (void) -{ +xfce_rr_error_quark (void) { return g_quark_from_static_string ("xfce-rr-error-quark"); } /* Screen */ static XfceRROutput * xfce_rr_output_by_id (ScreenInfo *info, - RROutput id) -{ + RROutput id) { XfceRROutput **output; g_assert (info != NULL); - for (output = info->outputs; *output; ++output) - { + for (output = info->outputs; *output; ++output) { if ((*output)->id == id) return *output; } @@ -222,15 +217,13 @@ xfce_rr_output_by_id (ScreenInfo *info, static XfceRRCrtc * crtc_by_id (ScreenInfo *info, - RRCrtc id) -{ + RRCrtc id) { XfceRRCrtc **crtc; if (!info) return NULL; - for (crtc = info->crtcs; *crtc; ++crtc) - { + for (crtc = info->crtcs; *crtc; ++crtc) { if ((*crtc)->id == id) return *crtc; } @@ -240,14 +233,12 @@ crtc_by_id (ScreenInfo *info, static XfceRRMode * mode_by_id (ScreenInfo *info, - RRMode id) -{ + RRMode id) { XfceRRMode **mode; g_assert (info != NULL); - for (mode = info->modes; *mode; ++mode) - { + for (mode = info->modes; *mode; ++mode) { if ((*mode)->id == id) return *mode; } @@ -256,8 +247,7 @@ mode_by_id (ScreenInfo *info, } static void -screen_info_free (ScreenInfo *info) -{ +screen_info_free (ScreenInfo *info) { XfceRROutput **output; XfceRRCrtc **crtc; XfceRRMode **mode; @@ -265,37 +255,32 @@ screen_info_free (ScreenInfo *info) g_assert (info != NULL); #ifdef HAVE_RANDR - if (info->resources) - { + if (info->resources) { XRRFreeScreenResources (info->resources); info->resources = NULL; } #endif - if (info->outputs) - { + if (info->outputs) { for (output = info->outputs; *output; ++output) output_free (*output); g_free (info->outputs); } - if (info->crtcs) - { + if (info->crtcs) { for (crtc = info->crtcs; *crtc; ++crtc) crtc_free (*crtc); g_free (info->crtcs); } - if (info->modes) - { + if (info->modes) { for (mode = info->modes; *mode; ++mode) mode_free (*mode); g_free (info->modes); } - if (info->clone_modes) - { + if (info->clone_modes) { /* The modes themselves were freed above */ g_free (info->clone_modes); } @@ -305,20 +290,17 @@ screen_info_free (ScreenInfo *info) static gboolean has_similar_mode (XfceRROutput *output, - XfceRRMode *mode) -{ + XfceRRMode *mode) { int i; XfceRRMode **modes = xfce_rr_output_list_modes (output); int width = xfce_rr_mode_get_width (mode); int height = xfce_rr_mode_get_height (mode); - for (i = 0; modes[i] != NULL; ++i) - { + for (i = 0; modes[i] != NULL; ++i) { XfceRRMode *m = modes[i]; if (xfce_rr_mode_get_width (m) == width && - xfce_rr_mode_get_height (m) == height) - { + xfce_rr_mode_get_height (m) == height) { return TRUE; } } @@ -327,13 +309,11 @@ has_similar_mode (XfceRROutput *output, } static void -gather_clone_modes (ScreenInfo *info) -{ +gather_clone_modes (ScreenInfo *info) { int i; GPtrArray *result = g_ptr_array_new (); - for (i = 0; info->outputs[i] != NULL; ++i) - { + for (i = 0; info->outputs[i] != NULL; ++i) { int j; XfceRROutput *output1, *output2; @@ -342,22 +322,19 @@ gather_clone_modes (ScreenInfo *info) if (!output1->connected) continue; - for (j = 0; output1->modes[j] != NULL; ++j) - { + for (j = 0; output1->modes[j] != NULL; ++j) { XfceRRMode *mode = output1->modes[j]; gboolean valid; int k; valid = TRUE; - for (k = 0; info->outputs[k] != NULL; ++k) - { + for (k = 0; info->outputs[k] != NULL; ++k) { output2 = info->outputs[k]; if (!output2->connected) continue; - if (!has_similar_mode (output2, mode)) - { + if (!has_similar_mode (output2, mode)) { valid = FALSE; break; } @@ -377,8 +354,7 @@ gather_clone_modes (ScreenInfo *info) static gboolean fill_screen_info_from_resources (ScreenInfo *info, XRRScreenResources *resources, - GError **error) -{ + GError **error) { int i; GPtrArray *a; XfceRRCrtc **crtc; @@ -390,8 +366,7 @@ fill_screen_info_from_resources (ScreenInfo *info, * that they can refer to each other. */ a = g_ptr_array_new (); - for (i = 0; i < resources->ncrtc; ++i) - { + for (i = 0; i < resources->ncrtc; ++i) { XfceRRCrtc *crtc = crtc_new (info, resources->crtcs[i]); g_ptr_array_add (a, crtc); @@ -400,8 +375,7 @@ fill_screen_info_from_resources (ScreenInfo *info, info->crtcs = (XfceRRCrtc **)g_ptr_array_free (a, FALSE); a = g_ptr_array_new (); - for (i = 0; i < resources->noutput; ++i) - { + for (i = 0; i < resources->noutput; ++i) { XfceRROutput *output = output_new (info, resources->outputs[i]); g_ptr_array_add (a, output); @@ -410,8 +384,7 @@ fill_screen_info_from_resources (ScreenInfo *info, info->outputs = (XfceRROutput **)g_ptr_array_free (a, FALSE); a = g_ptr_array_new (); - for (i = 0; i < resources->nmode; ++i) - { + for (i = 0; i < resources->nmode; ++i) { XfceRRMode *mode = mode_new (info, resources->modes[i].id); g_ptr_array_add (a, mode); @@ -420,20 +393,17 @@ fill_screen_info_from_resources (ScreenInfo *info, info->modes = (XfceRRMode **)g_ptr_array_free (a, FALSE); /* Initialize */ - for (crtc = info->crtcs; *crtc; ++crtc) - { + for (crtc = info->crtcs; *crtc; ++crtc) { if (!crtc_initialize (*crtc, resources, error)) return FALSE; } - for (output = info->outputs; *output; ++output) - { + for (output = info->outputs; *output; ++output) { if (!output_initialize (*output, resources, error)) return FALSE; } - for (i = 0; i < resources->nmode; ++i) - { + for (i = 0; i < resources->nmode; ++i) { XfceRRMode *mode = mode_by_id (info, resources->modes[i].id); mode_initialize (mode, &(resources->modes[i])); @@ -450,8 +420,7 @@ fill_out_screen_info (Display *xdisplay, Window xroot, ScreenInfo *info, gboolean needs_reprobe, - GError **error) -{ + GError **error) { #ifdef HAVE_RANDR XRRScreenResources *resources; GdkDisplay *display; @@ -466,13 +435,10 @@ fill_out_screen_info (Display *xdisplay, else resources = XRRGetScreenResourcesCurrent (xdisplay, xroot); - if (resources) - { + if (resources) { if (!fill_screen_info_from_resources (info, resources, error)) return FALSE; - } - else - { + } else { g_set_error (error, XFCE_RR_ERROR, XFCE_RR_ERROR_RANDR_ERROR, /* Translators: a CRTC is a CRT Controller (this is X terminology). */ _("could not get the screen resources (CRTCs, outputs, modes)")); @@ -505,9 +471,7 @@ fill_out_screen_info (Display *xdisplay, _("could not get the range of screen sizes")); return FALSE; } - } - else - { + } else { xfce_rr_screen_get_ranges (info->screen, &(info->min_width), &(info->max_width), @@ -530,8 +494,7 @@ fill_out_screen_info (Display *xdisplay, static ScreenInfo * screen_info_new (XfceRRScreen *screen, gboolean needs_reprobe, - GError **error) -{ + GError **error) { ScreenInfo *info = g_new0 (ScreenInfo, 1); XfceRRScreenPrivate *priv; @@ -544,12 +507,9 @@ screen_info_new (XfceRRScreen *screen, info->modes = NULL; info->screen = screen; - if (fill_out_screen_info (priv->xdisplay, priv->xroot, info, needs_reprobe, error)) - { + if (fill_out_screen_info (priv->xdisplay, priv->xroot, info, needs_reprobe, error)) { return info; - } - else - { + } else { screen_info_free (info); return NULL; } @@ -559,8 +519,7 @@ static gboolean screen_update (XfceRRScreen *screen, gboolean force_callback, gboolean needs_reprobe, - GError **error) -{ + GError **error) { ScreenInfo *info; gboolean changed = FALSE; @@ -588,8 +547,7 @@ screen_update (XfceRRScreen *screen, static GdkFilterReturn screen_on_event (GdkXEvent *xevent, GdkEvent *event, - gpointer data) -{ + gpointer data) { #ifdef HAVE_RANDR XfceRRScreen *screen = data; XfceRRScreenPrivate *priv = screen->priv; @@ -654,8 +612,7 @@ screen_on_event (GdkXEvent *xevent, * Note that the X server sends RRScreenChangeNotify in conjunction with the * more detailed events from RANDR 1.2 - see xserver/randr/randr.c:TellChanged(). */ - else if (event_num == RRNotify) - { + else if (event_num == RRNotify) { /* Other RandR events */ XRRNotifyEvent *event = (XRRNotifyEvent *)e; @@ -665,8 +622,7 @@ screen_on_event (GdkXEvent *xevent, * don't have anything special to do for particular subevent types, so * we leave this as an empty switch(). */ - switch (event->subtype) - { + switch (event->subtype) { default: break; } @@ -685,8 +641,7 @@ screen_on_event (GdkXEvent *xevent, static gboolean xfce_rr_screen_initable_init (GInitable *initable, GCancellable *canc, - GError **error) -{ + GError **error) { XfceRRScreen *self = XFCE_RR_SCREEN (initable); XfceRRScreenPrivate *priv = self->priv; Display *dpy = GDK_SCREEN_XDISPLAY (self->priv->gdk_screen); @@ -696,8 +651,7 @@ xfce_rr_screen_initable_init (GInitable *initable, priv->connector_type_atom = XInternAtom (dpy, "ConnectorType", FALSE); #ifdef HAVE_RANDR - if (XRRQueryExtension (dpy, &event_base, &ignore)) - { + if (XRRQueryExtension (dpy, &event_base, &ignore)) { priv->randr_event_base = event_base; XRRQueryVersion (dpy, &priv->rr_major_version, &priv->rr_minor_version); @@ -722,9 +676,7 @@ xfce_rr_screen_initable_init (GInitable *initable, gdk_window_add_filter (priv->gdk_root, screen_on_event, self); return TRUE; - } - else - { + } else { #endif /* HAVE_RANDR */ g_set_error (error, XFCE_RR_ERROR, XFCE_RR_ERROR_NO_RANDR_EXTENSION, _("RANDR extension is not present")); @@ -732,19 +684,17 @@ xfce_rr_screen_initable_init (GInitable *initable, return FALSE; #ifdef HAVE_RANDR - } + } #endif } void -xfce_rr_screen_initable_iface_init (GInitableIface *iface) -{ +xfce_rr_screen_initable_iface_init (GInitableIface *iface) { iface->init = xfce_rr_screen_initable_init; } void -xfce_rr_screen_finalize (GObject *gobject) -{ +xfce_rr_screen_finalize (GObject *gobject) { XfceRRScreen *screen = XFCE_RR_SCREEN (gobject); gdk_window_remove_filter (screen->priv->gdk_root, screen_on_event, screen); @@ -759,13 +709,11 @@ void xfce_rr_screen_set_property (GObject *gobject, guint property_id, const GValue *value, - GParamSpec *property) -{ + GParamSpec *property) { XfceRRScreen *self = XFCE_RR_SCREEN (gobject); XfceRRScreenPrivate *priv = self->priv; - switch (property_id) - { + switch (property_id) { case SCREEN_PROP_GDK_SCREEN: priv->gdk_screen = g_value_get_object (value); priv->gdk_root = gdk_screen_get_root_window (priv->gdk_screen); @@ -783,13 +731,11 @@ void xfce_rr_screen_get_property (GObject *gobject, guint property_id, GValue *value, - GParamSpec *property) -{ + GParamSpec *property) { XfceRRScreen *self = XFCE_RR_SCREEN (gobject); XfceRRScreenPrivate *priv = self->priv; - switch (property_id) - { + switch (property_id) { case SCREEN_PROP_GDK_SCREEN: g_value_set_object (value, priv->gdk_screen); return; @@ -800,8 +746,7 @@ xfce_rr_screen_get_property (GObject *gobject, } void -xfce_rr_screen_class_init (XfceRRScreenClass *klass) -{ +xfce_rr_screen_class_init (XfceRRScreenClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* GObject 2.58 */ g_type_class_add_private (klass, sizeof (XfceRRScreenPrivate)); @@ -833,8 +778,7 @@ xfce_rr_screen_class_init (XfceRRScreenClass *klass) } void -xfce_rr_screen_init (XfceRRScreen *self) -{ +xfce_rr_screen_init (XfceRRScreen *self) { XfceRRScreenPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, XFCE_TYPE_RR_SCREEN, XfceRRScreenPrivate); self->priv = priv; @@ -860,9 +804,7 @@ xfce_rr_screen_init (XfceRRScreen *self) */ XfceRRScreen * xfce_rr_screen_new (GdkScreen *screen, - GError **error) -{ - //bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); + GError **error) { bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); return g_initable_new (XFCE_TYPE_RR_SCREEN, NULL, error, "gdk-screen", screen, NULL); } @@ -882,8 +824,7 @@ xfce_rr_screen_get_ranges (XfceRRScreen *screen, int *min_width, int *max_width, int *min_height, - int *max_height) -{ + int *max_height) { XfceRRScreenPrivate *priv; g_return_if_fail (XFCE_IS_RR_SCREEN (screen)); @@ -904,8 +845,7 @@ xfce_rr_screen_get_ranges (XfceRRScreen *screen, } static gboolean -force_timestamp_update (XfceRRScreen *screen) -{ +force_timestamp_update (XfceRRScreen *screen) { #ifdef HAVE_RANDR XfceRRScreenPrivate *priv = screen->priv; XfceRRCrtc *crtc; @@ -971,8 +911,7 @@ out: */ gboolean xfce_rr_screen_refresh (XfceRRScreen *screen, - GError **error) -{ + GError **error) { gboolean refreshed; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); @@ -980,7 +919,9 @@ xfce_rr_screen_refresh (XfceRRScreen *screen, gdk_x11_display_grab (gdk_screen_get_display (screen->priv->gdk_screen)); refreshed = screen_update (screen, FALSE, TRUE, error); - force_timestamp_update (screen); /* this is to keep other clients from thinking that the X server re-detected things by itself - bgo#621046 */ + + /* Keep other clients from thinking that the X server re-detected things by itself - bgo#621046 */ + force_timestamp_update (screen); gdk_x11_display_ungrab (gdk_screen_get_display (screen->priv->gdk_screen)); @@ -995,8 +936,7 @@ xfce_rr_screen_refresh (XfceRRScreen *screen, * Returns: (array zero-terminated=1) (transfer none): */ XfceRRCrtc ** -xfce_rr_screen_list_crtcs (XfceRRScreen *screen) -{ +xfce_rr_screen_list_crtcs (XfceRRScreen *screen) { g_return_val_if_fail (XFCE_IS_RR_SCREEN (screen), NULL); g_return_val_if_fail (screen->priv->info != NULL, NULL); @@ -1006,8 +946,7 @@ xfce_rr_screen_list_crtcs (XfceRRScreen *screen) /* XfceRROutput */ static XfceRROutput * output_new (ScreenInfo *info, - RROutput id) -{ + RROutput id) { XfceRROutput *output = g_slice_new0 (XfceRROutput); output->id = id; @@ -1020,8 +959,7 @@ static guint8 * get_property (Display *dpy, RROutput output, Atom atom, - int *len) -{ + int *len) { #ifdef HAVE_RANDR unsigned char *prop; int actual_format; @@ -1035,14 +973,11 @@ get_property (Display *dpy, &actual_type, &actual_format, &nitems, &bytes_after, &prop); - if (actual_type == XA_INTEGER && actual_format == 8) - { + if (actual_type == XA_INTEGER && actual_format == 8) { result = g_memdup (prop, nitems); if (len) *len = nitems; - } - else - { + } else { result = NULL; } @@ -1055,8 +990,7 @@ get_property (Display *dpy, } static guint8 * -read_edid_data (XfceRROutput *output, int *len) -{ +read_edid_data (XfceRROutput *output, int *len) { Atom edid_atom; guint8 *result; @@ -1064,15 +998,13 @@ read_edid_data (XfceRROutput *output, int *len) result = get_property (DISPLAY (output), output->id, edid_atom, len); - if (!result) - { + if (!result) { edid_atom = XInternAtom (DISPLAY (output), "EDID_DATA", FALSE); result = get_property (DISPLAY (output), output->id, edid_atom, len); } - if (result) - { + if (result) { if (*len % 128 == 0) return result; else @@ -1083,8 +1015,7 @@ read_edid_data (XfceRROutput *output, int *len) } static char * -get_connector_type_string (XfceRROutput *output) -{ +get_connector_type_string (XfceRROutput *output) { #ifdef HAVE_RANDR char *result; unsigned char *prop; @@ -1128,8 +1059,7 @@ out: static gboolean output_initialize (XfceRROutput *output, XRRScreenResources *res, - GError **error) -{ + GError **error) { XRROutputInfo *info = XRRGetOutputInfo (DISPLAY (output), res, output->id); GPtrArray *a; int i; @@ -1138,8 +1068,7 @@ output_initialize (XfceRROutput *output, g_print ("Output %lx Timestamp: %u\n", output->id, (guint32)info->timestamp); #endif - if (!info || !output->info) - { + if (!info || !output->info) { /* FIXME: see the comment in crtc_initialize() */ /* Translators: here, an "output" is a video output */ g_set_error (error, XFCE_RR_ERROR, XFCE_RR_ERROR_RANDR_ERROR, @@ -1158,8 +1087,7 @@ output_initialize (XfceRROutput *output, /* Possible crtcs */ a = g_ptr_array_new (); - for (i = 0; i < info->ncrtc; ++i) - { + for (i = 0; i < info->ncrtc; ++i) { XfceRRCrtc *crtc = crtc_by_id (output->info, info->crtcs[i]); if (crtc) @@ -1170,8 +1098,7 @@ output_initialize (XfceRROutput *output, /* Clones */ a = g_ptr_array_new (); - for (i = 0; i < info->nclone; ++i) - { + for (i = 0; i < info->nclone; ++i) { XfceRROutput *xfce_rr_output = xfce_rr_output_by_id (output->info, info->clones[i]); if (xfce_rr_output) @@ -1182,8 +1109,7 @@ output_initialize (XfceRROutput *output, /* Modes */ a = g_ptr_array_new (); - for (i = 0; i < info->nmode; ++i) - { + for (i = 0; i < info->nmode; ++i) { XfceRRMode *mode = mode_by_id (output->info, info->modes[i]); if (mode) @@ -1204,8 +1130,7 @@ output_initialize (XfceRROutput *output, #endif /* HAVE_RANDR */ static XfceRROutput* -output_copy (const XfceRROutput *from) -{ +output_copy (const XfceRROutput *from) { GPtrArray *array; XfceRRCrtc **p_crtc; XfceRROutput **p_output; @@ -1223,22 +1148,19 @@ output_copy (const XfceRROutput *from) output->connector_type = g_strdup (from->connector_type); array = g_ptr_array_new (); - for (p_crtc = from->possible_crtcs; *p_crtc != NULL; p_crtc++) - { + for (p_crtc = from->possible_crtcs; *p_crtc != NULL; p_crtc++) { g_ptr_array_add (array, *p_crtc); } output->possible_crtcs = (XfceRRCrtc**) g_ptr_array_free (array, FALSE); array = g_ptr_array_new (); - for (p_output = from->clones; *p_output != NULL; p_output++) - { + for (p_output = from->clones; *p_output != NULL; p_output++) { g_ptr_array_add (array, *p_output); } output->clones = (XfceRROutput**) g_ptr_array_free (array, FALSE); array = g_ptr_array_new (); - for (p_mode = from->modes; *p_mode != NULL; p_mode++) - { + for (p_mode = from->modes; *p_mode != NULL; p_mode++) { g_ptr_array_add (array, *p_mode); } output->modes = (XfceRRMode**) g_ptr_array_free (array, FALSE); @@ -1250,8 +1172,7 @@ output_copy (const XfceRROutput *from) } static void -output_free (XfceRROutput *output) -{ +output_free (XfceRROutput *output) { g_free (output->clones); g_free (output->modes); g_free (output->possible_crtcs); @@ -1268,21 +1189,18 @@ output_free (XfceRROutput *output) */ static XfceRRMode ** -xfce_rr_output_list_modes (XfceRROutput *output) -{ +xfce_rr_output_list_modes (XfceRROutput *output) { g_return_val_if_fail (output != NULL, NULL); return output->modes; } /* XfceRRCrtc */ -typedef struct -{ +typedef struct { Rotation xrot; XfceRRRotation rot; } RotationMap; -static const RotationMap rotation_map[] = -{ +static const RotationMap rotation_map[] = { { RR_Rotate_0, XFCE_RR_ROTATION_0 }, { RR_Rotate_90, XFCE_RR_ROTATION_90 }, { RR_Rotate_180, XFCE_RR_ROTATION_180 }, @@ -1292,13 +1210,11 @@ static const RotationMap rotation_map[] = }; static XfceRRRotation -xfce_rr_rotation_from_xrotation (Rotation r) -{ +xfce_rr_rotation_from_xrotation (Rotation r) { int i; XfceRRRotation result = 0; - for (i = 0; i < G_N_ELEMENTS (rotation_map); ++i) - { + for (i = 0; i < G_N_ELEMENTS (rotation_map); ++i) { if (r & rotation_map[i].xrot) result |= rotation_map[i].rot; } @@ -1312,16 +1228,14 @@ xfce_rr_rotation_from_xrotation (Rotation r) * Returns: (transfer none): the current mode of this crtc */ XfceRRMode * -xfce_rr_crtc_get_current_mode (XfceRRCrtc *crtc) -{ +xfce_rr_crtc_get_current_mode (XfceRRCrtc *crtc) { g_return_val_if_fail (crtc != NULL, NULL); return crtc->current_mode; } static XfceRRCrtc * -crtc_new (ScreenInfo *info, RROutput id) -{ +crtc_new (ScreenInfo *info, RROutput id) { XfceRRCrtc *crtc = g_slice_new0 (XfceRRCrtc); crtc->id = id; @@ -1331,8 +1245,7 @@ crtc_new (ScreenInfo *info, RROutput id) } static XfceRRCrtc * -crtc_copy (const XfceRRCrtc *from) -{ +crtc_copy (const XfceRRCrtc *from) { XfceRROutput **p_output; GPtrArray *array; XfceRRCrtc *to = g_slice_new0 (XfceRRCrtc); @@ -1347,15 +1260,13 @@ crtc_copy (const XfceRRCrtc *from) to->gamma_size = from->gamma_size; array = g_ptr_array_new (); - for (p_output = from->current_outputs; *p_output != NULL; p_output++) - { + for (p_output = from->current_outputs; *p_output != NULL; p_output++) { g_ptr_array_add (array, *p_output); } to->current_outputs = (XfceRROutput**) g_ptr_array_free (array, FALSE); array = g_ptr_array_new (); - for (p_output = from->possible_outputs; *p_output != NULL; p_output++) - { + for (p_output = from->possible_outputs; *p_output != NULL; p_output++) { g_ptr_array_add (array, *p_output); } to->possible_outputs = (XfceRROutput**) g_ptr_array_free (array, FALSE); @@ -1367,8 +1278,7 @@ crtc_copy (const XfceRRCrtc *from) static gboolean crtc_initialize (XfceRRCrtc *crtc, XRRScreenResources *res, - GError **error) -{ + GError **error) { XRRCrtcInfo *info = XRRGetCrtcInfo (DISPLAY (crtc), res, crtc->id); GPtrArray *a; int i; @@ -1377,8 +1287,7 @@ crtc_initialize (XfceRRCrtc *crtc, g_print ("CRTC %lx Timestamp: %u\n", crtc->id, (guint32)info->timestamp); #endif - if (!info) - { + if (!info) { /* FIXME: We need to reaquire the screen resources */ /* FIXME: can we actually catch BadRRCrtc, and does it make sense to emit that? */ @@ -1399,8 +1308,7 @@ crtc_initialize (XfceRRCrtc *crtc, /* Current outputs */ a = g_ptr_array_new (); - for (i = 0; i < info->noutput; ++i) - { + for (i = 0; i < info->noutput; ++i) { XfceRROutput *output = xfce_rr_output_by_id (crtc->info, info->outputs[i]); if (output) @@ -1411,8 +1319,7 @@ crtc_initialize (XfceRRCrtc *crtc, /* Possible outputs */ a = g_ptr_array_new (); - for (i = 0; i < info->npossible; ++i) - { + for (i = 0; i < info->npossible; ++i) { XfceRROutput *output = xfce_rr_output_by_id (crtc->info, info->possible[i]); if (output) @@ -1435,8 +1342,7 @@ crtc_initialize (XfceRRCrtc *crtc, #endif static void -crtc_free (XfceRRCrtc *crtc) -{ +crtc_free (XfceRRCrtc *crtc) { g_free (crtc->current_outputs); g_free (crtc->possible_outputs); g_slice_free (XfceRRCrtc, crtc); @@ -1444,8 +1350,7 @@ crtc_free (XfceRRCrtc *crtc) /* XfceRRMode */ static XfceRRMode * -mode_new (ScreenInfo *info, RRMode id) -{ +mode_new (ScreenInfo *info, RRMode id) { XfceRRMode *mode = g_slice_new0 (XfceRRMode); mode->id = id; @@ -1455,15 +1360,13 @@ mode_new (ScreenInfo *info, RRMode id) } static guint -xfce_rr_mode_get_width (XfceRRMode *mode) -{ +xfce_rr_mode_get_width (XfceRRMode *mode) { g_return_val_if_fail (mode != NULL, 0); return mode->width; } static guint -xfce_rr_mode_get_height (XfceRRMode *mode) -{ +xfce_rr_mode_get_height (XfceRRMode *mode) { g_return_val_if_fail (mode != NULL, 0); return mode->height; } @@ -1471,8 +1374,7 @@ xfce_rr_mode_get_height (XfceRRMode *mode) #ifdef HAVE_RANDR static void mode_initialize (XfceRRMode *mode, - XRRModeInfo *info) -{ + XRRModeInfo *info) { g_assert (mode != NULL); g_assert (info != NULL); @@ -1484,8 +1386,7 @@ mode_initialize (XfceRRMode *mode, #endif /* HAVE_RANDR */ static XfceRRMode * -mode_copy (const XfceRRMode *from) -{ +mode_copy (const XfceRRMode *from) { XfceRRMode *to = g_slice_new0 (XfceRRMode); to->id = from->id; @@ -1499,8 +1400,7 @@ mode_copy (const XfceRRMode *from) } static void -mode_free (XfceRRMode *mode) -{ +mode_free (XfceRRMode *mode) { g_free (mode->name); g_slice_free (XfceRRMode, mode); } @@ -1509,8 +1409,7 @@ void xfce_rr_crtc_set_gamma (XfceRRCrtc *crtc, int size, unsigned short *red, unsigned short *green, - unsigned short *blue) -{ + unsigned short *blue) { #ifdef HAVE_RANDR int copy_size; XRRCrtcGamma *gamma; @@ -1550,8 +1449,7 @@ xfce_rr_crtc_get_gamma (XfceRRCrtc *crtc, int *size, unsigned short **red, unsigned short **green, - unsigned short **blue) -{ + unsigned short **blue) { #ifdef HAVE_RANDR int copy_size; unsigned short *r, *g, *b; diff --git a/src/xfce4-screensaver-command.c b/src/xfce4-screensaver-command.c index afd2f12c23e1d977b95c4ba0cf47867a6a23caf0..bbd45c1cd7d4fc349206e1ebc2d78b078a8f94f7 100644 --- a/src/xfce4-screensaver-command.c +++ b/src/xfce4-screensaver-command.c @@ -21,18 +21,20 @@ * */ -#include "config.h" +#include <config.h> -#include <stdlib.h> #include <locale.h> +#include <stdlib.h> + #include <glib.h> -#include <libxfce4util/libxfce4util.h> #define DBUS_API_SUBJECT_TO_CHANGE #include <dbus/dbus.h> #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> +#include <libxfce4util/libxfce4util.h> + #define GS_SERVICE "org.xfce.ScreenSaver" #define GS_PATH "/org/xfce/ScreenSaver" #define GS_INTERFACE "org.xfce.ScreenSaver" @@ -52,8 +54,7 @@ static gboolean do_time = FALSE; static char *inhibit_reason = NULL; static char *inhibit_application = NULL; -static GOptionEntry entries [] = -{ +static GOptionEntry entries[] = { { "exit", 0, 0, G_OPTION_ARG_NONE, &do_quit, N_("Causes the screensaver to exit gracefully"), NULL @@ -108,8 +109,7 @@ static GOptionEntry entries [] = static GMainLoop *loop = NULL; static gboolean -screensaver_is_running (DBusConnection *connection) -{ +screensaver_is_running (DBusConnection *connection) { DBusError error; gboolean exists; @@ -126,8 +126,7 @@ screensaver_is_running (DBusConnection *connection) static DBusMessage * screensaver_send_message_inhibit (DBusConnection *connection, const char *application, - const char *reason) -{ + const char *reason) { DBusMessage *message; DBusMessage *reply; DBusError error; @@ -138,8 +137,7 @@ screensaver_send_message_inhibit (DBusConnection *connection, dbus_error_init (&error); message = dbus_message_new_method_call (GS_SERVICE, GS_PATH, GS_INTERFACE, "Inhibit"); - if (message == NULL) - { + if (message == NULL) { g_warning ("Couldn't allocate the dbus message"); return NULL; } @@ -151,8 +149,7 @@ screensaver_send_message_inhibit (DBusConnection *connection, reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); - if (dbus_error_is_set (&error)) - { + if (dbus_error_is_set (&error)) { g_warning ("%s raised:\n %s\n\n", error.name, error.message); reply = NULL; } @@ -168,8 +165,7 @@ screensaver_send_message_inhibit (DBusConnection *connection, static DBusMessage * screensaver_send_message_bool (DBusConnection *connection, const char *name, - gboolean value) -{ + gboolean value) { DBusMessage *message; DBusMessage *reply; DBusError error; @@ -181,8 +177,7 @@ screensaver_send_message_bool (DBusConnection *connection, dbus_error_init (&error); message = dbus_message_new_method_call (GS_SERVICE, GS_PATH, GS_INTERFACE, name); - if (message == NULL) - { + if (message == NULL) { g_warning ("Couldn't allocate the dbus message"); return NULL; } @@ -193,8 +188,7 @@ screensaver_send_message_bool (DBusConnection *connection, reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); - if (dbus_error_is_set (&error)) - { + if (dbus_error_is_set (&error)) { g_warning ("%s raised:\n %s\n\n", error.name, error.message); reply = NULL; } @@ -210,8 +204,7 @@ screensaver_send_message_bool (DBusConnection *connection, static DBusMessage * screensaver_send_message_void (DBusConnection *connection, const char *name, - gboolean expect_reply) -{ + gboolean expect_reply) { DBusMessage *message; DBusMessage *reply; DBusError error; @@ -222,25 +215,20 @@ screensaver_send_message_void (DBusConnection *connection, dbus_error_init (&error); message = dbus_message_new_method_call (GS_SERVICE, GS_PATH, GS_INTERFACE, name); - if (message == NULL) - { + if (message == NULL) { g_warning ("Couldn't allocate the dbus message"); return NULL; } - if (! expect_reply) - { + if (!expect_reply) { if (!dbus_connection_send (connection, message, NULL)) g_warning ("could not send message"); reply = NULL; - } - else - { + } else { reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); - if (dbus_error_is_set (&error)) - { + if (dbus_error_is_set (&error)) { g_warning ("%s raised:\n %s\n\n", error.name, error.message); reply = NULL; } @@ -255,43 +243,36 @@ screensaver_send_message_void (DBusConnection *connection, static char ** get_string_from_iter (DBusMessageIter *iter, - int *num_elements) -{ + int *num_elements) { int count; char **buffer; - if (num_elements != NULL) - { + if (num_elements != NULL) { *num_elements = 0; } count = 0; buffer = (char **)malloc (sizeof (char *) * 8); - if (buffer == NULL) - { + if (buffer == NULL) { goto oom; } buffer[0] = NULL; - while (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_STRING) - { + while (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_STRING) { const char *value; char *str; - if ((count % 8) == 0 && count != 0) - { + if ((count % 8) == 0 && count != 0) { buffer = realloc (buffer, sizeof (char *) * (count + 8)); - if (buffer == NULL) - { + if (buffer == NULL) { goto oom; } } dbus_message_iter_get_basic (iter, &value); str = strdup (value); - if (str == NULL) - { + if (str == NULL) { goto oom; } @@ -301,18 +282,15 @@ get_string_from_iter (DBusMessageIter *iter, count++; } - if ((count % 8) == 0) - { + if ((count % 8) == 0) { buffer = realloc (buffer, sizeof (char *) * (count + 1)); - if (buffer == NULL) - { + if (buffer == NULL) { goto oom; } } buffer[count] = NULL; - if (num_elements != NULL) - { + if (num_elements != NULL) { *num_elements = count; } return buffer; @@ -320,29 +298,24 @@ get_string_from_iter (DBusMessageIter *iter, oom: g_debug ("%s %d : error allocating memory\n", __FILE__, __LINE__); return NULL; - } static gboolean -do_command (DBusConnection *connection) -{ +do_command (DBusConnection *connection) { DBusMessage *reply; - if (do_quit) - { + if (do_quit) { reply = screensaver_send_message_void (connection, "Quit", FALSE); goto done; } - if (do_query) - { + if (do_query) { DBusMessageIter iter; DBusMessageIter array; dbus_bool_t v; reply = screensaver_send_message_void (connection, "GetActive", TRUE); - if (! reply) - { + if (!reply) { g_message ("Did not receive a reply from the screensaver."); goto done; } @@ -354,8 +327,7 @@ do_command (DBusConnection *connection) dbus_message_unref (reply); reply = screensaver_send_message_void (connection, "GetInhibitors", TRUE); - if (! reply) - { + if (!reply) { g_message ("Did not receive a reply from screensaver."); goto done; } @@ -363,20 +335,16 @@ do_command (DBusConnection *connection) dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &array); - if (dbus_message_iter_get_arg_type (&array) == DBUS_TYPE_INVALID) - { + if (dbus_message_iter_get_arg_type (&array) == DBUS_TYPE_INVALID) { g_print (_("The screensaver is not inhibited\n")); - } - else - { + } else { char **inhibitors; int i; int num; g_print (_("The screensaver is being inhibited by:\n")); inhibitors = get_string_from_iter (&array, &num); - for (i = 0; i < num; i++) - { + for (i = 0; i < num; i++) { g_print ("\t%s\n", inhibitors[i]); } g_strfreev (inhibitors); @@ -385,15 +353,13 @@ do_command (DBusConnection *connection) dbus_message_unref (reply); } - if (do_time) - { + if (do_time) { DBusMessageIter iter; dbus_bool_t v; dbus_int32_t t; reply = screensaver_send_message_void (connection, "GetActive", TRUE); - if (! reply) - { + if (!reply) { g_message ("Did not receive a reply from the screensaver."); goto done; } @@ -402,66 +368,53 @@ do_command (DBusConnection *connection) dbus_message_iter_get_basic (&iter, &v); dbus_message_unref (reply); - if (v) - { - + if (v) { reply = screensaver_send_message_void (connection, "GetActiveTime", TRUE); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &t); g_print (_("The screensaver has been active for %d seconds.\n"), t); dbus_message_unref (reply); - } - else - { + } else { g_print (_("The screensaver is not currently active.\n")); } } - if (do_lock) - { + if (do_lock) { reply = screensaver_send_message_void (connection, "Lock", FALSE); } - if (do_cycle) - { + if (do_cycle) { reply = screensaver_send_message_void (connection, "Cycle", FALSE); } - if (do_poke) - { + if (do_poke) { reply = screensaver_send_message_void (connection, "SimulateUserActivity", FALSE); } - if (do_activate) - { + if (do_activate) { reply = screensaver_send_message_bool (connection, "SetActive", TRUE); - if (! reply) - { + if (!reply) { g_message ("Did not receive a reply from the screensaver."); goto done; } dbus_message_unref (reply); } - if (do_deactivate) - { + if (do_deactivate) { reply = screensaver_send_message_bool (connection, "SetActive", FALSE); - if (! reply) - { + if (!reply) { g_message ("Did not receive a reply from the screensaver."); goto done; } dbus_message_unref (reply); } - if (do_inhibit) - { + if (do_inhibit) { reply = screensaver_send_message_inhibit (connection, inhibit_application ? inhibit_application : "Unknown", inhibit_reason ? inhibit_reason : "Unknown"); - if (! reply) - { + if (!reply) { g_message ("Did not receive a reply from the screensaver."); goto done; } @@ -478,8 +431,7 @@ done: int main (int argc, - char **argv) -{ + char **argv) { DBusConnection *connection; DBusError dbus_error; GOptionContext *context; @@ -505,23 +457,20 @@ main (int argc, g_option_context_free (context); - if (!retval) - { + if (!retval) { g_warning ("%s", error->message); g_error_free (error); exit (1); } - if (do_version) - { - g_print ("%s %s\n", argv [0], VERSION); + if (do_version) { + g_print ("%s %s\n", argv[0], VERSION); exit (1); } dbus_error_init (&dbus_error); connection = dbus_bus_get (DBUS_BUS_SESSION, &dbus_error); - if (!connection) - { + if (!connection) { g_message ("Failed to connect to the D-BUS daemon: %s", dbus_error.message); dbus_error_free (&dbus_error); exit (1); @@ -529,8 +478,7 @@ main (int argc, dbus_connection_setup_with_g_main (connection, NULL); - if (!screensaver_is_running (connection)) - { + if (!screensaver_is_running (connection)) { g_message ("Screensaver is not running!"); exit (1); } diff --git a/src/xfce4-screensaver-dialog.c b/src/xfce4-screensaver-dialog.c index 61118081fa4b4b806f83d566ad24bb598db2ae17..6d899130fcd65593dd943493a17a6468138911e8 100644 --- a/src/xfce4-screensaver-dialog.c +++ b/src/xfce4-screensaver-dialog.c @@ -22,31 +22,29 @@ * */ -#include "config.h" +#include <config.h> +#include <signal.h> #include <stdlib.h> #include <string.h> #include <sys/time.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> -#include <signal.h> -#include <libxfce4util/libxfce4util.h> #include <gdk/gdkx.h> #include <gtk/gtk.h> #include <gtk/gtkx.h> -#include "gs-lock-plug.h" - -#include "gs-auth.h" -#include "setuid.h" - -#include "gs-debug.h" -#include "xfce4-screensaver-dialog-css.h" - +#include <libxfce4util/libxfce4util.h> #include <xfconf/xfconf.h> +#include "src/gs-auth.h" +#include "src/gs-debug.h" +#include "src/gs-lock-plug.h" +#include "src/setuid.h" +#include "src/xfce4-screensaver-dialog-css.h" + #define MAX_FAILURES 5 static gboolean verbose = FALSE; @@ -61,21 +59,30 @@ static char* away_message = NULL; static gint monitor_index = 0; static GOptionEntry entries[] = { - {"verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, N_("Show debugging output"), NULL}, - {"version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Version of this application"), NULL}, - {"enable-logout", 0, 0, G_OPTION_ARG_NONE, &enable_logout, N_("Show the logout button"), NULL}, - {"logout-command", 0, 0, G_OPTION_ARG_STRING, &logout_command, N_("Command to invoke from the logout button"), NULL}, - {"enable-switch", 0, 0, G_OPTION_ARG_NONE, &enable_switch, N_("Show the switch user button"), NULL}, - {"status-message", 0, 0, G_OPTION_ARG_STRING, &status_message, N_("Message to show in the dialog"), N_("MESSAGE")}, - {"away-message", 0, 0, G_OPTION_ARG_STRING, &away_message, N_("Not used"), N_("MESSAGE")}, - {"height", 0, 0, G_OPTION_ARG_INT, &dialog_height, N_("Monitor height"), NULL}, - {"width", 0, 0, G_OPTION_ARG_INT, &dialog_width, N_("Monitor width"), NULL}, - {"monitor", 0, 0, G_OPTION_ARG_INT, &monitor_index, N_("Monitor index"), NULL}, + {"verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, + N_("Show debugging output"), NULL}, + {"version", 0, 0, G_OPTION_ARG_NONE, &show_version, + N_("Version of this application"), NULL}, + {"enable-logout", 0, 0, G_OPTION_ARG_NONE, &enable_logout, + N_("Show the logout button"), NULL}, + {"logout-command", 0, 0, G_OPTION_ARG_STRING, &logout_command, + N_("Command to invoke from the logout button"), NULL}, + {"enable-switch", 0, 0, G_OPTION_ARG_NONE, &enable_switch, + N_("Show the switch user button"), NULL}, + {"status-message", 0, 0, G_OPTION_ARG_STRING, &status_message, + N_("Message to show in the dialog"), N_("MESSAGE")}, + {"away-message", 0, 0, G_OPTION_ARG_STRING, &away_message, + N_("Not used"), N_("MESSAGE")}, + {"height", 0, 0, G_OPTION_ARG_INT, &dialog_height, + N_("Monitor height"), NULL}, + {"width", 0, 0, G_OPTION_ARG_INT, &dialog_width, + N_("Monitor width"), NULL}, + {"monitor", 0, 0, G_OPTION_ARG_INT, &monitor_index, + N_("Monitor index"), NULL}, {NULL} }; -static char* get_id_string(GtkWidget* widget) -{ +static char* get_id_string(GtkWidget* widget) { char* id = NULL; g_return_val_if_fail(widget != NULL, NULL); @@ -85,8 +92,7 @@ static char* get_id_string(GtkWidget* widget) return id; } -static gboolean print_id(GtkWidget* widget) -{ +static gboolean print_id(GtkWidget* widget) { char* id; gs_profile_start(NULL); @@ -102,42 +108,36 @@ static gboolean print_id(GtkWidget* widget) return FALSE; } -static void response_cancel(void) -{ +static void response_cancel(void) { printf("RESPONSE=CANCEL\n"); fflush(stdout); } -static void response_ok(void) -{ +static void response_ok(void) { printf("RESPONSE=OK\n"); fflush(stdout); } -static gboolean quit_response_ok(void) -{ +static gboolean quit_response_ok(void) { response_ok(); gtk_main_quit(); return FALSE; } -static gboolean quit_response_cancel(void) -{ +static gboolean quit_response_cancel(void) { response_cancel(); gtk_main_quit(); return FALSE; } -static void response_lock_init_failed(void) -{ +static void response_lock_init_failed(void) { /* if we fail to lock then we should drop the dialog */ response_ok(); } static char* request_response(GSLockPlug* plug, const char* prompt, - gboolean visible) -{ + gboolean visible) { int response; char* text; @@ -149,8 +149,7 @@ static char* request_response(GSLockPlug* plug, text = NULL; - if (response == GS_LOCK_PLUG_RESPONSE_OK) - { + if (response == GS_LOCK_PLUG_RESPONSE_OK) { gs_lock_plug_get_text(plug, &text); } @@ -160,39 +159,55 @@ static char* request_response(GSLockPlug* plug, } /* Adapted from MDM2 daemon/verify-pam.c on 2006-06-13 */ -static const char* maybe_translate_message(const char* msg) -{ +static const char* maybe_translate_message(const char* msg) { char *s; const char *ret; static GHashTable *hash = NULL; - if (hash == NULL) - { + if (hash == NULL) { /* Here we come with some fairly standard messages so that we have as much as possible translated. Should really be translated in pam I suppose. This way we can "change" some of these messages to be more sane. */ hash = g_hash_table_new (g_str_hash, g_str_equal); /* login: is whacked always translate to Username: */ - g_hash_table_insert(hash, "login:", _("Please enter your username.")); - g_hash_table_insert(hash, "Username:", _("Please enter your username.")); + g_hash_table_insert(hash, "login:", + _("Please enter your username.")); + g_hash_table_insert(hash, "Username:", + _("Please enter your username.")); g_hash_table_insert(hash, "username:", _("Please enter your username.")); - g_hash_table_insert(hash, "Password:", ""); - g_hash_table_insert(hash, "password:", ""); - g_hash_table_insert(hash, "You are required to change your password immediately (password aged)", _("You are required to change your password immediately (password aged)")); - g_hash_table_insert(hash, "You are required to change your password immediately (root enforced)", _("You are required to change your password immediately (root enforced)")); - g_hash_table_insert(hash, "Your account has expired; please contact your system administrator", _("Your account has expired; please contact your system administrator")); - g_hash_table_insert(hash, "No password supplied", _("No password supplied.")); - g_hash_table_insert(hash, "Password unchanged", _("Password unchanged.")); - g_hash_table_insert(hash, "Can not get username", _("Can not get username.")); - g_hash_table_insert(hash, "Retype new UNIX password:", _("Retype your new password.")); - g_hash_table_insert(hash, "Enter new UNIX password:", _("Enter your new password.")); - g_hash_table_insert(hash, "(current) UNIX password:", _("Enter your current password:")); - g_hash_table_insert(hash, "Error while changing NIS password.", _("Error while changing NIS password.")); - g_hash_table_insert(hash, "You must choose a longer password", _("You must choose a longer password.")); - g_hash_table_insert(hash, "Password has been already used. Choose another.", _("Password has been already used. Choose another.")); - g_hash_table_insert(hash, "You must wait longer to change your password", _("You must wait longer to change your password.")); - g_hash_table_insert(hash, "Sorry, passwords do not match", _("Sorry, passwords do not match.")); + g_hash_table_insert(hash, "Password:", + ""); + g_hash_table_insert(hash, "password:", + ""); + g_hash_table_insert(hash, "You are required to change your password immediately (password aged)", + _("You are required to change your password immediately (password aged)")); + g_hash_table_insert(hash, "You are required to change your password immediately (root enforced)", + _("You are required to change your password immediately (root enforced)")); + g_hash_table_insert(hash, "Your account has expired; please contact your system administrator", + _("Your account has expired; please contact your system administrator")); + g_hash_table_insert(hash, "No password supplied", + _("No password supplied.")); + g_hash_table_insert(hash, "Password unchanged", + _("Password unchanged.")); + g_hash_table_insert(hash, "Can not get username", + _("Can not get username.")); + g_hash_table_insert(hash, "Retype new UNIX password:", + _("Retype your new password.")); + g_hash_table_insert(hash, "Enter new UNIX password:", + _("Enter your new password.")); + g_hash_table_insert(hash, "(current) UNIX password:", + _("Enter your current password:")); + g_hash_table_insert(hash, "Error while changing NIS password.", + _("Error while changing NIS password.")); + g_hash_table_insert(hash, "You must choose a longer password", + _("You must choose a longer password.")); + g_hash_table_insert(hash, "Password has been already used. Choose another.", + _("Password has been already used. Choose another.")); + g_hash_table_insert(hash, "You must wait longer to change your password", + _("You must wait longer to change your password.")); + g_hash_table_insert(hash, "Sorry, passwords do not match", + _("Sorry, passwords do not match.")); /* FIXME: what about messages which have some variables in them, perhaps try to do those as well */ } @@ -200,12 +215,9 @@ static const char* maybe_translate_message(const char* msg) ret = g_hash_table_lookup(hash, s); g_free(s); - if (ret != NULL) - { + if (ret != NULL) { return ret; - } - else - { + } else { return msg; } } @@ -213,8 +225,7 @@ static const char* maybe_translate_message(const char* msg) static gboolean auth_message_handler(GSAuthMessageStyle style, const char *msg, char **response, - gpointer data) -{ + gpointer data) { gboolean ret; GSLockPlug *plug; const char *message; @@ -231,19 +242,16 @@ static gboolean auth_message_handler(GSAuthMessageStyle style, *response = NULL; message = maybe_translate_message(msg); - switch (style) - { + switch (style) { case GS_AUTH_MESSAGE_PROMPT_ECHO_ON: - if (msg != NULL) - { + if (msg != NULL) { char *resp; resp = request_response(plug, message, TRUE); *response = resp; } break; case GS_AUTH_MESSAGE_PROMPT_ECHO_OFF: - if (msg != NULL) - { + if (msg != NULL) { char *resp; resp = request_response(plug, message, FALSE); *response = resp; @@ -259,20 +267,16 @@ static gboolean auth_message_handler(GSAuthMessageStyle style, g_assert_not_reached(); } - if (*response == NULL) - { + if (*response == NULL) { gs_debug("Got no response"); ret = FALSE; - } - else - { + } else { gs_lock_plug_show_message(plug, _("Checking...")); gs_lock_plug_set_sensitive(plug, FALSE); } /* we may have pending events that should be processed before continuing back into PAM */ - while (gtk_events_pending()) - { + while (gtk_events_pending()) { gtk_main_iteration(); } @@ -282,16 +286,14 @@ static gboolean auth_message_handler(GSAuthMessageStyle style, return ret; } -static gboolean reset_idle_cb(GSLockPlug* plug) -{ +static gboolean reset_idle_cb(GSLockPlug* plug) { gs_lock_plug_set_sensitive(plug, TRUE); gs_lock_plug_show_message(plug, NULL); return FALSE; } -static gboolean do_auth_check(GSLockPlug* plug) -{ +static gboolean do_auth_check(GSLockPlug* plug) { GError *error; gboolean res; @@ -303,23 +305,18 @@ static gboolean do_auth_check(GSLockPlug* plug) gs_debug("Verify user returned: %s", res ? "TRUE" : "FALSE"); - if (! res) - { - if (error != NULL) - { + if (!res) { + if (error != NULL) { gs_debug("Verify user returned error: %s", error->message); gs_lock_plug_show_message(plug, error->message); - } - else - { + } else { gs_lock_plug_show_message(plug, _("Authentication failed.")); } printf("NOTICE=AUTH FAILED\n"); fflush(stdout); - if (error != NULL) - { + if (error != NULL) { g_error_free(error); } } @@ -328,29 +325,24 @@ static gboolean do_auth_check(GSLockPlug* plug) } static void response_cb(GSLockPlug *plug, - gint response_id) -{ - if ((response_id == GS_LOCK_PLUG_RESPONSE_CANCEL) || (response_id == GTK_RESPONSE_DELETE_EVENT)) - { + gint response_id) { + if ((response_id == GS_LOCK_PLUG_RESPONSE_CANCEL) || (response_id == GTK_RESPONSE_DELETE_EVENT)) { quit_response_cancel(); } } -static gboolean response_request_quit(void) -{ +static gboolean response_request_quit(void) { printf("REQUEST QUIT\n"); fflush(stdout); return FALSE; } -static gboolean quit_timeout_cb(gpointer data) -{ +static gboolean quit_timeout_cb(gpointer data) { gtk_main_quit(); return FALSE; } -static gboolean auth_check_idle(GSLockPlug* plug) -{ +static gboolean auth_check_idle(GSLockPlug* plug) { gboolean res; gboolean again; static guint loop_counter = 0; @@ -358,22 +350,16 @@ static gboolean auth_check_idle(GSLockPlug* plug) again = TRUE; res = do_auth_check(plug); - if (res) - { + if (res) { again = FALSE; g_idle_add((GSourceFunc) quit_response_ok, NULL); - } - else - { + } else { loop_counter++; - if (loop_counter < MAX_FAILURES) - { + if (loop_counter < MAX_FAILURES) { gs_debug ("Authentication failed, retrying (%u)", loop_counter); g_timeout_add (3000, (GSourceFunc) reset_idle_cb, plug); - } - else - { + } else { gs_debug ("Authentication failed, quitting (max failures)"); again = FALSE; /* Don't quit immediately, but rather request that xfce4-screensaver @@ -388,13 +374,11 @@ static gboolean auth_check_idle(GSLockPlug* plug) } static void show_cb(GtkWidget *widget, - gpointer data) -{ + gpointer data) { print_id(widget); } -static gboolean popup_dialog_idle(void) -{ +static gboolean popup_dialog_idle(void) { GtkWidget *widget; GtkCssProvider *css_provider; @@ -402,23 +386,19 @@ static gboolean popup_dialog_idle(void) widget = gs_lock_plug_new(); - if (enable_logout) - { + if (enable_logout) { g_object_set(widget, "logout-enabled", TRUE, NULL); } - if (logout_command) - { + if (logout_command) { g_object_set(widget, "logout-command", logout_command, NULL); } - if (enable_switch) - { + if (enable_switch) { g_object_set(widget, "switch-enabled", TRUE, NULL); } - if (status_message) - { + if (status_message) { g_object_set(widget, "status-message", status_message, NULL); } @@ -430,7 +410,10 @@ static gboolean popup_dialog_idle(void) g_signal_connect(widget, "show", G_CALLBACK(show_cb), NULL); css_provider = gtk_css_provider_new (); - gtk_css_provider_load_from_data (css_provider, xfce4_screensaver_dialog_css, xfce4_screensaver_dialog_css_length, NULL); + gtk_css_provider_load_from_data (css_provider, + xfce4_screensaver_dialog_css, + xfce4_screensaver_dialog_css_length, + NULL); gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), GTK_STYLE_PROVIDER (css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); @@ -454,8 +437,7 @@ static gboolean popup_dialog_idle(void) */ static gboolean privileged_initialization(int *argc, char **argv, - gboolean verbose) -{ + gboolean verbose) { gboolean ret; char *nolock_reason; char *orig_uid; @@ -470,13 +452,11 @@ static gboolean privileged_initialization(int *argc, ret = hack_uid(&nolock_reason, &orig_uid, &uid_message); - if (nolock_reason) - { + if (nolock_reason) { g_debug("Locking disabled: %s", nolock_reason); } - if (uid_message && verbose) - { + if (uid_message && verbose) { g_print("Modified UID: %s", uid_message); } @@ -499,17 +479,14 @@ static gboolean privileged_initialization(int *argc, static gboolean lock_initialization (int *argc, char **argv, char **nolock_reason, - gboolean verbose) -{ - if (nolock_reason != NULL) - { + gboolean verbose) { + if (nolock_reason != NULL) { *nolock_reason = NULL; } #ifdef NO_LOCKING - if (nolock_reason != NULL) - { + if (nolock_reason != NULL) { *nolock_reason = g_strdup("not compiled with locking support"); } @@ -517,10 +494,8 @@ static gboolean lock_initialization (int *argc, #else /* !NO_LOCKING */ /* Finish initializing locking, now that we're out of privileged code. */ - if (!gs_auth_init()) - { - if (nolock_reason != NULL) - { + if (!gs_auth_init()) { + if (nolock_reason != NULL) { *nolock_reason = g_strdup("error getting password"); } @@ -531,10 +506,8 @@ static gboolean lock_initialization (int *argc, * we have been launched as MDM's "Background" program, then disable * locking just in case. */ - if (getenv("RUNNING_UNDER_MDM")) - { - if (nolock_reason != NULL) - { + if (getenv("RUNNING_UNDER_MDM")) { + if (nolock_reason != NULL) { *nolock_reason = g_strdup("running under MDM"); } @@ -557,10 +530,8 @@ static gboolean lock_initialization (int *argc, macos = TRUE; #endif /* __APPLE__ */ - if (macos) - { - if (nolock_reason != NULL) - { + if (macos) { + if (nolock_reason != NULL) { *nolock_reason = g_strdup("Cannot lock securely on MacOS X"); } @@ -574,8 +545,7 @@ static gboolean lock_initialization (int *argc, } int main(int argc, - char **argv) -{ + char **argv) { GError *error = NULL; char *nolock_reason = NULL; @@ -589,18 +559,15 @@ int main(int argc, gs_profile_start(NULL); - if (!privileged_initialization(&argc, argv, verbose)) - { + if (!privileged_initialization(&argc, argv, verbose)) { response_lock_init_failed(); exit(1); } error = NULL; - if (!gtk_init_with_args(&argc, &argv, NULL, entries, NULL, &error)) - { - if (error != NULL) - { + if (!gtk_init_with_args(&argc, &argv, NULL, entries, NULL, &error)) { + if (error != NULL) { fprintf(stderr, "%s", error->message); g_error_free(error); } @@ -608,24 +575,20 @@ int main(int argc, exit(1); } - if (!xfconf_init(&error)) - { + if (!xfconf_init(&error)) { g_error("Failed to connect to xfconf daemon: %s.", error->message); g_error_free(error); exit(1); } - if (show_version) - { + if (show_version) { g_print("%s %s\n", argv[0], VERSION); exit(1); } - if (!lock_initialization(&argc, argv, &nolock_reason, verbose)) - { - if (nolock_reason != NULL) - { + if (!lock_initialization(&argc, argv, &nolock_reason, verbose)) { + if (nolock_reason != NULL) { g_debug ("Screen locking disabled: %s", nolock_reason); g_free (nolock_reason); } diff --git a/src/xfce4-screensaver-gl-helper.c b/src/xfce4-screensaver-gl-helper.c index 49ffd90bffdf7c18bbb3f8ddc6b775e681108572..5f0246c2c1a14dbc9f92d37378859b695195cd38 100644 --- a/src/xfce4-screensaver-gl-helper.c +++ b/src/xfce4-screensaver-gl-helper.c @@ -19,21 +19,21 @@ * */ -#include "config.h" +#include <config.h> #include <stdlib.h> -#include <glib.h> -#include <libxfce4util/libxfce4util.h> -#include <gtk/gtk.h> +#include <glib.h> #include <gdk/gdkx.h> +#include <gtk/gtk.h> -#include "gs-visual-gl.h" +#include <libxfce4util/libxfce4util.h> + +#include "src/gs-visual-gl.h" int main (int argc, - char **argv) -{ + char **argv) { GdkDisplay *display; GdkVisual *visual; Visual *xvisual; @@ -48,15 +48,11 @@ main (int argc, #endif g_set_prgname (argv[0]); - if (! gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) - { - if (error != NULL) - { + if (!gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) { + if (error != NULL) { g_warning ("%s", error->message); g_error_free (error); - } - else - { + } else { g_warning ("Unable to initialize GTK+"); } exit (1); @@ -65,13 +61,10 @@ main (int argc, display = gdk_display_get_default (); visual = gs_visual_gl_get_best_for_display (display); - if (visual != NULL) - { + if (visual != NULL) { xvisual = gdk_x11_visual_get_xvisual (visual); printf ("0x%x\n", (unsigned int) XVisualIDFromVisual (xvisual)); - } - else - { + } else { printf ("none\n"); } diff --git a/src/xfce4-screensaver-preferences.c b/src/xfce4-screensaver-preferences.c index fe2998cc8b45e613e1e768908803979294eb80aa..94f795c2f8a85c0a95e3d94761395b86a164ac9e 100644 --- a/src/xfce4-screensaver-preferences.c +++ b/src/xfce4-screensaver-preferences.c @@ -23,54 +23,45 @@ * */ -#include "config.h" +#include <config.h> #define _GNU_SOURCE -#include <unistd.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> /* For uid_t, gid_t */ +#include <unistd.h> +#include <gio/gio.h> #include <gdk/gdkx.h> #include <gtk/gtk.h> #include <gtk/gtkx.h> -#include <gio/gio.h> - #include <libxfce4ui/libxfce4ui.h> - -#include "xfce-desktop-utils.h" - -#include "gs-debug.h" - -#include "copy-theme-dialog.h" - -#include "gs-theme-manager.h" -#include "gs-job.h" -#include "gs-prefs.h" /* for GS_MODE enum */ - -#include "xfce4-screensaver-preferences-ui.h" - #include <xfconf/xfconf.h> +#include "src/copy-theme-dialog.h" +#include "src/gs-debug.h" +#include "src/gs-job.h" +#include "src/gs-prefs.h" /* for GS_MODE enum */ +#include "src/gs-theme-manager.h" +#include "src/xfce-desktop-utils.h" +#include "src/xfce4-screensaver-preferences-ui.h" + #define GPM_COMMAND "xfce4-power-manager-settings" -enum -{ +enum { NAME_COLUMN = 0, ID_COLUMN, N_COLUMNS }; /* Drag and drop info */ -enum -{ +enum { TARGET_URI_LIST, TARGET_NS_URL }; -static GtkTargetEntry drop_types [] = -{ +static GtkTargetEntry drop_types[] = { { "text/uri-list", 0, TARGET_URI_LIST }, { "_NETSCAPE_URL", 0, TARGET_NS_URL } }; @@ -81,27 +72,24 @@ static GSJob *job = NULL; static XfconfChannel *screensaver_channel = NULL; static gint opt_socket_id = 0; -static GOptionEntry entries[] = -{ - { "socket-id", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, &opt_socket_id, N_("Settings manager socket"), N_("SOCKET ID") }, +static GOptionEntry entries[] = { + { "socket-id", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, &opt_socket_id, + N_("Settings manager socket"), N_("SOCKET ID") }, { NULL } }; static gint32 -config_get_activate_delay (gboolean *is_writable) -{ +config_get_activate_delay (gboolean *is_writable) { gint32 delay; - if (is_writable) - { + if (is_writable) { *is_writable = !xfconf_channel_is_property_locked (screensaver_channel, KEY_IDLE_DELAY); } delay = xfconf_channel_get_int (screensaver_channel, KEY_IDLE_DELAY, DEFAULT_KEY_IDLE_DELAY); - if (delay < 1) - { + if (delay < 1) { delay = 1; } @@ -109,18 +97,15 @@ config_get_activate_delay (gboolean *is_writable) } static void -config_set_activate_delay (gint32 timeout) -{ +config_set_activate_delay (gint32 timeout) { xfconf_channel_set_int (screensaver_channel, KEY_IDLE_DELAY, timeout); } static int -config_get_mode (gboolean *is_writable) -{ +config_get_mode (gboolean *is_writable) { int mode; - if (is_writable) - { + if (is_writable) { *is_writable = !xfconf_channel_is_property_locked (screensaver_channel, KEY_MODE); } @@ -131,50 +116,40 @@ config_get_mode (gboolean *is_writable) } static void -config_set_mode (int mode) -{ +config_set_mode (int mode) { xfconf_channel_set_int (screensaver_channel, KEY_MODE, mode); } static char * -config_get_theme (gboolean *is_writable) -{ +config_get_theme (gboolean *is_writable) { char *name; int mode; - if (is_writable) - { + if (is_writable) { gboolean can_write_theme = TRUE; gboolean can_write_mode = TRUE; can_write_theme = !xfconf_channel_is_property_locked (screensaver_channel, KEY_THEMES); can_write_mode = !xfconf_channel_is_property_locked (screensaver_channel, - KEY_MODE); + KEY_MODE); *is_writable = can_write_theme && can_write_mode; } mode = config_get_mode (NULL); name = NULL; - if (mode == GS_MODE_BLANK_ONLY) - { + if (mode == GS_MODE_BLANK_ONLY) { name = g_strdup ("__blank-only"); - } - else if (mode == GS_MODE_RANDOM) - { + } else if (mode == GS_MODE_RANDOM) { name = g_strdup ("__random"); - } - else - { + } else { gchar **strv; strv = xfconf_channel_get_string_list (screensaver_channel, KEY_THEMES); if (strv != NULL) { name = g_strdup (strv[0]); - } - else - { + } else { /* TODO: handle error */ /* default to blank */ name = g_strdup ("__blank-only"); @@ -187,8 +162,7 @@ config_get_theme (gboolean *is_writable) } static gchar ** -get_all_theme_ids (GSThemeManager *theme_manager) -{ +get_all_theme_ids (GSThemeManager *theme_manager) { gchar **ids = NULL; GSList *entries; GSList *l; @@ -196,8 +170,7 @@ get_all_theme_ids (GSThemeManager *theme_manager) entries = gs_theme_manager_get_info_list (theme_manager); ids = g_new0 (gchar *, g_slist_length (entries) + 1); - for (l = entries; l; l = l->next) - { + for (l = entries; l; l = l->next) { GSThemeInfo *info = l->data; ids[idx++] = g_strdup (gs_theme_info_get_id (info)); @@ -209,24 +182,18 @@ get_all_theme_ids (GSThemeManager *theme_manager) } static void -config_set_theme (const char *theme_id) -{ +config_set_theme (const char *theme_id) { gchar **strv = NULL; int mode; - if (theme_id && strcmp (theme_id, "__blank-only") == 0) - { + if (theme_id && strcmp (theme_id, "__blank-only") == 0) { mode = GS_MODE_BLANK_ONLY; - } - else if (theme_id && strcmp (theme_id, "__random") == 0) - { + } else if (theme_id && strcmp (theme_id, "__random") == 0) { mode = GS_MODE_RANDOM; /* set the themes key to contain all available screensavers */ strv = get_all_theme_ids (theme_manager); - } - else - { + } else { mode = GS_MODE_SINGLE; strv = g_strsplit (theme_id, "%%%", 1); } @@ -241,12 +208,10 @@ config_set_theme (const char *theme_id) } static gboolean -config_get_enabled (gboolean *is_writable) -{ +config_get_enabled (gboolean *is_writable) { int enabled; - if (is_writable) - { + if (is_writable) { *is_writable = !xfconf_channel_is_property_locked (screensaver_channel, KEY_LOCK_ENABLED); } @@ -259,20 +224,17 @@ config_get_enabled (gboolean *is_writable) } static void -config_set_enabled (gboolean enabled) -{ +config_set_enabled (gboolean enabled) { xfconf_channel_set_bool (screensaver_channel, KEY_IDLE_ACTIVATION_ENABLED, enabled); } static gboolean -config_get_lock (gboolean *is_writable) -{ +config_get_lock (gboolean *is_writable) { gboolean lock; - if (is_writable) - { + if (is_writable) { *is_writable = !xfconf_channel_is_property_locked (screensaver_channel, KEY_LOCK_ENABLED); } @@ -285,30 +247,26 @@ config_get_lock (gboolean *is_writable) } static void -config_set_lock (gboolean lock) -{ +config_set_lock (gboolean lock) { xfconf_channel_set_bool (screensaver_channel, KEY_LOCK_ENABLED, lock); } static void job_set_theme (GSJob *job, - const char *theme) -{ + const char *theme) { GSThemeInfo *info; const char *command; command = NULL; info = gs_theme_manager_lookup_theme_info (theme_manager, theme); - if (info != NULL) - { + if (info != NULL) { command = gs_theme_info_get_exec (info); } gs_job_set_command (job, command); - if (info != NULL) - { + if (info != NULL) { gs_theme_info_unref (info); } } @@ -316,10 +274,8 @@ job_set_theme (GSJob *job, static gboolean preview_on_draw (GtkWidget *widget, cairo_t *cr, - gpointer data) -{ - if (job == NULL || !gs_job_is_running (job)) - { + gpointer data) { + if (job == NULL || !gs_job_is_running (job)) { cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgb (cr, 0, 0, 0); cairo_paint (cr); @@ -331,13 +287,11 @@ preview_on_draw (GtkWidget *widget, static void preview_set_theme (GtkWidget *widget, const char *theme, - const char *name) -{ + const char *name) { GtkWidget *label; char *markup; - if (job != NULL) - { + if (job != NULL) { gs_job_stop (job); } @@ -348,17 +302,13 @@ preview_set_theme (GtkWidget *widget, gtk_label_set_markup (GTK_LABEL (label), markup); g_free (markup); - if ((theme && strcmp (theme, "__blank-only") == 0)) - { - - } - else if (theme && strcmp (theme, "__random") == 0) - { + if ((theme && strcmp (theme, "__blank-only") == 0)) { + /* Do nothing */ + } else if (theme && strcmp (theme, "__random") == 0) { gchar **themes; themes = get_all_theme_ids (theme_manager); - if (themes != NULL) - { + if (themes != NULL) { gint32 i; i = g_random_int_range (0, g_strv_length (themes)); @@ -367,17 +317,14 @@ preview_set_theme (GtkWidget *widget, gs_job_start (job); } - } - else - { + } else { job_set_theme (job, theme); gs_job_start (job); } } static void -help_display (void) -{ +help_display (void) { GError *error; error = NULL; @@ -386,8 +333,7 @@ help_display (void) GDK_CURRENT_TIME, &error); - if (error != NULL) - { + if (error != NULL) { GtkWidget *d; d = gtk_message_dialog_new (NULL, @@ -398,50 +344,39 @@ help_display (void) gtk_widget_destroy (d); g_error_free (error); } - } static void response_cb (GtkWidget *widget, - int response_id) -{ - - if (response_id == GTK_RESPONSE_HELP) - { + int response_id) { + if (response_id == GTK_RESPONSE_HELP) { help_display (); - } - else if (response_id == GTK_RESPONSE_REJECT) - { + } else if (response_id == GTK_RESPONSE_REJECT) { GError *error; gboolean res; error = NULL; res = xfce_gdk_spawn_command_line_on_screen (gdk_screen_get_default (), - GPM_COMMAND, - &error); - if (! res) - { + GPM_COMMAND, + &error); + if (!res) { g_warning ("Unable to start power management preferences: %s", error->message); g_error_free (error); } - } - else - { + } else { gtk_widget_destroy (widget); gtk_main_quit (); } } static GSList * -get_theme_info_list (void) -{ +get_theme_info_list (void) { return gs_theme_manager_get_info_list (theme_manager); } static void -populate_model (GtkTreeStore *store) -{ +populate_model (GtkTreeStore *store) { GtkTreeIter iter; GSList *themes = NULL; GSList *l; @@ -466,19 +401,16 @@ populate_model (GtkTreeStore *store) themes = get_theme_info_list (); - if (themes == NULL) - { + if (themes == NULL) { return; } - for (l = themes; l; l = l->next) - { + for (l = themes; l; l = l->next) { const char *name; const char *id; GSThemeInfo *info = l->data; - if (info == NULL) - { + if (info == NULL) { continue; } @@ -498,33 +430,28 @@ populate_model (GtkTreeStore *store) } static void -tree_selection_previous (GtkTreeSelection *selection) -{ +tree_selection_previous (GtkTreeSelection *selection) { GtkTreeIter iter; GtkTreeModel *model; GtkTreePath *path; - if (! gtk_tree_selection_get_selected (selection, &model, &iter)) - { + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { return; } path = gtk_tree_model_get_path (model, &iter); - if (gtk_tree_path_prev (path)) - { + if (gtk_tree_path_prev (path)) { gtk_tree_selection_select_path (selection, path); } } static void -tree_selection_next (GtkTreeSelection *selection) -{ +tree_selection_next (GtkTreeSelection *selection) { GtkTreeIter iter; GtkTreeModel *model; GtkTreePath *path; - if (! gtk_tree_selection_get_selected (selection, &model, &iter)) - { + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { return; } @@ -535,22 +462,19 @@ tree_selection_next (GtkTreeSelection *selection) static void tree_selection_changed_cb (GtkTreeSelection *selection, - GtkWidget *preview) -{ + GtkWidget *preview) { GtkTreeIter iter; GtkTreeModel *model; char *theme; char *name; - if (! gtk_tree_selection_get_selected (selection, &model, &iter)) - { + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { return; } gtk_tree_model_get (model, &iter, ID_COLUMN, &theme, NAME_COLUMN, &name, -1); - if (theme == NULL) - { + if (theme == NULL) { g_free (name); return; } @@ -564,8 +488,7 @@ tree_selection_changed_cb (GtkTreeSelection *selection, static void activate_delay_value_changed_cb (GtkRange *range, - gpointer user_data) -{ + gpointer user_data) { gdouble value; value = gtk_range_get_value (range); @@ -576,48 +499,30 @@ static int compare_theme_names (char *name_a, char *name_b, char *id_a, - char *id_b) -{ - if (id_a == NULL) - { + char *id_b) { + if (id_a == NULL) { return 1; - } - else if (id_b == NULL) - { + } else if (id_b == NULL) { return -1; } - if (strcmp (id_a, "__blank-only") == 0) - { + if (strcmp (id_a, "__blank-only") == 0) { return -1; - } - else if (strcmp (id_b, "__blank-only") == 0) - { + } else if (strcmp (id_b, "__blank-only") == 0) { return 1; - } - else if (strcmp (id_a, "__random") == 0) - { + } else if (strcmp (id_a, "__random") == 0) { return -1; - } - else if (strcmp (id_b, "__random") == 0) - { + } else if (strcmp (id_b, "__random") == 0) { return 1; - } - else if (strcmp (id_a, "__separator") == 0) - { + } else if (strcmp (id_a, "__separator") == 0) { return -1; - } - else if (strcmp (id_b, "__separator") == 0) - { + } else if (strcmp (id_b, "__separator") == 0) { return 1; } - if (name_a == NULL) - { + if (name_a == NULL) { return 1; - } - else if (name_b == NULL) - { + } else if (name_b == NULL) { return -1; } @@ -628,8 +533,7 @@ static int compare_theme (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, - gpointer user_data) -{ + gpointer user_data) { char *name_a; char *name_b; char *id_a; @@ -654,15 +558,13 @@ compare_theme (GtkTreeModel *model, static gboolean separator_func (GtkTreeModel *model, GtkTreeIter *iter, - gpointer data) -{ + gpointer data) { int column = GPOINTER_TO_INT (data); char *text; gtk_tree_model_get (model, iter, column, &text, -1); - if (text != NULL && strcmp (text, "__separator") == 0) - { + if (text != NULL && strcmp (text, "__separator") == 0) { return TRUE; } @@ -673,8 +575,7 @@ separator_func (GtkTreeModel *model, static void setup_treeview (GtkWidget *tree, - GtkWidget *preview) -{ + GtkWidget *preview) { GtkTreeStore *store; GtkTreeViewColumn *column; GtkCellRenderer *renderer; @@ -717,12 +618,10 @@ setup_treeview (GtkWidget *tree, g_signal_connect (G_OBJECT (select), "changed", G_CALLBACK (tree_selection_changed_cb), preview); - } static void -setup_treeview_selection (GtkWidget *tree) -{ +setup_treeview_selection (GtkWidget *tree) { char *theme; GtkTreeModel *model; GtkTreeIter iter; @@ -731,18 +630,14 @@ setup_treeview_selection (GtkWidget *tree) theme = config_get_theme (&is_writable); - if (! is_writable) - { + if (!is_writable) { gtk_widget_set_sensitive (tree, FALSE); } model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree)); - if (theme && gtk_tree_model_get_iter_first (model, &iter)) - { - - do - { + if (theme && gtk_tree_model_get_iter_first (model, &iter)) { + do { char *id; gboolean found; @@ -751,18 +646,14 @@ setup_treeview_selection (GtkWidget *tree) found = (id && strcmp (id, theme) == 0); g_free (id); - if (found) - { + if (found) { path = gtk_tree_model_get_path (model, &iter); break; } - - } - while (gtk_tree_model_iter_next (model, &iter)); + } while (gtk_tree_model_iter_next (model, &iter)); } - if (path) - { + if (path) { gtk_tree_view_set_cursor (GTK_TREE_VIEW (tree), path, NULL, @@ -775,8 +666,7 @@ setup_treeview_selection (GtkWidget *tree) } static void -reload_themes (void) -{ +reload_themes (void) { GtkWidget *treeview; GtkTreeModel *model; @@ -791,16 +681,14 @@ reload_themes (void) static void theme_copy_complete_cb (GtkWidget *dialog, - gpointer user_data) -{ + gpointer user_data) { reload_themes (); gtk_widget_destroy (dialog); } static void theme_installer_run (GtkWidget *prefs_dialog, - GList *files) -{ + GList *files) { GtkWidget *copy_dialog; copy_dialog = copy_theme_dialog_new (files); @@ -825,8 +713,7 @@ drag_motion_cb (GtkWidget *widget, int x, int y, guint time, - gpointer data) -{ + gpointer data) { return FALSE; } @@ -835,8 +722,7 @@ static void drag_leave_cb (GtkWidget *widget, GdkDragContext *context, guint time, - gpointer data) -{ + gpointer data) { gtk_widget_queue_draw (widget); } @@ -844,8 +730,7 @@ drag_leave_cb (GtkWidget *widget, * and re-work to create GFiles. **/ static GList * -uri_list_parse (const gchar *uri_list) -{ +uri_list_parse (const gchar *uri_list) { const gchar *p, *q; gchar *retval; GFile *file; @@ -860,10 +745,8 @@ uri_list_parse (const gchar *uri_list) * comments and trim whitespace off the ends. We also * allow LF delimination as well as the specified CRLF. */ - while (p != NULL) - { - if (*p != '#') - { + while (p != NULL) { + if (*p != '#') { while (g_ascii_isspace (*p)) p++; @@ -873,8 +756,7 @@ uri_list_parse (const gchar *uri_list) && (*q != '\r')) q++; - if (q > p) - { + if (q > p) { q--; while (q > p && g_ascii_isspace (*q)) @@ -909,16 +791,14 @@ drag_data_received_cb (GtkWidget *widget, GtkSelectionData *selection_data, guint info, guint time, - gpointer data) -{ + gpointer data) { GList *files; if (!(info == TARGET_URI_LIST || info == TARGET_NS_URL)) return; files = uri_list_parse ((char *) gtk_selection_data_get_data (selection_data)); - if (files != NULL) - { + if (files != NULL) { GtkWidget *prefs_dialog; prefs_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_dialog")); @@ -928,8 +808,7 @@ drag_data_received_cb (GtkWidget *widget, /* Adapted from totem_time_to_string_text */ static char * -time_to_string_text (long time) -{ +time_to_string_text (long time) { char *secs, *mins, *hours, *string; int sec, min, hour; int n, inc_len, len_minutes; @@ -957,18 +836,14 @@ time_to_string_text (long time) len_minutes = 0; - for (n = 2; n < 60; n++) - { - if (n < 10) - { + for (n = 2; n < 60; n++) { + if (n < 10) { if ((strlen (g_str_to_ascii (g_strdup_printf (ngettext ("%d minute", "%d minutes", n), n), NULL)) - 2) > len_minutes) len_minutes = strlen (g_str_to_ascii (g_strdup_printf (ngettext ("%d minute", "%d minutes", n), n), NULL)) - 2; - } - else - { + } else { if ((strlen (g_str_to_ascii (g_strdup_printf (ngettext ("%d minute", "%d minutes", n), n), NULL)) - 3) > len_minutes) @@ -986,59 +861,43 @@ time_to_string_text (long time) if (len_minutes < 1) len_minutes = 1; - if (hour > 0) - { - if (sec > 0) - { + if (hour > 0) { + if (sec > 0) { /* hour:minutes:seconds */ string = g_strdup_printf (_("%s %s %s"), hours, mins, secs); - } - else if (min > 0) - { + } else if (min > 0) { /* hour:minutes */ string = g_strdup_printf (_("%s %s"), hours, mins); - } - else - { + } else { /* hour */ string = g_strdup_printf (_("%s"), hours); } - } - else if (min > 0) - { - if (sec > 0) - { + } else if (min > 0) { + if (sec > 0) { /* minutes:seconds */ string = g_strdup_printf (_("%s %s"), mins, secs); - } - else - { + } else { /* minutes */ string = g_strdup_printf (_("%s"), mins); - if (min < 10) - { - if (min == 1) - while (strlen (string) != (len_minutes + inc_len + 3)) - { + if (min < 10) { + if (min == 1) { + while (strlen (string) != (len_minutes + inc_len + 3)) { if (strlen (string) % 2 == 0) string = g_strconcat (string, " ", NULL); else string = g_strconcat (" " , string, NULL); } - else - while (strlen (string) != (len_minutes + inc_len)) - { + } else { + while (strlen (string) != (len_minutes + inc_len)) { if (strlen (string) % 2 == 0) string = g_strconcat (string, " ", NULL); else string = g_strconcat (" " , string, NULL); } - } - else - { - while (strlen (string) != (len_minutes + inc_len - 1)) - { + } + } else { + while (strlen (string) != (len_minutes + inc_len - 1)) { if (strlen (string) % 2 == 0) string = g_strconcat (string, " ", NULL); else @@ -1046,9 +905,7 @@ time_to_string_text (long time) } } } - } - else - { + } else { /* seconds */ string = g_strdup_printf (_("%s"), secs); } @@ -1062,8 +919,7 @@ time_to_string_text (long time) static char * format_value_callback_time (GtkScale *scale, - gdouble value) -{ + gdouble value) { if (value == 0) return g_strdup_printf (_("Never")); @@ -1071,57 +927,49 @@ format_value_callback_time (GtkScale *scale, } static void -lock_checkbox_toggled (GtkToggleButton *button, gpointer user_data) -{ +lock_checkbox_toggled (GtkToggleButton *button, gpointer user_data) { config_set_lock (gtk_toggle_button_get_active (button)); } static void -enabled_checkbox_toggled (GtkToggleButton *button, gpointer user_data) -{ +enabled_checkbox_toggled (GtkToggleButton *button, gpointer user_data) { config_set_enabled (gtk_toggle_button_get_active (button)); } static void -ui_set_lock (gboolean enabled) -{ +ui_set_lock (gboolean enabled) { GtkWidget *widget; gboolean active; widget = GTK_WIDGET (gtk_builder_get_object (builder, "lock_checkbox")); active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); - if (active != enabled) - { + if (active != enabled) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), enabled); } } static void -ui_set_enabled (gboolean enabled) -{ +ui_set_enabled (gboolean enabled) { GtkWidget *widget; gboolean active; gboolean is_writable; widget = GTK_WIDGET (gtk_builder_get_object (builder, "enable_checkbox")); active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); - if (active != enabled) - { + if (active != enabled) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), enabled); } widget = GTK_WIDGET (gtk_builder_get_object (builder, "lock_checkbox")); config_get_lock (&is_writable); - if (is_writable) - { + if (is_writable) { gtk_widget_set_sensitive (widget, enabled); } } static void -ui_set_delay (int delay) -{ +ui_set_delay (int delay) { GtkWidget *widget; widget = GTK_WIDGET (gtk_builder_get_object (builder, "activate_delay_hscale")); @@ -1129,42 +977,31 @@ ui_set_delay (int delay) } static void -key_changed_cb (XfconfChannel *channel, const gchar *key, gpointer data) -{ - if (strcmp (key, KEY_IDLE_ACTIVATION_ENABLED) == 0) - { +key_changed_cb (XfconfChannel *channel, const gchar *key, gpointer data) { + if (strcmp (key, KEY_IDLE_ACTIVATION_ENABLED) == 0) { gboolean enabled; enabled = xfconf_channel_get_bool (channel, key, DEFAULT_KEY_IDLE_ACTIVATION_ENABLED); ui_set_enabled (enabled); - } - else if (strcmp (key, KEY_LOCK_ENABLED) == 0) - { + } else if (strcmp (key, KEY_LOCK_ENABLED) == 0) { gboolean enabled; enabled = xfconf_channel_get_bool (channel, key, DEFAULT_KEY_LOCK_ENABLED); ui_set_lock (enabled); - } - else if (strcmp (key, KEY_THEMES) == 0) - { + } else if (strcmp (key, KEY_THEMES) == 0) { GtkWidget *treeview; treeview = GTK_WIDGET (gtk_builder_get_object (builder, "savers_treeview")); setup_treeview_selection (treeview); - } - else if (strcmp (key, KEY_IDLE_DELAY) == 0) - { + } else if (strcmp (key, KEY_IDLE_DELAY) == 0) { int delay; delay = xfconf_channel_get_int (channel, key, DEFAULT_KEY_IDLE_DELAY); ui_set_delay (delay); - } - else - { + } else { /*g_warning ("Config key not handled: %s", key);*/ } } static void fullscreen_preview_previous_cb (GtkWidget *fullscreen_preview_window, - gpointer user_data) -{ + gpointer user_data) { GtkWidget *treeview; GtkTreeSelection *selection; @@ -1175,8 +1012,7 @@ fullscreen_preview_previous_cb (GtkWidget *fullscreen_preview_window, static void fullscreen_preview_next_cb (GtkWidget *fullscreen_preview_window, - gpointer user_data) -{ + gpointer user_data) { GtkWidget *treeview; GtkTreeSelection *selection; @@ -1187,9 +1023,7 @@ fullscreen_preview_next_cb (GtkWidget *fullscreen_preview_window, static void fullscreen_preview_cancelled_cb (GtkWidget *button, - gpointer user_data) -{ - + gpointer user_data) { GtkWidget *fullscreen_preview_area; GtkWidget *fullscreen_preview_window; GtkWidget *preview_area; @@ -1211,8 +1045,7 @@ fullscreen_preview_cancelled_cb (GtkWidget *button, static void fullscreen_preview_start_cb (GtkWidget *widget, - gpointer user_data) -{ + gpointer user_data) { GtkWidget *fullscreen_preview_area; GtkWidget *fullscreen_preview_window; GtkWidget *dialog; @@ -1236,8 +1069,7 @@ fullscreen_preview_start_cb (GtkWidget *widget, static void constrain_list_size (GtkWidget *widget, GtkAllocation *allocation, - GtkWidget *to_size) -{ + GtkWidget *to_size) { GtkRequisition req; int max_height; @@ -1250,15 +1082,13 @@ constrain_list_size (GtkWidget *widget, static void setup_list_size_constraint (GtkWidget *widget, - GtkWidget *to_size) -{ + GtkWidget *to_size) { g_signal_connect (widget, "size-allocate", G_CALLBACK (constrain_list_size), to_size); } static gboolean -check_is_root_user (void) -{ +check_is_root_user (void) { #ifndef G_OS_WIN32 uid_t ruid, euid, suid; /* Real, effective and saved user ID's */ gid_t rgid, egid, sgid; /* Real, effective and saved group ID's */ @@ -1274,18 +1104,16 @@ check_is_root_user (void) egid = getegid (); } - if (ruid == 0) - { + if (ruid == 0) { return TRUE; } -#endif +#endif /* G_OS_WIN32 */ return FALSE; } static void -setup_for_root_user (void) -{ +setup_for_root_user (void) { GtkWidget *lock_checkbox; GtkWidget *infobar; @@ -1300,23 +1128,20 @@ setup_for_root_user (void) static void resolve_lid_switch_cb (GtkWidget *widget, - gpointer user_data) -{ + gpointer user_data) { XfconfChannel *channel = xfconf_channel_get("xfce4-power-manager"); const gchar *property = "/xfce4-power-manager/logind-handle-lid-switch"; gboolean locked = xfconf_channel_is_property_locked(channel, property); GtkWidget *infobar = GTK_WIDGET (gtk_builder_get_object (builder, "logind_lid_infobar")); - if (!locked) - { + if (!locked) { xfconf_channel_set_bool(channel, property, FALSE); gtk_widget_hide (GTK_WIDGET (infobar)); } } static void -setup_for_lid_switch (void) -{ +setup_for_lid_switch (void) { XfconfChannel *channel = xfconf_channel_get ("xfce4-power-manager"); const gchar *property = "/xfce4-power-manager/logind-handle-lid-switch"; gboolean handled = xfconf_channel_get_bool (channel, property, FALSE); @@ -1327,21 +1152,15 @@ setup_for_lid_switch (void) infobar = GTK_WIDGET (gtk_builder_get_object (builder, "logind_lid_infobar")); button = GTK_WIDGET (gtk_builder_get_object (builder, "logind_lid_resolve")); - if (handled) - { + if (handled) { gtk_widget_show (infobar); - if (locked) - { + if (locked) { gtk_widget_hide (button); - } - else - { + } else { gtk_widget_show (button); g_signal_connect (button, "clicked", G_CALLBACK (resolve_lid_switch_cb), NULL); } - } - else - { + } else { gtk_widget_hide (infobar); } } @@ -1351,8 +1170,7 @@ extern char **environ; static gchar ** spawn_make_environment_for_display (GdkDisplay *display, - gchar **envp) -{ + gchar **envp) { gchar **retval = NULL; const gchar *display_name; gint display_index = -1; @@ -1389,16 +1207,14 @@ spawn_command_line_on_display_sync (GdkDisplay *display, char **standard_output, char **standard_error, int *exit_status, - GError **error) -{ + GError **error) { char **argv = NULL; char **envp = NULL; gboolean retval; g_return_val_if_fail (command_line != NULL, FALSE); - if (! g_shell_parse_argv (command_line, NULL, &argv, error)) - { + if (!g_shell_parse_argv (command_line, NULL, &argv, error)) { return FALSE; } @@ -1423,8 +1239,7 @@ spawn_command_line_on_display_sync (GdkDisplay *display, static GdkVisual * -get_best_visual_for_display (GdkDisplay *display) -{ +get_best_visual_for_display (GdkDisplay *display) { GdkScreen *screen; char *command; char *std_output; @@ -1448,17 +1263,14 @@ get_best_visual_for_display (GdkDisplay *display) NULL, &exit_status, &error); - if (! res) - { + if (!res) { gs_debug ("Could not run command '%s': %s", command, error->message); g_error_free (error); goto out; } - if (1 == sscanf (std_output, "0x%lx %c", &v, &c)) - { - if (v != 0) - { + if (1 == sscanf (std_output, "0x%lx %c", &v, &c)) { + if (v != 0) { VisualID visual_id; visual_id = (VisualID) v; @@ -1478,23 +1290,20 @@ out: static void -widget_set_best_visual (GtkWidget *widget) -{ +widget_set_best_visual (GtkWidget *widget) { GdkVisual *visual; g_return_if_fail (widget != NULL); visual = get_best_visual_for_display (gtk_widget_get_display (widget)); - if (visual != NULL) - { + if (visual != NULL) { gtk_widget_set_visual (widget, visual); g_object_unref (visual); } } static gboolean -setup_treeview_idle (gpointer data) -{ +setup_treeview_idle (gpointer data) { GtkWidget *preview; GtkWidget *treeview; @@ -1508,23 +1317,18 @@ setup_treeview_idle (gpointer data) } static gboolean -is_program_in_path (const char *program) -{ +is_program_in_path (const char *program) { char *tmp = g_find_program_in_path (program); - if (tmp != NULL) - { + if (tmp != NULL) { g_free (tmp); return TRUE; - } - else - { + } else { return FALSE; } } static void -configure_capplet (void) -{ +configure_capplet (void) { GtkWidget *dialog; GtkWidget *plug_child; GtkWidget *preview; @@ -1546,20 +1350,17 @@ configure_capplet (void) gdouble activate_delay; gboolean enabled; gboolean is_writable; - GError *error=NULL; + GError *error = NULL; gint mode; builder = gtk_builder_new(); if (!gtk_builder_add_from_string (builder, xfce4_screensaver_preferences_ui, - xfce4_screensaver_preferences_ui_length, &error)) - { + xfce4_screensaver_preferences_ui_length, &error)) { g_warning ("Error loading UI: %s", error->message); g_error_free(error); } - if (builder == NULL) - { - + if (builder == NULL) { dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, @@ -1600,8 +1401,7 @@ configure_capplet (void) gtk_widget_set_no_show_all (root_warning_infobar, TRUE); widget_set_best_visual (preview); - if (! is_program_in_path (GPM_COMMAND)) - { + if (!is_program_in_path (GPM_COMMAND)) { gtk_widget_set_no_show_all (gpm_button, TRUE); gtk_widget_hide (gpm_button); } @@ -1614,16 +1414,14 @@ configure_capplet (void) activate_delay = config_get_activate_delay (&is_writable); ui_set_delay (activate_delay); - if (! is_writable) - { + if (!is_writable) { gtk_widget_set_sensitive (activate_delay_hbox, FALSE); } g_signal_connect (activate_delay_hscale, "format-value", G_CALLBACK (format_value_callback_time), NULL); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lock_checkbox), config_get_lock (&is_writable)); - if (! is_writable) - { + if (!is_writable) { gtk_widget_set_sensitive (lock_checkbox, FALSE); } g_signal_connect (lock_checkbox, "toggled", @@ -1631,8 +1429,7 @@ configure_capplet (void) enabled = config_get_enabled (&is_writable); ui_set_enabled (enabled); - if (! is_writable) - { + if (!is_writable) { gtk_widget_set_sensitive (enabled_checkbox, FALSE); } g_signal_connect (enabled_checkbox, "toggled", @@ -1672,8 +1469,7 @@ configure_capplet (void) setup_for_lid_switch (); - if (check_is_root_user ()) - { + if (check_is_root_user ()) { setup_for_root_user (); } @@ -1695,15 +1491,13 @@ configure_capplet (void) } static void -finalize_capplet (void) -{ +finalize_capplet (void) { g_object_unref (screensaver_channel); } int main (int argc, - char **argv) -{ + char **argv) { GtkWidget *plug; GObject *plug_child; GError *error = NULL; @@ -1716,16 +1510,12 @@ main (int argc, textdomain (GETTEXT_PACKAGE); #endif - if (!gtk_init_with_args (&argc, &argv, "", entries, NULL, &error)) - { - if (G_LIKELY (error)) - { + if (!gtk_init_with_args (&argc, &argv, "", entries, NULL, &error)) { + if (G_LIKELY (error)) { /* print error */ g_error ("%s\n", error->message); g_error_free (error); - } - else - { + } else { g_error ("Unable to open display."); } @@ -1736,8 +1526,7 @@ main (int argc, if (xfce_titled_dialog_get_type() == 0) exit(1); - if (!xfconf_init(&error)) - { + if (!xfconf_init(&error)) { g_error("Failed to connect to xfconf daemon: %s.", error->message); g_error_free(error); @@ -1749,8 +1538,7 @@ main (int argc, configure_capplet (); - if (G_UNLIKELY(opt_socket_id == 0)) - { + if (G_UNLIKELY(opt_socket_id == 0)) { GtkWidget *dialog = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_dialog")); g_signal_connect(dialog, "response", @@ -1762,9 +1550,7 @@ main (int argc, gdk_x11_set_sm_client_id("FAKE ID"); gtk_main(); - } - else - { + } else { /* Create plug widget */ plug = gtk_plug_new(opt_socket_id); g_signal_connect(plug, "delete-event", G_CALLBACK(gtk_main_quit), NULL); diff --git a/src/xfce4-screensaver.c b/src/xfce4-screensaver.c index cb31d5e58372d9f1cacddda5e68e2be24391db6a..170199fc7db3204e90934540e314344248c119dd 100644 --- a/src/xfce4-screensaver.c +++ b/src/xfce4-screensaver.c @@ -22,32 +22,31 @@ * */ -#include "config.h" +#include <config.h> + +#include <errno.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> -#include <errno.h> #include <sys/time.h> #include <sys/types.h> #include <sys/wait.h> +#include <unistd.h> -#include <libxfce4util/libxfce4util.h> #include <gtk/gtk.h> -#include "xfce4-screensaver.h" -#include "gs-monitor.h" -#include "gs-debug.h" - +#include <libxfce4util/libxfce4util.h> #include <xfconf/xfconf.h> -void xfce4_screensaver_quit(void) -{ +#include "src/gs-monitor.h" +#include "src/gs-debug.h" +#include "src/xfce4-screensaver.h" + +void xfce4_screensaver_quit(void) { gtk_main_quit(); } int main(int argc, - char **argv) -{ + char **argv) { GSMonitor *monitor; GError *error = NULL; @@ -70,29 +69,23 @@ int main(int argc, textdomain(GETTEXT_PACKAGE); #endif - if (!gtk_init_with_args(&argc, &argv, NULL, entries, NULL, &error)) - { - if (error) - { + if (!gtk_init_with_args(&argc, &argv, NULL, entries, NULL, &error)) { + if (error) { g_warning("%s", error->message); g_error_free(error); - } - else - { + } else { g_warning("Unable to initialize GTK+"); } exit(1); } - if (show_version) - { + if (show_version) { g_print("%s %s\n", argv[0], VERSION); exit(1); } - if (!xfconf_init(&error)) - { + if (!xfconf_init(&error)) { g_error("Failed to connect to xfconf daemon: %s.", error->message); g_error_free(error); @@ -105,22 +98,17 @@ int main(int argc, monitor = gs_monitor_new(); - if (monitor == NULL) - { + if (monitor == NULL) { exit (1); } error = NULL; - if (!gs_monitor_start(monitor, &error)) - { - if (error) - { + if (!gs_monitor_start(monitor, &error)) { + if (error) { g_warning("%s", error->message); g_error_free(error); - } - else - { + } else { g_warning("Unable to start screensaver"); } diff --git a/src/xfcekbd-desktop-config.c b/src/xfcekbd-desktop-config.c index f1f8783972db73238f050429dde10d30afed7b69..cd90c6801dca574af864b57d8386d1c50eb86af9 100644 --- a/src/xfcekbd-desktop-config.c +++ b/src/xfcekbd-desktop-config.c @@ -21,16 +21,18 @@ #include <config.h> #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> + #include <X11/keysym.h> -#include <xfconf/xfconf.h> +#include <gio/gio.h> #include <libxfce4util/libxfce4util.h> -#include <gio/gio.h> -#include "xfcekbd-desktop-config.h" -#include "xfcekbd-config-private.h" +#include <xfconf/xfconf.h> + +#include "src/xfcekbd-desktop-config.h" +#include "src/xfcekbd-config-private.h" /* * static common functions @@ -44,8 +46,7 @@ xfcekbd_desktop_config_get_lv_descriptions (XfcekbdDesktopConfig *config, gchar ***short_layout_descriptions, gchar ***long_layout_descriptions, gchar ***short_variant_descriptions, - gchar ***long_variant_descriptions) -{ + gchar ***long_variant_descriptions) { const gchar **pl, **pv; guint total_layouts; gchar **sld, **lld, **svd, **lvd; @@ -63,7 +64,6 @@ xfcekbd_desktop_config_get_lv_descriptions (XfcekbdDesktopConfig *config, lvd = *long_variant_descriptions = g_new0 (gchar *, total_layouts + 1); while (pl != NULL && *pl != NULL) { - xkl_debug (100, "ids: [%s][%s]\n", *pl, pv == NULL ? NULL : *pv); g_snprintf (item->name, sizeof item->name, "%s", *pl); @@ -110,23 +110,20 @@ xfcekbd_desktop_config_get_lv_descriptions (XfcekbdDesktopConfig *config, */ void xfcekbd_desktop_config_init (XfcekbdDesktopConfig *config, - XklEngine *engine) -{ + XklEngine *engine) { memset (config, 0, sizeof (*config)); config->channel = xfconf_channel_get (SETTINGS_XFCONF_CHANNEL); config->engine = engine; } void -xfcekbd_desktop_config_term (XfcekbdDesktopConfig *config) -{ +xfcekbd_desktop_config_term (XfcekbdDesktopConfig *config) { g_object_unref (config->channel); config->channel = NULL; } void -xfcekbd_desktop_config_load_from_xfconf (XfcekbdDesktopConfig *config) -{ +xfcekbd_desktop_config_load_from_xfconf (XfcekbdDesktopConfig *config) { config->group_per_app = xfconf_channel_get_bool(config->channel, KEY_KBD_GROUP_PER_WINDOW, @@ -158,16 +155,14 @@ xfcekbd_desktop_config_load_from_xfconf (XfcekbdDesktopConfig *config) if (config->default_group < -1 || config->default_group >= - xkl_engine_get_max_num_groups (config->engine)) - { + xkl_engine_get_max_num_groups (config->engine)) { config->default_group = -1; } xkl_debug (150, "default_group: %d\n", config->default_group); } gboolean -xfcekbd_desktop_config_activate (XfcekbdDesktopConfig *config) -{ +xfcekbd_desktop_config_activate (XfcekbdDesktopConfig *config) { gboolean rv = TRUE; xkl_engine_set_group_per_toplevel_window (config->engine, @@ -181,8 +176,7 @@ xfcekbd_desktop_config_activate (XfcekbdDesktopConfig *config) } void -xfcekbd_desktop_config_lock_next_group (XfcekbdDesktopConfig *config) -{ +xfcekbd_desktop_config_lock_next_group (XfcekbdDesktopConfig *config) { int group = xkl_engine_get_next_group (config->engine); xkl_engine_lock_group (config->engine, group); } @@ -194,16 +188,14 @@ xfcekbd_desktop_config_lock_next_group (XfcekbdDesktopConfig *config) void xfcekbd_desktop_config_start_listen (XfcekbdDesktopConfig *config, GCallback func, - gpointer user_data) -{ + gpointer user_data) { config->config_listener_id = g_signal_connect (config->channel, "property-changed", func, user_data); } void -xfcekbd_desktop_config_stop_listen (XfcekbdDesktopConfig *config) -{ +xfcekbd_desktop_config_stop_listen (XfcekbdDesktopConfig *config) { g_signal_handler_disconnect (config->channel, config->config_listener_id); config->config_listener_id = 0; @@ -215,8 +207,7 @@ xfcekbd_desktop_config_load_group_descriptions (XfcekbdDesktopConfig *config, const gchar **layout_ids, const gchar **variant_ids, gchar ***short_group_names, - gchar ***full_group_names) -{ + gchar ***full_group_names) { gchar **sld, **lld, **svd, **lvd; gchar **psld, **plld, **plvd; gchar **psgn, **pfgn, **psvd; @@ -229,8 +220,7 @@ xfcekbd_desktop_config_load_group_descriptions (XfcekbdDesktopConfig *config, &sld, &lld, &svd, - &lvd)) - { + &lvd)) { return False; } diff --git a/src/xfcekbd-indicator-config.c b/src/xfcekbd-indicator-config.c index a77792262f5542240e0de7ce4ebed84584c58638..5182d694d06f18f1c648a2d3198273d495d5c9b3 100644 --- a/src/xfcekbd-indicator-config.c +++ b/src/xfcekbd-indicator-config.c @@ -21,36 +21,33 @@ #include <config.h> #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> + #include <X11/keysym.h> +#include <gdk/gdkx.h> #include <pango/pango.h> #include <libxfce4util/libxfce4util.h> -#include <gdk/gdkx.h> - #include <xfconf/xfconf.h> -#include "xfcekbd-keyboard-config.h" -#include "xfcekbd-indicator-config.h" - -#include "xfcekbd-config-private.h" +#include "src/xfcekbd-keyboard-config.h" +#include "src/xfcekbd-indicator-config.h" +#include "src/xfcekbd-config-private.h" /* * static applet config functions */ static void -xfcekbd_indicator_config_load_font (XfcekbdIndicatorConfig *ind_config) -{ +xfcekbd_indicator_config_load_font (XfcekbdIndicatorConfig *ind_config) { ind_config->font_family = xfconf_channel_get_string(ind_config->channel, KEY_KBD_INDICATOR_FONT_FAMILY, DEFAULT_KEY_KBD_INDICATOR_FONT_FAMILY); if (ind_config->font_family == NULL || - ind_config->font_family[0] == '\0') - { + ind_config->font_family[0] == '\0') { PangoFontDescription *fd = NULL; GtkWidgetPath *widget_path = gtk_widget_path_new (); GtkStyleContext *context = gtk_style_context_new (); @@ -80,8 +77,7 @@ xfcekbd_indicator_config_load_font (XfcekbdIndicatorConfig *ind_config) } static void -xfcekbd_indicator_config_load_colors (XfcekbdIndicatorConfig *ind_config) -{ +xfcekbd_indicator_config_load_colors (XfcekbdIndicatorConfig *ind_config) { ind_config->foreground_color = xfconf_channel_get_string(ind_config->channel, KEY_KBD_INDICATOR_FOREGROUND_COLOR, @@ -124,8 +120,7 @@ xfcekbd_indicator_config_load_colors (XfcekbdIndicatorConfig *ind_config) static gchar * xfcekbd_indicator_config_get_images_file (XfcekbdIndicatorConfig *ind_config, XfcekbdKeyboardConfig *kbd_config, - int group) -{ + int group) { char *image_file = NULL; GtkIconInfo *icon_info = NULL; @@ -173,8 +168,7 @@ void xfcekbd_indicator_config_load_image_filenames (XfcekbdIndicatorConfig * ind_config, XfcekbdKeyboardConfig * - kbd_config) -{ + kbd_config) { int i; ind_config->image_filenames = NULL; @@ -194,8 +188,7 @@ xfcekbd_indicator_config_load_image_filenames (XfcekbdIndicatorConfig * } void -xfcekbd_indicator_config_free_image_filenames (XfcekbdIndicatorConfig *ind_config) -{ +xfcekbd_indicator_config_free_image_filenames (XfcekbdIndicatorConfig *ind_config) { while (ind_config->image_filenames) { if (ind_config->image_filenames->data) g_free (ind_config->image_filenames->data); @@ -207,8 +200,7 @@ xfcekbd_indicator_config_free_image_filenames (XfcekbdIndicatorConfig *ind_confi void xfcekbd_indicator_config_init (XfcekbdIndicatorConfig *ind_config, - XklEngine *engine) -{ + XklEngine *engine) { gchar *sp; memset (ind_config, 0, sizeof (*ind_config)); @@ -240,8 +232,7 @@ xfcekbd_indicator_config_init (XfcekbdIndicatorConfig *ind_config, } void -xfcekbd_indicator_config_term (XfcekbdIndicatorConfig *ind_config) -{ +xfcekbd_indicator_config_term (XfcekbdIndicatorConfig *ind_config) { g_free (ind_config->font_family); ind_config->font_family = NULL; @@ -260,8 +251,7 @@ xfcekbd_indicator_config_term (XfcekbdIndicatorConfig *ind_config) } void -xfcekbd_indicator_config_load_from_xfconf (XfcekbdIndicatorConfig * ind_config) -{ +xfcekbd_indicator_config_load_from_xfconf (XfcekbdIndicatorConfig * ind_config) { ind_config->secondary_groups_mask = xfconf_channel_get_int (ind_config->channel, KEY_KBD_INDICATOR_SECONDARIES, @@ -274,12 +264,10 @@ xfcekbd_indicator_config_load_from_xfconf (XfcekbdIndicatorConfig * ind_config) xfcekbd_indicator_config_load_font (ind_config); xfcekbd_indicator_config_load_colors (ind_config); - } void -xfcekbd_indicator_config_activate (XfcekbdIndicatorConfig * ind_config) -{ +xfcekbd_indicator_config_activate (XfcekbdIndicatorConfig * ind_config) { xkl_engine_set_secondary_groups_mask (ind_config->engine, ind_config->secondary_groups_mask); } @@ -291,8 +279,7 @@ xfcekbd_indicator_config_activate (XfcekbdIndicatorConfig * ind_config) void xfcekbd_indicator_config_start_listen (XfcekbdIndicatorConfig *ind_config, GCallback func, - gpointer user_data) -{ + gpointer user_data) { ind_config->config_listener_id = g_signal_connect (ind_config->channel, "property-changed", @@ -301,8 +288,7 @@ xfcekbd_indicator_config_start_listen (XfcekbdIndicatorConfig *ind_config, } void -xfcekbd_indicator_config_stop_listen (XfcekbdIndicatorConfig *ind_config) -{ +xfcekbd_indicator_config_stop_listen (XfcekbdIndicatorConfig *ind_config) { g_signal_handler_disconnect (ind_config->channel, ind_config->config_listener_id); ind_config->config_listener_id = 0; diff --git a/src/xfcekbd-indicator.c b/src/xfcekbd-indicator.c index 49e49e4172f2f52341ab7581f872688ae7f3cbb4..992e66ea97939625d17599b623bdc6732da65d9b 100644 --- a/src/xfcekbd-indicator.c +++ b/src/xfcekbd-indicator.c @@ -17,20 +17,21 @@ * write to the Free Software Foundation, Inc., 51 Franklin St, * Fifth Floor, Boston, MA 02110-1301, USA. */ + #include <config.h> #include <memory.h> -#include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> #include <gdk/gdkx.h> -#include <libxfce4util/libxfce4util.h> +#include <gtk/gtk.h> -#include "xfcekbd-indicator.h" -#include "xfcekbd-indicator-marshal.h" +#include <libxfce4util/libxfce4util.h> -#include "xfcekbd-desktop-config.h" -#include "xfcekbd-indicator-config.h" +#include "src/xfcekbd-desktop-config.h" +#include "src/xfcekbd-indicator.h" +#include "src/xfcekbd-indicator-config.h" +#include "src/xfcekbd-indicator-marshal.h" typedef struct _gki_globals { XklEngine *engine; @@ -79,8 +80,7 @@ static void xfcekbd_indicator_set_tooltips (XfcekbdIndi const char *str); static void -xfcekbd_indicator_load_images () -{ +xfcekbd_indicator_load_images () { int i; GSList *image_filename; @@ -134,8 +134,7 @@ xfcekbd_indicator_load_images () } static void -xfcekbd_indicator_free_images () -{ +xfcekbd_indicator_free_images () { GdkPixbuf *pi; GSList *img_node; @@ -154,16 +153,14 @@ xfcekbd_indicator_free_images () } static void -xfcekbd_indicator_update_images (void) -{ +xfcekbd_indicator_update_images (void) { xfcekbd_indicator_free_images (); xfcekbd_indicator_load_images (); } void xfcekbd_indicator_set_tooltips (XfcekbdIndicator *gki, - const char *str) -{ + const char *str) { g_assert (str == NULL || g_utf8_validate (str, -1, NULL)); gtk_widget_set_tooltip_text (GTK_WIDGET (gki), str); @@ -178,8 +175,7 @@ xfcekbd_indicator_set_tooltips (XfcekbdIndicator *gki, } void -xfcekbd_indicator_cleanup (XfcekbdIndicator * gki) -{ +xfcekbd_indicator_cleanup (XfcekbdIndicator * gki) { int i; GtkNotebook *notebook = GTK_NOTEBOOK (gki); @@ -190,8 +186,7 @@ xfcekbd_indicator_cleanup (XfcekbdIndicator * gki) } void -xfcekbd_indicator_fill (XfcekbdIndicator * gki) -{ +xfcekbd_indicator_fill (XfcekbdIndicator * gki) { int grp; int total_groups = xkl_engine_get_num_groups (globals.engine); GtkNotebook *notebook = GTK_NOTEBOOK (gki); @@ -209,10 +204,8 @@ xfcekbd_indicator_fill (XfcekbdIndicator * gki) static gboolean xfcekbd_indicator_key_pressed (GtkWidget *widget, GdkEventKey *event, - XfcekbdIndicator *gki) -{ - switch (event->keyval) - { + XfcekbdIndicator *gki) { + switch (event->keyval) { case GDK_KEY_KP_Enter: case GDK_KEY_ISO_Enter: case GDK_KEY_3270_Enter: @@ -231,8 +224,7 @@ static gboolean xfcekbd_indicator_key_pressed (GtkWidget *widget, static gboolean xfcekbd_indicator_button_pressed (GtkWidget *widget, GdkEventButton *event, - XfcekbdIndicator *gki) -{ + XfcekbdIndicator *gki) { GtkWidget *img = gtk_bin_get_child (GTK_BIN (widget)); GtkAllocation allocation; gtk_widget_get_allocation (img, &allocation); @@ -248,8 +240,7 @@ xfcekbd_indicator_button_pressed (GtkWidget *widget, static void draw_flag (GtkWidget *flag, cairo_t *cr, - GdkPixbuf *image) -{ + GdkPixbuf *image) { /* Image width and height */ int iw = gdk_pixbuf_get_width (image); int ih = gdk_pixbuf_get_height (image); @@ -277,8 +268,7 @@ xfcekbd_indicator_extract_layout_name (int group, XklEngine *engine, XfcekbdKeyboardConfig *kbd_cfg, gchar **short_group_names, - gchar **full_group_names) -{ + gchar **full_group_names) { char *layout_name = NULL; if (group < g_strv_length (short_group_names)) { if (xkl_engine_get_features (engine) & XKLF_MULTIPLE_LAYOUTS_SUPPORTED) { @@ -286,8 +276,7 @@ xfcekbd_indicator_extract_layout_name (int group, char *variant_name; if (!xfcekbd_keyboard_config_split_items (full_layout_name, &layout_name, - &variant_name)) - { + &variant_name)) { /* just in case */ layout_name = full_layout_name; } @@ -318,8 +307,7 @@ xfcekbd_indicator_extract_layout_name (int group, static gchar * xfcekbd_indicator_create_label_title (int group, GHashTable **ln2cnt_map, - gchar *layout_name) -{ + gchar *layout_name) { gpointer pcounter = NULL; char *prev_layout_name = NULL; char *lbl_title = NULL; @@ -333,8 +321,7 @@ xfcekbd_indicator_create_label_title (int group, if (g_hash_table_lookup_extended (*ln2cnt_map, layout_name, (gpointer *) & prev_layout_name, - &pcounter)) - { + &pcounter)) { /* "next" same description */ gchar appendix[10] = ""; gint utf8length; @@ -356,8 +343,7 @@ xfcekbd_indicator_create_label_title (int group, static GtkWidget * xfcekbd_indicator_prepare_drawing (XfcekbdIndicator *gki, - int group) -{ + int group) { gpointer pimage; GdkPixbuf *image; GtkWidget *ebox; @@ -404,8 +390,7 @@ xfcekbd_indicator_prepare_drawing (XfcekbdIndicator *gki, g_free (lbl_title); gtk_label_set_angle (GTK_LABEL (label), gki->priv->angle); - if (group + 1 == xkl_engine_get_num_groups (globals.engine)) - { + if (group + 1 == xkl_engine_get_num_groups (globals.engine)) { g_hash_table_destroy (ln2cnt_map); ln2cnt_map = NULL; } @@ -427,14 +412,12 @@ xfcekbd_indicator_prepare_drawing (XfcekbdIndicator *gki, } static void -xfcekbd_indicator_update_tooltips (XfcekbdIndicator *gki) -{ +xfcekbd_indicator_update_tooltips (XfcekbdIndicator *gki) { XklState *state = xkl_engine_get_current_state (globals.engine); gchar *buf; if (state == NULL || state->group < 0 || - state->group >= g_strv_length (globals.full_group_names)) - { + state->group >= g_strv_length (globals.full_group_names)) { return; } @@ -446,15 +429,13 @@ xfcekbd_indicator_update_tooltips (XfcekbdIndicator *gki) static void xfcekbd_indicator_parent_set (GtkWidget *gki, - GtkWidget *previous_parent) -{ + GtkWidget *previous_parent) { xfcekbd_indicator_update_tooltips (XFCEKBD_INDICATOR (gki)); } static void -xfcekbd_indicator_reinit_ui (XfcekbdIndicator *gki) -{ +xfcekbd_indicator_reinit_ui (XfcekbdIndicator *gki) { xfcekbd_indicator_cleanup (gki); xfcekbd_indicator_fill (gki); @@ -467,8 +448,7 @@ xfcekbd_indicator_reinit_ui (XfcekbdIndicator *gki) static void xfcekbd_indicator_cfg_changed (XfconfChannel *channel, gchar *key, - gpointer user_data) -{ + gpointer user_data) { xkl_debug (100, "General configuration changed in Xfconf - reiniting...\n"); xfcekbd_desktop_config_load_from_xfconf (&globals.cfg); xfcekbd_desktop_config_activate (&globals.cfg); @@ -481,8 +461,7 @@ xfcekbd_indicator_cfg_changed (XfconfChannel *channel, static void xfcekbd_indicator_ind_cfg_changed (XfconfChannel *channel, gchar *key, - gpointer user_data) -{ + gpointer user_data) { xkl_debug (100, "Applet configuration changed in Xfconf - reiniting...\n"); xfcekbd_indicator_config_load_from_xfconf (&globals.ind_cfg); xfcekbd_indicator_update_images (); @@ -495,15 +474,13 @@ xfcekbd_indicator_ind_cfg_changed (XfconfChannel *channel, static void xfcekbd_indicator_load_group_names (const gchar **layout_ids, - const gchar **variant_ids) -{ + const gchar **variant_ids) { if (!xfcekbd_desktop_config_load_group_descriptions (&globals.cfg, globals.registry, layout_ids, variant_ids, &globals.short_group_names, - &globals.full_group_names)) - { + &globals.full_group_names)) { /* We just populate no short names (remain NULL) - * full names are going to be used anyway */ gint i, total_groups = xkl_engine_get_num_groups (globals.engine); @@ -524,8 +501,7 @@ xfcekbd_indicator_load_group_names (const gchar **layout_ids, /* Should be called once for all widgets */ static void -xfcekbd_indicator_kbd_cfg_callback (XfcekbdIndicator *gki) -{ +xfcekbd_indicator_kbd_cfg_callback (XfcekbdIndicator *gki) { XklConfigRec *xklrec = xkl_config_rec_new (); xkl_debug (100, "XKB configuration changed on X Server - reiniting...\n"); @@ -555,8 +531,7 @@ static void xfcekbd_indicator_state_callback (XklEngine *engine, XklEngineStateChange changeType, gint group, - gboolean restore) -{ + gboolean restore) { xkl_debug (150, "group is now %d, restore: %d\n", group, restore); if (changeType == GROUP_CHANGED) { @@ -571,8 +546,7 @@ xfcekbd_indicator_state_callback (XklEngine *engine, void -xfcekbd_indicator_set_current_page (XfcekbdIndicator *gki) -{ +xfcekbd_indicator_set_current_page (XfcekbdIndicator *gki) { XklState *cur_state; cur_state = xkl_engine_get_current_state (globals.engine); if (cur_state->group >= 0) @@ -582,8 +556,7 @@ xfcekbd_indicator_set_current_page (XfcekbdIndicator *gki) void xfcekbd_indicator_set_current_page_for_group (XfcekbdIndicator *gki, - int group) -{ + int group) { xkl_debug (200, "Revalidating for group %d\n", group); gtk_notebook_set_current_page (GTK_NOTEBOOK (gki), group + 1); @@ -594,8 +567,7 @@ xfcekbd_indicator_set_current_page_for_group (XfcekbdIndicator *gki, /* Should be called once for all widgets */ static GdkFilterReturn xfcekbd_indicator_filter_x_evt (GdkXEvent *xev, - GdkEvent *event) -{ + GdkEvent *event) { XEvent *xevent = (XEvent *) xev; xkl_engine_filter_events (globals.engine, xevent); @@ -628,8 +600,7 @@ xfcekbd_indicator_filter_x_evt (GdkXEvent *xev, /* Should be called once for all widgets */ static void -xfcekbd_indicator_start_listen (void) -{ +xfcekbd_indicator_start_listen (void) { gdk_window_add_filter (NULL, (GdkFilterFunc) xfcekbd_indicator_filter_x_evt, NULL); gdk_window_add_filter (gdk_get_default_root_window (), @@ -641,8 +612,7 @@ xfcekbd_indicator_start_listen (void) /* Should be called once for all widgets */ static void -xfcekbd_indicator_stop_listen (void) -{ +xfcekbd_indicator_stop_listen (void) { xkl_engine_stop_listen (globals.engine, XKLL_TRACK_KEYBOARD_STATE); gdk_window_remove_filter (NULL, (GdkFilterFunc) @@ -654,19 +624,16 @@ xfcekbd_indicator_stop_listen (void) static gboolean xfcekbd_indicator_scroll (GtkWidget *gki, - GdkEventScroll *event) -{ + GdkEventScroll *event) { /* mouse wheel events should be ignored, otherwise funny effects appear */ return TRUE; } -static void xfcekbd_indicator_init(XfcekbdIndicator *gki) -{ +static void xfcekbd_indicator_init(XfcekbdIndicator *gki) { GtkWidget *def_drawing; GtkNotebook *notebook; - if (!g_slist_length(globals.widget_instances)) - { + if (!g_slist_length(globals.widget_instances)) { xfcekbd_indicator_global_init(); } @@ -702,8 +669,7 @@ static void xfcekbd_indicator_init(XfcekbdIndicator *gki) } static void -xfcekbd_indicator_finalize (GObject *obj) -{ +xfcekbd_indicator_finalize (GObject *obj) { XfcekbdIndicator *gki = XFCEKBD_INDICATOR (obj); xkl_debug (100, "Starting the xfce-kbd-indicator widget shutdown process for %p\n", @@ -726,8 +692,7 @@ xfcekbd_indicator_finalize (GObject *obj) } static void -xfcekbd_indicator_global_term (void) -{ +xfcekbd_indicator_global_term (void) { xkl_debug (100, "*** Last XfcekbdIndicator instance ***\n"); xfcekbd_indicator_stop_listen (); @@ -746,8 +711,7 @@ xfcekbd_indicator_global_term (void) } static void -xfcekbd_indicator_class_init (XfcekbdIndicatorClass *klass) -{ +xfcekbd_indicator_class_init (XfcekbdIndicatorClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); @@ -774,14 +738,12 @@ xfcekbd_indicator_class_init (XfcekbdIndicatorClass *klass) } static void -xfcekbd_indicator_global_init (void) -{ +xfcekbd_indicator_global_init (void) { XklConfigRec *xklrec = xkl_config_rec_new (); globals.engine = xkl_engine_get_instance(GDK_DISPLAY_XDISPLAY(gdk_display_get_default())); - if (globals.engine == NULL) - { + if (globals.engine == NULL) { xkl_debug (0, "Libxklavier initialization error"); return; } @@ -831,14 +793,12 @@ xfcekbd_indicator_global_init (void) } GtkWidget * -xfcekbd_indicator_new (void) -{ +xfcekbd_indicator_new (void) { return GTK_WIDGET (g_object_new (xfcekbd_indicator_get_type (), NULL)); } void -xfcekbd_indicator_set_parent_tooltips (XfcekbdIndicator * gki, gboolean spt) -{ +xfcekbd_indicator_set_parent_tooltips (XfcekbdIndicator * gki, gboolean spt) { gki->priv->set_parent_tooltips = spt; xfcekbd_indicator_update_tooltips (gki); } diff --git a/src/xfcekbd-keyboard-config.c b/src/xfcekbd-keyboard-config.c index c06d05f15a5b8751866f612dcf54ba74f5818ae6..5c8db578795ee1004779c3f1632237ed163ac926 100644 --- a/src/xfcekbd-keyboard-config.c +++ b/src/xfcekbd-keyboard-config.c @@ -21,14 +21,15 @@ #include <config.h> #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> + #include <X11/keysym.h> #include <libxfce4util/libxfce4util.h> -#include "xfcekbd-keyboard-config.h" -#include "xfcekbd-config-private.h" +#include "src/xfcekbd-config-private.h" +#include "src/xfcekbd-keyboard-config.h" /* * XfcekbdKeyboardConfig @@ -39,8 +40,7 @@ */ static const gchar * xfcekbd_keyboard_config_merge_items (const gchar *parent, - const gchar *child) -{ + const gchar *child) { static gchar buffer[XKL_MAX_CI_NAME_LENGTH * 2 - 1]; *buffer = '\0'; if (parent != NULL) { @@ -60,8 +60,7 @@ xfcekbd_keyboard_config_merge_items (const gchar *parent, gboolean xfcekbd_keyboard_config_split_items (const gchar *merged, gchar **parent, - gchar **child) -{ + gchar **child) { static gchar pbuffer[XKL_MAX_CI_NAME_LENGTH]; static gchar cbuffer[XKL_MAX_CI_NAME_LENGTH]; int plen, clen; @@ -94,8 +93,7 @@ xfcekbd_keyboard_config_split_items (const gchar *merged, */ static void xfcekbd_keyboard_config_copy_from_xkl_config (XfcekbdKeyboardConfig *kbd_config, - XklConfigRec *pdata) -{ + XklConfigRec *pdata) { char **p, **p1; int i; @@ -161,15 +159,13 @@ xfcekbd_keyboard_config_copy_from_xkl_config (XfcekbdKeyboardConfig *kbd_config, */ void xfcekbd_keyboard_config_init (XfcekbdKeyboardConfig *kbd_config, - XklEngine *engine) -{ + XklEngine *engine) { memset (kbd_config, 0, sizeof (*kbd_config)); kbd_config->engine = engine; } void -xfcekbd_keyboard_config_term (XfcekbdKeyboardConfig *kbd_config) -{ +xfcekbd_keyboard_config_term (XfcekbdKeyboardConfig *kbd_config) { xfcekbd_keyboard_config_model_set (kbd_config, NULL); g_strfreev (kbd_config->layouts_variants); @@ -180,8 +176,7 @@ xfcekbd_keyboard_config_term (XfcekbdKeyboardConfig *kbd_config) void xfcekbd_keyboard_config_load_from_x_current (XfcekbdKeyboardConfig *kbd_config, - XklConfigRec *data) -{ + XklConfigRec *data) { gboolean own_data = data == NULL; xkl_debug (150, "Copying config from X(current)\n"); if (own_data) @@ -199,8 +194,7 @@ xfcekbd_keyboard_config_load_from_x_current (XfcekbdKeyboardConfig *kbd_config, void xfcekbd_keyboard_config_model_set (XfcekbdKeyboardConfig *kbd_config, - const gchar *model_name) -{ + const gchar *model_name) { if (kbd_config->model != NULL) g_free (kbd_config->model); kbd_config->model = @@ -212,8 +206,7 @@ void xfcekbd_keyboard_config_options_set (XfcekbdKeyboardConfig *kbd_config, gint idx, const gchar *group_name, - const gchar *option_name) -{ + const gchar *option_name) { const gchar *merged; if (group_name == NULL || option_name == NULL) return; @@ -226,8 +219,7 @@ xfcekbd_keyboard_config_options_set (XfcekbdKeyboardConfig *kbd_config, const gchar * xfcekbd_keyboard_config_format_full_layout (const gchar *layout_descr, - const gchar *variant_descr) -{ + const gchar *variant_descr) { static gchar full_descr[XKL_MAX_CI_DESC_LENGTH * 2]; if (variant_descr == NULL || variant_descr[0] == 0) g_snprintf (full_descr, sizeof (full_descr), "%s",