make use of stdbool.h

This commit is contained in:
Sascha Kruse 2012-10-20 15:48:16 +02:00
parent bdfa4301d7
commit 3c8d8b00c6
4 changed files with 47 additions and 43 deletions

7
draw.c
View File

@ -34,6 +34,7 @@ DEALINGS IN THE SOFTWARE.
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include <string.h> #include <string.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/X.h> #include <X11/X.h>
@ -45,7 +46,7 @@ DEALINGS IN THE SOFTWARE.
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
void void
drawrect(DC * dc, int x, int y, unsigned int w, unsigned int h, Bool fill, drawrect(DC * dc, int x, int y, unsigned int w, unsigned int h, bool fill,
unsigned long color) unsigned long color)
{ {
XSetForeground(dc->dpy, dc->gc, color); XSetForeground(dc->dpy, dc->gc, color);
@ -71,7 +72,7 @@ void drawtext(DC * dc, const char *text, ColorSet * col)
if (mn < n) if (mn < n)
for (n = MAX(mn - 3, 0); n < mn; buf[n++] = '.') ; for (n = MAX(mn - 3, 0); n < mn; buf[n++] = '.') ;
drawrect(dc, 0, 0, dc->w, dc->h, True, col->BG); drawrect(dc, 0, 0, dc->w, dc->h, true, col->BG);
drawtextn(dc, buf, mn, col); drawtextn(dc, buf, mn, col);
} }
@ -237,7 +238,7 @@ void initfont(DC * dc, const char *fontstr)
void void
setopacity(DC *dc, Window win, unsigned long opacity) setopacity(DC *dc, Window win, unsigned long opacity)
{ {
Atom _NET_WM_WINDOW_OPACITY = XInternAtom(dc->dpy, "_NET_WM_WINDOW_OPACITY", False); Atom _NET_WM_WINDOW_OPACITY = XInternAtom(dc->dpy, "_NET_WM_WINDOW_OPACITY", false);
XChangeProperty(dc->dpy, win, _NET_WM_WINDOW_OPACITY, XA_CARDINAL, 32, PropModeReplace, XChangeProperty(dc->dpy, win, _NET_WM_WINDOW_OPACITY, XA_CARDINAL, 32, PropModeReplace,
(unsigned char *)&opacity, 1L); (unsigned char *)&opacity, 1L);
} }

4
draw.h
View File

@ -37,7 +37,7 @@ DEALINGS IN THE SOFTWARE.
typedef struct { typedef struct {
int x, y, w, h; int x, y, w, h;
Bool invert; bool invert;
Display *dpy; Display *dpy;
GC gc; GC gc;
Pixmap canvas; Pixmap canvas;
@ -59,7 +59,7 @@ typedef struct {
unsigned long BG; unsigned long BG;
} ColorSet; } ColorSet;
void drawrect(DC * dc, int x, int y, unsigned int w, unsigned int h, Bool fill, void drawrect(DC * dc, int x, int y, unsigned int w, unsigned int h, bool fill,
unsigned long color); unsigned long color);
void drawtext(DC * dc, const char *text, ColorSet * col); void drawtext(DC * dc, const char *text, ColorSet * col);
void drawtextn(DC * dc, const char *text, size_t n, ColorSet * col); void drawtextn(DC * dc, const char *text, size_t n, ColorSet * col);

73
dunst.c
View File

@ -7,6 +7,7 @@
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include <string.h> #include <string.h>
#include <fnmatch.h> #include <fnmatch.h>
#include <sys/time.h> #include <sys/time.h>
@ -59,20 +60,20 @@ static Atom utf8;
static DC *dc; static DC *dc;
static Window win; static Window win;
static time_t now; static time_t now;
static int visible = False; static bool visible = false;
static screen_info scr; static screen_info scr;
static dimension_t geometry; static dimension_t geometry;
static XScreenSaverInfo *screensaver_info; static XScreenSaverInfo *screensaver_info;
static int font_h; static int font_h;
static int print_notifications = False; static bool print_notifications = false;
static dimension_t window_dim; static dimension_t window_dim;
int dunst_grab_errored = False; bool dunst_grab_errored = false;
int next_notification_id = 1; int next_notification_id = 1;
int deprecated_mod = False; bool deprecated_mod = false;
int deprecated_dunstrc_shortcuts = False; bool deprecated_dunstrc_shortcuts = false;
/* notification lists */ /* notification lists */
list *notification_queue = NULL; /* all new notifications get into here */ list *notification_queue = NULL; /* all new notifications get into here */
@ -88,7 +89,7 @@ void handle_mouse_click(XEvent ev);
void handleXEvents(void); void handleXEvents(void);
void history_pop(void); void history_pop(void);
rule_t *initrule(void); rule_t *initrule(void);
int is_idle(void); bool is_idle(void);
void run(void); void run(void);
void setup(void); void setup(void);
void update_screen_info(); void update_screen_info();
@ -121,7 +122,7 @@ static void print_notification(notification *n)
static int GrabXErrorHandler(Display * display, XErrorEvent * e) static int GrabXErrorHandler(Display * display, XErrorEvent * e)
{ {
dunst_grab_errored = True; dunst_grab_errored = true;
char err_buf[BUFSIZ]; char err_buf[BUFSIZ];
XGetErrorText(display, e->error_code, err_buf, BUFSIZ); XGetErrorText(display, e->error_code, err_buf, BUFSIZ);
fputs(err_buf, stderr); fputs(err_buf, stderr);
@ -136,7 +137,7 @@ static int GrabXErrorHandler(Display * display, XErrorEvent * e)
static void setup_error_handler(void) static void setup_error_handler(void)
{ {
dunst_grab_errored = False; dunst_grab_errored = false;
XFlush(dc->dpy); XFlush(dc->dpy);
XSetErrorHandler(GrabXErrorHandler); XSetErrorHandler(GrabXErrorHandler);
@ -145,7 +146,7 @@ static void setup_error_handler(void)
static int tear_down_error_handler(void) static int tear_down_error_handler(void)
{ {
XFlush(dc->dpy); XFlush(dc->dpy);
XSync(dc->dpy, False); XSync(dc->dpy, false);
XSetErrorHandler(NULL); XSetErrorHandler(NULL);
return dunst_grab_errored; return dunst_grab_errored;
} }
@ -161,11 +162,11 @@ int grab_key(keyboard_shortcut * ks)
if (ks->is_valid) if (ks->is_valid)
XGrabKey(dc->dpy, ks->code, ks->mask, root, XGrabKey(dc->dpy, ks->code, ks->mask, root,
True, GrabModeAsync, GrabModeAsync); true, GrabModeAsync, GrabModeAsync);
if (tear_down_error_handler()) { if (tear_down_error_handler()) {
fprintf(stderr, "Unable to grab key \"%s\"\n", ks->str); fprintf(stderr, "Unable to grab key \"%s\"\n", ks->str);
ks->is_valid = False; ks->is_valid = false;
return 1; return 1;
} }
return 0; return 0;
@ -371,7 +372,7 @@ int do_word_wrap(char *source, int max_width)
char *eol = source; char *eol = source;
while (True) { while (true) {
if (*eol == '\0') if (*eol == '\0')
return 1; return 1;
if (*eol == '\n') { if (*eol == '\n') {
@ -656,7 +657,7 @@ void draw_win(void)
char *line = draw_txt_get_line(&n->draw_txt_buf, i + 1); char *line = draw_txt_get_line(&n->draw_txt_buf, i + 1);
dc->x = 0; dc->x = 0;
drawrect(dc, 0, 0, width, line_height, True, drawrect(dc, 0, 0, width, line_height, true,
n->colors->BG); n->colors->BG);
dc->x = calculate_x_offset(width, textw(dc, line)); dc->x = calculate_x_offset(width, textw(dc, line));
@ -674,7 +675,7 @@ void draw_win(void)
else else
color = n->colors->FG; color = n->colors->FG;
drawrect(dc, 0, 0, width, separator_height, True, color); drawrect(dc, 0, 0, width, separator_height, true, color);
dc->y += separator_height; dc->y += separator_height;
} }
} }
@ -682,7 +683,7 @@ void draw_win(void)
/* draw x_more */ /* draw x_more */
if (x_more.txt) { if (x_more.txt) {
dc->x = 0; dc->x = 0;
drawrect(dc, 0, 0, width, line_height, True, last_color->BG); drawrect(dc, 0, 0, width, line_height, true, last_color->BG);
dc->x = calculate_x_offset(width, textw(dc, x_more.txt)); dc->x = calculate_x_offset(width, textw(dc, x_more.txt));
drawtext(dc, x_more.txt, last_color); drawtext(dc, x_more.txt, last_color);
} }
@ -870,7 +871,7 @@ void history_pop(void)
for (iter = notification_history->head; iter->next; iter = iter->next) ; for (iter = notification_history->head; iter->next; iter = iter->next) ;
data = (notification *) iter->data; data = (notification *) iter->data;
data->redisplayed = True; data->redisplayed = true;
data->start = 0; data->start = 0;
if (sticky_history) { if (sticky_history) {
data->timeout = 0; data->timeout = 0;
@ -968,7 +969,7 @@ int init_notification(notification * n, int id)
n->timestamp = now; n->timestamp = now;
n->redisplayed = False; n->redisplayed = false;
if (id == 0) { if (id == 0) {
n->id = ++next_notification_id; n->id = ++next_notification_id;
@ -1063,7 +1064,7 @@ void init_shortcut(keyboard_shortcut * ks)
return; return;
if (!strcmp(ks->str, "none") || (!strcmp(ks->str, ""))) { if (!strcmp(ks->str, "none") || (!strcmp(ks->str, ""))) {
ks->is_valid = False; ks->is_valid = false;
return; return;
} }
@ -1103,9 +1104,9 @@ void init_shortcut(keyboard_shortcut * ks)
if (ks->sym == NoSymbol || ks->code == NoSymbol) { if (ks->sym == NoSymbol || ks->code == NoSymbol) {
fprintf(stderr, "Warning: Unknown keyboard shortcut: %s\n", fprintf(stderr, "Warning: Unknown keyboard shortcut: %s\n",
ks->str); ks->str);
ks->is_valid = False; ks->is_valid = false;
} else { } else {
ks->is_valid = True; ks->is_valid = true;
} }
free(str_begin); free(str_begin);
@ -1128,19 +1129,19 @@ rule_t *initrule(void)
return r; return r;
} }
int is_idle(void) bool is_idle(void)
{ {
XScreenSaverQueryInfo(dc->dpy, DefaultRootWindow(dc->dpy), XScreenSaverQueryInfo(dc->dpy, DefaultRootWindow(dc->dpy),
screensaver_info); screensaver_info);
if (idle_threshold == 0) { if (idle_threshold == 0) {
return False; return false;
} }
return screensaver_info->idle / 1000 > idle_threshold; return screensaver_info->idle / 1000 > idle_threshold;
} }
void run(void) void run(void)
{ {
while (True) { while (true) {
if (visible) { if (visible) {
dbus_poll(50); dbus_poll(50);
} else { } else {
@ -1173,7 +1174,7 @@ void hide_win()
XUngrabButton(dc->dpy, AnyButton, AnyModifier, win); XUngrabButton(dc->dpy, AnyButton, AnyModifier, win);
XUnmapWindow(dc->dpy, win); XUnmapWindow(dc->dpy, win);
XFlush(dc->dpy); XFlush(dc->dpy);
visible = False; visible = false;
} }
Window get_focused_window(void) Window get_focused_window(void)
@ -1185,10 +1186,10 @@ Window get_focused_window(void)
unsigned char *prop_return = NULL; unsigned char *prop_return = NULL;
Window root = RootWindow(dc->dpy, DefaultScreen(dc->dpy)); Window root = RootWindow(dc->dpy, DefaultScreen(dc->dpy));
Atom netactivewindow = Atom netactivewindow =
XInternAtom(dc->dpy, "_NET_ACTIVE_WINDOW", False); XInternAtom(dc->dpy, "_NET_ACTIVE_WINDOW", false);
XGetWindowProperty(dc->dpy, root, netactivewindow, 0L, XGetWindowProperty(dc->dpy, root, netactivewindow, 0L,
sizeof(Window), False, XA_WINDOW, sizeof(Window), false, XA_WINDOW,
&type, &format, &nitems, &bytes_after, &prop_return); &type, &format, &nitems, &bytes_after, &prop_return);
if (prop_return) { if (prop_return) {
focused = *(Window *) prop_return; focused = *(Window *) prop_return;
@ -1286,7 +1287,7 @@ void setup(void)
} }
root = RootWindow(dc->dpy, DefaultScreen(dc->dpy)); root = RootWindow(dc->dpy, DefaultScreen(dc->dpy));
utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False); utf8 = XInternAtom(dc->dpy, "UTF8_STRING", false);
/* menu geometry */ /* menu geometry */
font_h = dc->font.height + FONT_HEIGHT_BORDER; font_h = dc->font.height + FONT_HEIGHT_BORDER;
@ -1294,7 +1295,7 @@ void setup(void)
update_screen_info(); update_screen_info();
/* menu window */ /* menu window */
wa.override_redirect = True; wa.override_redirect = true;
wa.background_pixmap = ParentRelative; wa.background_pixmap = ParentRelative;
wa.event_mask = wa.event_mask =
ExposureMask | KeyPressMask | VisibilityChangeMask | ExposureMask | KeyPressMask | VisibilityChangeMask |
@ -1321,7 +1322,7 @@ void map_win(void)
grab_key(&close_ks); grab_key(&close_ks);
grab_key(&close_all_ks); grab_key(&close_all_ks);
setup_error_handler(); setup_error_handler();
XGrabButton(dc->dpy, AnyButton, AnyModifier, win, False, XGrabButton(dc->dpy, AnyButton, AnyModifier, win, false,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
if (tear_down_error_handler()) { if (tear_down_error_handler()) {
fprintf(stderr, "Unable to grab mouse button(s)\n"); fprintf(stderr, "Unable to grab mouse button(s)\n");
@ -1331,7 +1332,7 @@ void map_win(void)
XMapRaised(dc->dpy, win); XMapRaised(dc->dpy, win);
draw_win(); draw_win();
XFlush(dc->dpy); XFlush(dc->dpy);
visible = True; visible = true;
} }
void parse_follow_mode(const char *mode) void parse_follow_mode(const char *mode)
@ -1418,7 +1419,7 @@ void load_options(char *cmdline_config_path)
{ {
char *c = option_get_string("global", "modifier", NULL, "", ""); char *c = option_get_string("global", "modifier", NULL, "", "");
if (strlen(c) > 0) { if (strlen(c) > 0) {
deprecated_dunstrc_shortcuts = True; deprecated_dunstrc_shortcuts = true;
KeySym mod = string_to_mask(c); KeySym mod = string_to_mask(c);
close_ks.mask = mod; close_ks.mask = mod;
close_all_ks.mask = mod; close_all_ks.mask = mod;
@ -1475,7 +1476,7 @@ void load_options(char *cmdline_config_path)
close_all_ks.str = option_get_string("shortcuts", "close_all", "-all_key", close_all_ks.str, "Shortcut for closing all notifications"); close_all_ks.str = option_get_string("shortcuts", "close_all", "-all_key", close_all_ks.str, "Shortcut for closing all notifications");
history_ks.str = option_get_string("shortcuts", "history", "-history_key", history_ks.str, "Shortcut to pop the last notification from history"); history_ks.str = option_get_string("shortcuts", "history", "-history_key", history_ks.str, "Shortcut to pop the last notification from history");
print_notifications = cmdline_get_bool("-print", False, "Print notifications to cmdline (DEBUG)"); print_notifications = cmdline_get_bool("-print", false, "Print notifications to cmdline (DEBUG)");
char *cur_section = NULL; char *cur_section = NULL;
for (;;) { for (;;) {
@ -1544,7 +1545,7 @@ int main(int argc, char *argv[])
cmdline_load(argc, argv); cmdline_load(argc, argv);
if (cmdline_get_bool("-v/-version", False, "Print version") || cmdline_get_bool("--version", False, "Print version")) { if (cmdline_get_bool("-v/-version", false, "Print version") || cmdline_get_bool("--version", false, "Print version")) {
print_version(); print_version();
} }
@ -1552,7 +1553,7 @@ int main(int argc, char *argv[])
cmdline_config_path = cmdline_get_string("-conf/-config", NULL, "Path to configuration file"); cmdline_config_path = cmdline_get_string("-conf/-config", NULL, "Path to configuration file");
load_options(cmdline_config_path); load_options(cmdline_config_path);
if (cmdline_get_bool("-h/-help", False, "Print help") || cmdline_get_bool("--help", False, "Print help")) { if (cmdline_get_bool("-h/-help", false, "Print help") || cmdline_get_bool("--help", false, "Print help")) {
usage(EXIT_SUCCESS); usage(EXIT_SUCCESS);
} }
@ -1564,10 +1565,10 @@ int main(int argc, char *argv[])
if (geom[0] == '-') { if (geom[0] == '-') {
geometry.negative_width = True; geometry.negative_width = true;
geom++; geom++;
} else { } else {
geometry.negative_width = False; geometry.negative_width = false;
} }
geometry.mask = XParseGeometry(geom, geometry.mask = XParseGeometry(geom,

View File

@ -2,6 +2,8 @@
#pragma once #pragma once
#include <stdbool.h>
#include "draw.h" #include "draw.h"
#define LOW 0 #define LOW 0
@ -49,7 +51,7 @@ typedef struct _notification {
time_t timestamp; time_t timestamp;
int timeout; int timeout;
int urgency; int urgency;
int redisplayed; /* has been displayed before? */ bool redisplayed; /* has been displayed before? */
int id; int id;
int dup_count; int dup_count;
ColorSet *colors; ColorSet *colors;
@ -84,7 +86,7 @@ typedef struct _keyboard_shortcut {
KeyCode code; KeyCode code;
KeySym sym; KeySym sym;
KeySym mask; KeySym mask;
int is_valid; bool is_valid;
} keyboard_shortcut; } keyboard_shortcut;
extern int verbosity; extern int verbosity;