diff --git a/src/draw.c b/src/draw.c index 6d40a02..6b1971a 100644 --- a/src/draw.c +++ b/src/draw.c @@ -18,18 +18,18 @@ #include "queues.h" #include "x11/x.h" -typedef struct { +struct colored_layout { PangoLayout *l; - color_t fg; - color_t bg; - color_t frame; + struct color fg; + struct color bg; + struct color frame; char *text; PangoAttrList *attr; cairo_surface_t *icon; const notification *n; -} colored_layout; +}; -window_x11 *win; +struct window_x11 *win; PangoFontDescription *pango_fdesc; @@ -41,9 +41,9 @@ void draw_setup(void) pango_fdesc = pango_font_description_from_string(settings.font); } -static color_t color_hex_to_double(int hexValue) +static struct color color_hex_to_double(int hexValue) { - color_t color; + struct color color; color.r = ((hexValue >> 16) & 0xFF) / 255.0; color.g = ((hexValue >> 8) & 0xFF) / 255.0; color.b = ((hexValue) & 0xFF) / 255.0; @@ -51,7 +51,7 @@ static color_t color_hex_to_double(int hexValue) return color; } -static color_t string_to_color(const char *str) +static struct color string_to_color(const char *str) { char *end; long int val = strtol(str+1, &end, 16); @@ -73,10 +73,10 @@ static double color_apply_delta(double base, double delta) return base; } -static color_t calculate_foreground_color(color_t bg) +static struct color calculate_foreground_color(struct color bg) { double c_delta = 0.1; - color_t color = bg; + struct color color = bg; /* do we need to darken or brighten the colors? */ bool darken = (bg.r + bg.g + bg.b) / 3 > 0.5; @@ -90,7 +90,8 @@ static color_t calculate_foreground_color(color_t bg) return color; } -static color_t layout_get_sepcolor(colored_layout *cl, colored_layout *cl_next) +static struct color layout_get_sepcolor(struct colored_layout *cl, + struct colored_layout *cl_next) { switch (settings.sep_color) { case SEP_FRAME: @@ -136,7 +137,7 @@ static void layout_setup_pango(PangoLayout *layout, int width) static void free_colored_layout(void *data) { - colored_layout *cl = data; + struct colored_layout *cl = data; g_object_unref(cl->l); pango_attr_list_unref(cl->attr); g_free(cl->text); @@ -153,7 +154,7 @@ static struct dimensions calculate_dimensions(GSList *layouts) { struct dimensions dim = { 0 }; - screen_info *scr = get_active_screen(); + struct screen_info *scr = get_active_screen(); if (have_dynamic_width()) { /* dynamic width */ dim.w = 0; @@ -176,7 +177,7 @@ static struct dimensions calculate_dimensions(GSList *layouts) int text_width = 0, total_width = 0; for (GSList *iter = layouts; iter; iter = iter->next) { - colored_layout *cl = iter->data; + struct colored_layout *cl = iter->data; int w=0,h=0; pango_layout_get_pixel_size(cl->l, &w, &h); if (cl->icon) { @@ -233,7 +234,7 @@ static struct dimensions calculate_dimensions(GSList *layouts) static PangoLayout *layout_create(cairo_t *c) { - screen_info *screen = get_active_screen(); + struct screen_info *screen = get_active_screen(); PangoContext *context = pango_cairo_create_context(c); pango_cairo_context_set_resolution(context, get_dpi_for_screen(screen)); @@ -245,9 +246,9 @@ static PangoLayout *layout_create(cairo_t *c) return layout; } -static colored_layout *layout_init_shared(cairo_t *c, const notification *n) +static struct colored_layout *layout_init_shared(cairo_t *c, const notification *n) { - colored_layout *cl = g_malloc(sizeof(colored_layout)); + struct colored_layout *cl = g_malloc(sizeof(struct colored_layout)); cl->l = layout_create(c); if (!settings.word_wrap) { @@ -301,19 +302,19 @@ static colored_layout *layout_init_shared(cairo_t *c, const notification *n) return cl; } -static colored_layout *layout_derive_xmore(cairo_t *c, const notification *n, int qlen) +static struct colored_layout *layout_derive_xmore(cairo_t *c, const notification *n, int qlen) { - colored_layout *cl = layout_init_shared(c, n); + struct colored_layout *cl = layout_init_shared(c, n); cl->text = g_strdup_printf("(%d more)", qlen); cl->attr = NULL; pango_layout_set_text(cl->l, cl->text, -1); return cl; } -static colored_layout *layout_from_notification(cairo_t *c, notification *n) +static struct colored_layout *layout_from_notification(cairo_t *c, notification *n) { - colored_layout *cl = layout_init_shared(c, n); + struct colored_layout *cl = layout_init_shared(c, n); /* markup */ GError *err = NULL; @@ -380,7 +381,7 @@ static void free_layouts(GSList *layouts) g_slist_free_full(layouts, free_colored_layout); } -static int layout_get_height(colored_layout *cl) +static int layout_get_height(struct colored_layout *cl) { int h; int h_icon = 0; @@ -446,8 +447,8 @@ static void draw_rounded_rect(cairo_t *c, int x, int y, int width, int height, i } static cairo_surface_t *render_background(cairo_surface_t *srf, - colored_layout *cl, - colored_layout *cl_next, + struct colored_layout *cl, + struct colored_layout *cl_next, int y, int width, int height, @@ -492,7 +493,7 @@ static cairo_surface_t *render_background(cairo_surface_t *srf, if ( settings.sep_color != SEP_FRAME && settings.separator_height > 0 && !last) { - color_t sep_color = layout_get_sepcolor(cl, cl_next); + struct color sep_color = layout_get_sepcolor(cl, cl_next); cairo_set_source_rgb(c, sep_color.r, sep_color.g, sep_color.b); cairo_rectangle(c, settings.frame_width, y + height, width, settings.separator_height); @@ -508,7 +509,7 @@ static cairo_surface_t *render_background(cairo_surface_t *srf, return cairo_surface_create_for_rectangle(srf, x, y, width, height); } -static void render_content(cairo_t *c, colored_layout *cl, int width) +static void render_content(cairo_t *c, struct colored_layout *cl, int width) { const int h = layout_get_height(cl); int h_text; @@ -550,8 +551,8 @@ static void render_content(cairo_t *c, colored_layout *cl, int width) } static struct dimensions layout_render(cairo_surface_t *srf, - colored_layout *cl, - colored_layout *cl_next, + struct colored_layout *cl, + struct colored_layout *cl_next, struct dimensions dim, bool first, bool last) @@ -593,7 +594,7 @@ static struct dimensions layout_render(cairo_surface_t *srf, */ static void calc_window_pos(int width, int height, int *ret_x, int *ret_y) { - screen_info *scr = get_active_screen(); + struct screen_info *scr = get_active_screen(); if (ret_x) { if (settings.geometry.negative_x) { @@ -624,8 +625,8 @@ void draw(void) bool first = true; for (GSList *iter = layouts; iter; iter = iter->next) { - colored_layout *cl_this = iter->data; - colored_layout *cl_next = iter->next ? iter->next->data : NULL; + struct colored_layout *cl_this = iter->data; + struct colored_layout *cl_next = iter->next ? iter->next->data : NULL; dim = layout_render(image_surface, cl_this, cl_next, dim, first, !cl_next); diff --git a/src/draw.h b/src/draw.h index 3a3ea88..581d0ca 100644 --- a/src/draw.h +++ b/src/draw.h @@ -2,7 +2,7 @@ #define DUNST_DRAW_H #include "src/x11/x.h" -extern window_x11 *win; // Temporary +extern struct window_x11 *win; // Temporary void draw_setup(void); diff --git a/src/settings.h b/src/settings.h index 272e079..f35a11c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -80,10 +80,10 @@ typedef struct _settings { char *icon_path; enum follow_mode f_mode; bool always_run_script; - keyboard_shortcut close_ks; - keyboard_shortcut close_all_ks; - keyboard_shortcut history_ks; - keyboard_shortcut context_ks; + struct keyboard_shortcut close_ks; + struct keyboard_shortcut close_all_ks; + struct keyboard_shortcut history_ks; + struct keyboard_shortcut context_ks; bool force_xinerama; int corner_radius; enum mouse_action mouse_left_click; diff --git a/src/x11/screen.c b/src/x11/screen.c index 185a607..edf9838 100644 --- a/src/x11/screen.c +++ b/src/x11/screen.c @@ -19,7 +19,7 @@ #include "src/settings.h" #include "x.h" -screen_info *screens; +struct screen_info *screens; int screens_len; bool dunst_follow_errored = false; @@ -80,9 +80,9 @@ void alloc_screen_ar(int n) assert(n > 0); if (n <= screens_len) return; - screens = g_realloc(screens, n * sizeof(screen_info)); + screens = g_realloc(screens, n * sizeof(struct screen_info)); - memset(screens, 0, n * sizeof(screen_info)); + memset(screens, 0, n * sizeof(struct screen_info)); screens_len = n; } @@ -137,7 +137,7 @@ void randr_update(void) XRRFreeMonitors(m); } -static int autodetect_dpi(screen_info *scr) +static int autodetect_dpi(struct screen_info *scr) { return (double)scr->h * 25.4 / (double)scr->mmh; } @@ -278,7 +278,7 @@ bool window_is_fullscreen(Window window) * Select the screen on which the Window * should be displayed. */ -screen_info *get_active_screen(void) +struct screen_info *get_active_screen(void) { int ret = 0; if (settings.monitor > 0 && settings.monitor < screens_len) { @@ -351,7 +351,7 @@ sc_cleanup: return &screens[ret]; } -double get_dpi_for_screen(screen_info *scr) +double get_dpi_for_screen(struct screen_info *scr) { double dpi = 0; if ((!settings.force_xinerama && settings.per_monitor_dpi && diff --git a/src/x11/screen.h b/src/x11/screen.h index 1188299..5ff2e69 100644 --- a/src/x11/screen.h +++ b/src/x11/screen.h @@ -7,20 +7,20 @@ #define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh)) -typedef struct { +struct screen_info { int id; int x; int y; unsigned int h; unsigned int mmh; unsigned int w; -} screen_info; +}; void init_screens(void); void screen_check_event(XEvent event); -screen_info *get_active_screen(void); -double get_dpi_for_screen(screen_info *scr); +struct screen_info *get_active_screen(void); +double get_dpi_for_screen(struct screen_info *scr); /** * Find the currently focused window and check if it's in diff --git a/src/x11/x.c b/src/x11/x.c index bf50a73..52430f8 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -46,24 +46,24 @@ struct window_x11 { struct x11_source { GSource source; - window_x11 *win; + struct window_x11 *win; }; -xctx_t xctx; +struct x_context xctx; bool dunst_grab_errored = false; static bool fullscreen_last = false; -static void x_shortcut_init(keyboard_shortcut *ks); -static int x_shortcut_grab(keyboard_shortcut *ks); -static void x_shortcut_ungrab(keyboard_shortcut *ks); +static void x_shortcut_init(struct keyboard_shortcut *ks); +static int x_shortcut_grab(struct keyboard_shortcut *ks); +static void x_shortcut_ungrab(struct keyboard_shortcut *ks); /* FIXME refactor setup teardown handlers into one setup and one teardown */ static void x_shortcut_setup_error_handler(void); static int x_shortcut_tear_down_error_handler(void); static void setopacity(Window win, unsigned long opacity); static void x_handle_click(XEvent ev); -static void x_win_move(window_x11 *win, int x, int y, int width, int height) +static void x_win_move(struct window_x11 *win, int x, int y, int width, int height) { /* move and resize */ if (x != win->dim.x || y != win->dim.y) { @@ -81,7 +81,7 @@ static void x_win_move(window_x11 *win, int x, int y, int width, int height) } } -static void x_win_round_corners(window_x11 *win, const int rad) +static void x_win_round_corners(struct window_x11 *win, const int rad) { const int width = win->dim.w; const int height = win->dim.h; @@ -148,7 +148,7 @@ static void x_win_round_corners(window_x11 *win, const int rad) win->xwin, ShapeNotifyMask); } -void x_display_surface(cairo_surface_t *srf, window_x11 *win, const struct dimensions *dim) +void x_display_surface(cairo_surface_t *srf, struct window_x11 *win, const struct dimensions *dim) { x_win_move(win, dim->x, dim->y, dim->w, dim->h); cairo_xlib_surface_set_size(win->root_surface, dim->w, dim->h); @@ -164,12 +164,12 @@ void x_display_surface(cairo_surface_t *srf, window_x11 *win, const struct dimen } -bool x_win_visible(window_x11 *win) +bool x_win_visible(struct window_x11 *win) { return win->visible; } -cairo_t* x_win_get_context(window_x11 *win) +cairo_t* x_win_get_context(struct window_x11 *win) { return win->c_ctx; } @@ -266,10 +266,10 @@ gboolean x_mainloop_fd_check(GSource *source) */ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { - window_x11 *win = ((struct x11_source*) source)->win; + struct window_x11 *win = ((struct x11_source*) source)->win; bool fullscreen_now; - screen_info *scr; + struct screen_info *scr; XEvent ev; unsigned int state; while (XPending(xctx.dpy) > 0) { @@ -571,7 +571,7 @@ static void x_set_wm(Window win) PropModeReplace, (unsigned char *) data, 1L); } -GSource* x_win_reg_source(window_x11 *win) +GSource* x_win_reg_source(struct window_x11 *win) { // Static is necessary here because glib keeps the pointer and we need // to keep the reference alive. @@ -599,9 +599,9 @@ GSource* x_win_reg_source(window_x11 *win) /* * Setup the window */ -window_x11 *x_win_create(void) +struct window_x11 *x_win_create(void) { - window_x11 *win = g_malloc0(sizeof(window_x11)); + struct window_x11 *win = g_malloc0(sizeof(struct window_x11)); Window root; XSetWindowAttributes wa; @@ -614,7 +614,7 @@ window_x11 *x_win_create(void) ExposureMask | KeyPressMask | VisibilityChangeMask | ButtonReleaseMask | FocusChangeMask| StructureNotifyMask; - screen_info *scr = get_active_screen(); + struct screen_info *scr = get_active_screen(); win->xwin = XCreateWindow(xctx.dpy, root, scr->x, @@ -651,7 +651,7 @@ window_x11 *x_win_create(void) return win; } -void x_win_destroy(window_x11 *win) +void x_win_destroy(struct window_x11 *win) { g_source_destroy(win->esrc); g_source_unref(win->esrc); @@ -666,7 +666,7 @@ void x_win_destroy(window_x11 *win) /* * Show the window and grab shortcuts. */ -void x_win_show(window_x11 *win) +void x_win_show(struct window_x11 *win) { /* window is already mapped or there's nothing to show */ if (win->visible || queues_length_displayed() == 0) { @@ -699,7 +699,7 @@ void x_win_show(window_x11 *win) /* * Hide the window and ungrab unused keyboard_shortcuts */ -void x_win_hide(window_x11 *win) +void x_win_hide(struct window_x11 *win) { x_shortcut_ungrab(&settings.close_ks); x_shortcut_ungrab(&settings.close_all_ks); @@ -777,7 +777,7 @@ static int x_shortcut_tear_down_error_handler(void) /* * Grab the given keyboard shortcut. */ -static int x_shortcut_grab(keyboard_shortcut *ks) +static int x_shortcut_grab(struct keyboard_shortcut *ks) { if (!ks->is_valid) return 1; @@ -814,7 +814,7 @@ static int x_shortcut_grab(keyboard_shortcut *ks) /* * Ungrab the given keyboard shortcut. */ -static void x_shortcut_ungrab(keyboard_shortcut *ks) +static void x_shortcut_ungrab(struct keyboard_shortcut *ks) { Window root; root = RootWindow(xctx.dpy, DefaultScreen(xctx.dpy)); @@ -827,7 +827,7 @@ static void x_shortcut_ungrab(keyboard_shortcut *ks) /* * Initialize the keyboard shortcut. */ -static void x_shortcut_init(keyboard_shortcut *ks) +static void x_shortcut_init(struct keyboard_shortcut *ks) { if (!ks|| !ks->str) return; diff --git a/src/x11/x.h b/src/x11/x.h index 6974ca1..3a644cf 100644 --- a/src/x11/x.h +++ b/src/x11/x.h @@ -13,18 +13,18 @@ #include "screen.h" -typedef struct _keyboard_shortcut { +struct keyboard_shortcut { const char *str; KeyCode code; KeySym sym; KeySym mask; bool is_valid; -} keyboard_shortcut; +}; // Cyclical dependency #include "src/settings.h" -typedef struct window_x11 window_x11; +struct window_x11; struct dimensions { int x; @@ -35,31 +35,31 @@ struct dimensions { int corner_radius; }; -typedef struct _xctx { +struct x_context { Display *dpy; const char *colors[3][3]; XScreenSaverInfo *screensaver_info; -} xctx_t; +}; -typedef struct _color_t { +struct color { double r; double g; double b; -} color_t; +}; -extern xctx_t xctx; +extern struct x_context xctx; /* window */ -window_x11 *x_win_create(void); -void x_win_destroy(window_x11 *win); +struct window_x11 *x_win_create(void); +void x_win_destroy(struct window_x11 *win); -void x_win_show(window_x11 *win); -void x_win_hide(window_x11 *win); +void x_win_show(struct window_x11 *win); +void x_win_hide(struct window_x11 *win); -void x_display_surface(cairo_surface_t *srf, window_x11 *win, const struct dimensions *dim); +void x_display_surface(cairo_surface_t *srf, struct window_x11 *win, const struct dimensions *dim); -bool x_win_visible(window_x11 *win); -cairo_t* x_win_get_context(window_x11 *win); +bool x_win_visible(struct window_x11 *win); +cairo_t* x_win_get_context(struct window_x11 *win); /* X misc */ bool x_is_idle(void);