remove folding markers again
This commit is contained in:
parent
0a04bceb6f
commit
b8004f56d8
49
dunst.c
49
dunst.c
@ -1,6 +1,5 @@
|
||||
/* copyright 2012 Sascha Kruse and contributors (see LICENSE for licensing information) */
|
||||
|
||||
// {{{ INCLUDES
|
||||
#define _GNU_SOURCE
|
||||
#define XLIB_ILLEGAL_ACCESS
|
||||
|
||||
@ -38,9 +37,7 @@
|
||||
#include "option_parser.h"
|
||||
#include "settings.h"
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ DEFINES
|
||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||
|
||||
#ifndef VERSION
|
||||
@ -50,19 +47,15 @@
|
||||
#define MSG 1
|
||||
#define INFO 2
|
||||
#define DEBUG 3
|
||||
//}}}
|
||||
|
||||
// {{{ STRUCTS
|
||||
typedef struct _x11_source {
|
||||
GSource source;
|
||||
Display *dpy;
|
||||
Window w;
|
||||
} x11_source_t;
|
||||
|
||||
// }}}
|
||||
|
||||
|
||||
// {{{ GLOBALS
|
||||
|
||||
/* index of colors fit to urgency level */
|
||||
bool pause_display = false;
|
||||
@ -78,15 +71,12 @@ GQueue *queue = NULL; /* all new notifications get into here */
|
||||
GQueue *displayed = NULL; /* currently displayed notifications */
|
||||
GQueue *history = NULL; /* history of displayed notifications */
|
||||
GSList *rules = NULL;
|
||||
// }}}
|
||||
|
||||
// {{{ FUNCTION DEFINITIONS
|
||||
|
||||
|
||||
|
||||
/* misc funtions */
|
||||
|
||||
// }}}
|
||||
|
||||
|
||||
|
||||
@ -99,9 +89,8 @@ GSList *rules = NULL;
|
||||
|
||||
|
||||
|
||||
// {{{ RUN
|
||||
void check_timeouts(void)
|
||||
{ // {{{
|
||||
{
|
||||
/* nothing to do */
|
||||
if (displayed->length == 0)
|
||||
return;
|
||||
@ -130,10 +119,9 @@ void check_timeouts(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
void update_lists()
|
||||
{ // {{{
|
||||
{
|
||||
int limit;
|
||||
|
||||
check_timeouts();
|
||||
@ -178,11 +166,10 @@ void update_lists()
|
||||
g_queue_insert_sorted(displayed, n, notification_cmp_data, NULL);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
void move_all_to_history()
|
||||
{ // {{{
|
||||
{
|
||||
while (displayed->length > 0) {
|
||||
notification_close(g_queue_peek_head_link(displayed)->data, 2);
|
||||
}
|
||||
@ -193,10 +180,9 @@ void move_all_to_history()
|
||||
n = g_queue_pop_head(queue);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
void history_pop(void)
|
||||
{ // {{{
|
||||
{
|
||||
|
||||
if (g_queue_is_empty(history))
|
||||
return;
|
||||
@ -211,10 +197,9 @@ void history_pop(void)
|
||||
wake_up();
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
void update(void)
|
||||
{ // {{{
|
||||
{
|
||||
time_t last_time = time(&last_time);
|
||||
static time_t last_redraw = 0;
|
||||
|
||||
@ -233,10 +218,9 @@ void update(void)
|
||||
last_redraw = time(NULL);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
void wake_up(void)
|
||||
{ // {{{
|
||||
{
|
||||
force_redraw = true;
|
||||
update();
|
||||
if (!timer_active) {
|
||||
@ -244,10 +228,9 @@ void wake_up(void)
|
||||
g_timeout_add(1000, run, mainloop);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
gboolean run(void *data)
|
||||
{ // {{{
|
||||
{
|
||||
|
||||
update();
|
||||
|
||||
@ -264,16 +247,13 @@ gboolean run(void *data)
|
||||
|
||||
return true;
|
||||
}
|
||||
// }}}
|
||||
|
||||
//}}}
|
||||
|
||||
|
||||
|
||||
|
||||
// {{{ MAIN
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{ // {{{
|
||||
{
|
||||
|
||||
history = g_queue_new();
|
||||
displayed = g_queue_new();
|
||||
@ -351,10 +331,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
|
||||
void pause_signal_handler(int sig)
|
||||
{ // {{{
|
||||
{
|
||||
if (sig == SIGUSR1) {
|
||||
pause_display = true;
|
||||
}
|
||||
@ -364,25 +343,21 @@ void pause_signal_handler(int sig)
|
||||
|
||||
signal (sig, pause_signal_handler);
|
||||
}
|
||||
// }}}
|
||||
|
||||
void usage(int exit_status)
|
||||
{ // {{{
|
||||
{
|
||||
fputs("usage:\n", stderr);
|
||||
char *us = cmdline_create_usage();
|
||||
fputs(us, stderr);
|
||||
fputs("\n", stderr);
|
||||
exit(exit_status);
|
||||
}
|
||||
// }}}
|
||||
|
||||
void print_version(void)
|
||||
{ // {{{
|
||||
{
|
||||
printf("Dunst - A customizable and lightweight notification-daemon %s\n",
|
||||
VERSION);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
// }}}
|
||||
// }}}
|
||||
|
||||
/* vim: set ts=8 sw=8 tw=0: */
|
||||
|
19
menu.c
19
menu.c
@ -1,4 +1,3 @@
|
||||
/// {{{ INCLUDES
|
||||
#define _GNU_SOURCE
|
||||
#include <stdbool.h>
|
||||
#include <regex.h>
|
||||
@ -12,9 +11,7 @@
|
||||
#include "utils.h"
|
||||
#include "settings.h"
|
||||
#include "dbus.h"
|
||||
// }}}
|
||||
|
||||
// {{{ CONTEXT_MENU
|
||||
|
||||
/*
|
||||
* Exctract all urls from a given string.
|
||||
@ -23,7 +20,7 @@
|
||||
*
|
||||
*/
|
||||
char *extract_urls( const char * to_match)
|
||||
{ // {{{
|
||||
{
|
||||
static bool is_initialized = false;
|
||||
static regex_t cregex;
|
||||
|
||||
@ -65,7 +62,6 @@ char *extract_urls( const char * to_match)
|
||||
return urls;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
|
||||
/*
|
||||
@ -73,7 +69,7 @@ char *extract_urls( const char * to_match)
|
||||
*
|
||||
*/
|
||||
void open_browser(const char *url)
|
||||
{ // {{{
|
||||
{
|
||||
int browser_pid1 = fork();
|
||||
|
||||
if (browser_pid1) {
|
||||
@ -90,7 +86,6 @@ if (browser_pid1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
/*
|
||||
@ -98,7 +93,7 @@ if (browser_pid1) {
|
||||
* that an action has been invoked
|
||||
*/
|
||||
void invoke_action(const char *action)
|
||||
{ // {{{
|
||||
{
|
||||
notification *invoked = NULL;
|
||||
char *action_identifier = NULL;
|
||||
|
||||
@ -132,14 +127,13 @@ void invoke_action(const char *action)
|
||||
actionInvoked(invoked, action_identifier);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Dispatch whatever has been returned
|
||||
* by the menu.
|
||||
*/
|
||||
void dispatch_menu_result(const char *input)
|
||||
{ // {{{
|
||||
{
|
||||
char *maybe_url = extract_urls(input);
|
||||
if (maybe_url) {
|
||||
open_browser(maybe_url);
|
||||
@ -149,14 +143,13 @@ void dispatch_menu_result(const char *input)
|
||||
|
||||
invoke_action(input);
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Open the context menu that let's the user
|
||||
* select urls/actions/etc
|
||||
*/
|
||||
void context_menu(void)
|
||||
{ // {{{
|
||||
{
|
||||
char *dmenu_input = NULL;
|
||||
|
||||
for (GList *iter = g_queue_peek_head_link(displayed); iter; iter = iter->next) {
|
||||
@ -220,7 +213,5 @@ void context_menu(void)
|
||||
|
||||
dispatch_menu_result(buf);
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
// }}}
|
||||
|
2
menu.h
2
menu.h
@ -1,7 +1,5 @@
|
||||
// {{{ INCLUDES
|
||||
#include "dunst.h"
|
||||
#include <regex.h>
|
||||
// }}}
|
||||
|
||||
char *extract_urls(const char *to_match);
|
||||
void open_browser(const char *url);
|
||||
|
@ -23,14 +23,13 @@ int next_notification_id = 1;
|
||||
|
||||
|
||||
|
||||
// {{{ NOTIFICATION
|
||||
|
||||
/*
|
||||
* print a human readable representation
|
||||
* of the given notification to stdout.
|
||||
*/
|
||||
void notification_print(notification * n)
|
||||
{ // {{{
|
||||
{
|
||||
printf("{\n");
|
||||
printf("\tappname: '%s'\n", n->appname);
|
||||
printf("\tsummary: '%s'\n", n->summary);
|
||||
@ -58,14 +57,13 @@ void notification_print(notification * n)
|
||||
printf("\tscript: %s\n", n->script);
|
||||
printf("}\n");
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Run the script associated with the
|
||||
* given notification.
|
||||
*/
|
||||
void notification_run_script(notification *n)
|
||||
{ // {{{
|
||||
{
|
||||
if (!n->script || strlen(n->script) < 1)
|
||||
return;
|
||||
|
||||
@ -115,14 +113,13 @@ void notification_run_script(notification *n)
|
||||
}
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Helper function to compare to given
|
||||
* notifications.
|
||||
*/
|
||||
int notification_cmp(const void *va, const void *vb)
|
||||
{ // {{{
|
||||
{
|
||||
notification *a = (notification*) va;
|
||||
notification *b = (notification*) vb;
|
||||
|
||||
@ -135,24 +132,22 @@ int notification_cmp(const void *va, const void *vb)
|
||||
return a->timestamp - b->timestamp;
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Wrapper for notification_cmp to match glib's
|
||||
* compare functions signature.
|
||||
*/
|
||||
int notification_cmp_data(const void *va, const void *vb, void *data)
|
||||
{ // {{{
|
||||
{
|
||||
return notification_cmp(va, vb);
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
/*
|
||||
* Free the memory used by the given notification.
|
||||
*/
|
||||
void notification_free(notification * n)
|
||||
{ // {{{
|
||||
{
|
||||
if (n == NULL)
|
||||
return;
|
||||
free(n->appname);
|
||||
@ -163,14 +158,13 @@ void notification_free(notification * n)
|
||||
free(n->dbus_client);
|
||||
free(n);
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Strip any markup from text
|
||||
*/
|
||||
|
||||
char *notification_fix_markup(char *str)
|
||||
{ // {{{
|
||||
{
|
||||
char *replace_buf, *start, *end;
|
||||
|
||||
if (str == NULL) {
|
||||
@ -216,14 +210,13 @@ char *notification_fix_markup(char *str)
|
||||
return str;
|
||||
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Initialize the given notification and add it to
|
||||
* the queue. Replace notification with id if id > 0.
|
||||
*/
|
||||
int notification_init(notification * n, int id)
|
||||
{ // {{{
|
||||
{
|
||||
const char *fg = NULL;
|
||||
const char *bg = NULL;
|
||||
|
||||
@ -366,7 +359,6 @@ int notification_init(notification * n, int id)
|
||||
|
||||
return n->id;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Close the notification that has id.
|
||||
@ -378,7 +370,7 @@ int notification_init(notification * n, int id)
|
||||
* 3 -> The notification was closed by a call to CloseNotification
|
||||
*/
|
||||
int notification_close_by_id(int id, int reason)
|
||||
{ // {{{
|
||||
{
|
||||
notification *target = NULL;
|
||||
|
||||
for (GList *iter = g_queue_peek_head_link(displayed); iter; iter = iter->next) {
|
||||
@ -408,17 +400,14 @@ int notification_close_by_id(int id, int reason)
|
||||
wake_up();
|
||||
return reason;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Close the given notification. SEE notification_close_by_id.
|
||||
*/
|
||||
int notification_close(notification * n, int reason)
|
||||
{ // {{{
|
||||
{
|
||||
if (n == NULL)
|
||||
return -1;
|
||||
return notification_close_by_id(n->id, reason);
|
||||
}
|
||||
// }}}
|
||||
|
||||
// }}}
|
||||
|
2
rules.c
2
rules.c
@ -1,10 +1,8 @@
|
||||
// {{{ INVLUDES
|
||||
#include <glib.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include "dunst.h"
|
||||
#include "rules.h"
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Apply rule to notification.
|
||||
|
8
rules.h
8
rules.h
@ -1,13 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
// {{{ INCLUDES
|
||||
#include <glib.h>
|
||||
|
||||
#include "dunst.h"
|
||||
#include "notification.h"
|
||||
// }}}
|
||||
|
||||
// {{{ STRUCTS
|
||||
typedef struct _rule_t {
|
||||
char *name;
|
||||
/* filters */
|
||||
@ -24,15 +21,10 @@ typedef struct _rule_t {
|
||||
const char *format;
|
||||
const char *script;
|
||||
} rule_t;
|
||||
// }}}
|
||||
|
||||
// {{{ GLOBALS
|
||||
extern GSList *rules;
|
||||
// }}}
|
||||
|
||||
// {{{ FUNCTIONS
|
||||
void rule_init(rule_t *r);
|
||||
void rule_apply(rule_t *r, notification *n);
|
||||
void rule_apply_all(notification *n);
|
||||
bool rule_matches_notification(rule_t *r, notification *n);
|
||||
// }}}
|
||||
|
@ -1,4 +1,3 @@
|
||||
// {{{ INCLUDES
|
||||
|
||||
#include <glib.h>
|
||||
#include <basedir.h>
|
||||
@ -9,7 +8,6 @@
|
||||
#include "option_parser.h"
|
||||
#include "settings.h"
|
||||
#include "config.h"
|
||||
// }}}
|
||||
|
||||
settings_t settings;
|
||||
|
||||
|
95
x.c
95
x.c
@ -301,19 +301,16 @@ int textw(DC * dc, const char *text)
|
||||
return textnw(dc, text, strlen(text)) + dc->font.height;
|
||||
}
|
||||
|
||||
// {{{ X
|
||||
// {{{ X_MAINLOOP
|
||||
|
||||
/*
|
||||
* Helper function to use glib's mainloop mechanic
|
||||
* with Xlib
|
||||
*/
|
||||
gboolean x_mainloop_fd_prepare(GSource *source, gint *timeout)
|
||||
{ // {{{
|
||||
{
|
||||
*timeout = -1;
|
||||
return false;
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
/*
|
||||
@ -321,17 +318,16 @@ gboolean x_mainloop_fd_prepare(GSource *source, gint *timeout)
|
||||
* with Xlib
|
||||
*/
|
||||
gboolean x_mainloop_fd_check(GSource *source)
|
||||
{ // {{{
|
||||
{
|
||||
return XPending(xctx.dc->dpy) > 0;
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
/*
|
||||
* Main Dispatcher for XEvents
|
||||
*/
|
||||
gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
|
||||
{ // {{{
|
||||
{
|
||||
XEvent ev;
|
||||
while (XPending(xctx.dc->dpy) > 0) {
|
||||
XNextEvent(xctx.dc->dpy, &ev);
|
||||
@ -380,17 +376,14 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ X_MISC
|
||||
|
||||
/*
|
||||
* Check whether the user is currently idle.
|
||||
*/
|
||||
bool x_is_idle(void)
|
||||
{ // {{{
|
||||
{
|
||||
XScreenSaverQueryInfo(xctx.dc->dpy, DefaultRootWindow(xctx.dc->dpy),
|
||||
xctx.screensaver_info);
|
||||
if (settings.idle_threshold == 0) {
|
||||
@ -398,14 +391,13 @@ bool x_is_idle(void)
|
||||
}
|
||||
return xctx.screensaver_info->idle / 1000 > settings.idle_threshold;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/* TODO move to x_mainloop_* */
|
||||
/*
|
||||
* Handle incoming mouse click events
|
||||
*/
|
||||
void x_handle_click(XEvent ev)
|
||||
{ // {{{
|
||||
{
|
||||
if (ev.xbutton.button == Button3) {
|
||||
move_all_to_history();
|
||||
|
||||
@ -431,7 +423,6 @@ void x_handle_click(XEvent ev)
|
||||
notification_close(n, 2);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
|
||||
@ -440,7 +431,7 @@ void x_handle_click(XEvent ev)
|
||||
* the keyboard focus.
|
||||
*/
|
||||
Window get_focused_window(void)
|
||||
{ // {{{
|
||||
{
|
||||
Window focused = 0;
|
||||
Atom type;
|
||||
int format;
|
||||
@ -460,7 +451,6 @@ Window get_focused_window(void)
|
||||
|
||||
return focused;
|
||||
}
|
||||
// }}}
|
||||
|
||||
#ifdef XINERAMA
|
||||
/*
|
||||
@ -468,7 +458,7 @@ Window get_focused_window(void)
|
||||
* should be displayed.
|
||||
*/
|
||||
int select_screen(XineramaScreenInfo * info, int info_len)
|
||||
{ // {{{
|
||||
{
|
||||
if (settings.f_mode == FOLLOW_NONE) {
|
||||
return settings.monitor >= 0 ? settings.monitor : XDefaultScreen(xctx.dc->dpy);
|
||||
|
||||
@ -513,7 +503,6 @@ int select_screen(XineramaScreenInfo * info, int info_len)
|
||||
return settings.monitor >= 0 ? settings.monitor : XDefaultScreen(xctx.dc->dpy);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -521,7 +510,7 @@ int select_screen(XineramaScreenInfo * info, int info_len)
|
||||
* geometry.
|
||||
*/
|
||||
void x_screen_info(screen_info *scr)
|
||||
{ // {{{
|
||||
{
|
||||
#ifdef XINERAMA
|
||||
int n;
|
||||
XineramaScreenInfo *info;
|
||||
@ -552,14 +541,13 @@ void x_screen_info(screen_info *scr)
|
||||
scr->dim.h = DisplayHeight(xctx.dc->dpy, screen);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
/*
|
||||
* Setup X11 stuff
|
||||
*/
|
||||
void x_setup(void)
|
||||
{ // {{{
|
||||
{
|
||||
|
||||
/* initialize xctx.dc, font, keyboard, colors */
|
||||
xctx.dc = initdc();
|
||||
@ -615,16 +603,13 @@ void x_setup(void)
|
||||
x_win_setup();
|
||||
x_shortcut_grab(&settings.history_ks);
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
// }}}
|
||||
|
||||
/* TODO comments and naming */
|
||||
// {{{ X_RENDER
|
||||
|
||||
GSList *do_word_wrap(char *text, int max_width)
|
||||
{ // {{{
|
||||
{
|
||||
|
||||
GSList *result = NULL;
|
||||
g_strstrip(text);
|
||||
@ -663,11 +648,10 @@ GSList *do_word_wrap(char *text, int max_width)
|
||||
|
||||
return result;
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
char *generate_final_text(notification *n)
|
||||
{ // {{{
|
||||
{
|
||||
char *msg = g_strstrip(n->msg);
|
||||
char *buf;
|
||||
|
||||
@ -713,10 +697,9 @@ char *generate_final_text(notification *n)
|
||||
|
||||
return buf;
|
||||
}
|
||||
// }}}
|
||||
|
||||
int calculate_x_offset(int line_width, int text_width)
|
||||
{ // {{{
|
||||
{
|
||||
int leftover = line_width - text_width;
|
||||
struct timeval t;
|
||||
float pos;
|
||||
@ -739,10 +722,9 @@ int calculate_x_offset(int line_width, int text_width)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
unsigned long calculate_foreground_color(unsigned long source_color)
|
||||
{ // {{{
|
||||
{
|
||||
Colormap cmap = DefaultColormap(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
||||
XColor color;
|
||||
|
||||
@ -786,10 +768,9 @@ unsigned long calculate_foreground_color(unsigned long source_color)
|
||||
XAllocColor(xctx.dc->dpy, cmap, &color);
|
||||
return color.pixel;
|
||||
}
|
||||
// }}}
|
||||
|
||||
int calculate_width(void)
|
||||
{ // {{{
|
||||
{
|
||||
screen_info scr;
|
||||
x_screen_info(&scr);
|
||||
if (xctx.geometry.mask & WidthValue && xctx.geometry.w == 0) {
|
||||
@ -807,10 +788,9 @@ int calculate_width(void)
|
||||
return scr.dim.w;
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
void move_and_map(int width, int height)
|
||||
{ // {{{
|
||||
{
|
||||
|
||||
int x,y;
|
||||
screen_info scr;
|
||||
@ -844,10 +824,9 @@ void move_and_map(int width, int height)
|
||||
mapdc(xctx.dc, xctx.win, width, height);
|
||||
|
||||
}
|
||||
// }}}
|
||||
|
||||
GSList *generate_render_texts(int width)
|
||||
{ // {{{
|
||||
{
|
||||
GSList *render_texts = NULL;
|
||||
|
||||
for (GList *iter = g_queue_peek_head_link(displayed); iter; iter = iter->next) {
|
||||
@ -879,7 +858,6 @@ GSList *generate_render_texts(int width)
|
||||
|
||||
return render_texts;
|
||||
}
|
||||
// }}}
|
||||
|
||||
void free_render_text(void *data) {
|
||||
g_slist_free_full(((render_text *) data)->lines, g_free);
|
||||
@ -890,13 +868,11 @@ void free_render_texts(GSList *texts) {
|
||||
}
|
||||
|
||||
|
||||
// }}}
|
||||
|
||||
|
||||
// {{{ X_WIN
|
||||
|
||||
void x_win_draw(void)
|
||||
{ // {{{
|
||||
{
|
||||
|
||||
int outer_width = calculate_width();
|
||||
screen_info scr;
|
||||
@ -1014,13 +990,12 @@ void x_win_draw(void)
|
||||
|
||||
free_render_texts(texts);
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Setup the window
|
||||
*/
|
||||
void x_win_setup(void)
|
||||
{ // {{{
|
||||
{
|
||||
|
||||
Window root;
|
||||
XSetWindowAttributes wa;
|
||||
@ -1053,13 +1028,12 @@ void x_win_setup(void)
|
||||
setopacity(xctx.dc, xctx.win,
|
||||
(unsigned long)((100 - settings.transparency) * (0xffffffff / 100)));
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Show the window and grab shortcuts.
|
||||
*/
|
||||
void x_win_show(void)
|
||||
{ // {{{
|
||||
{
|
||||
/* window is already mapped or there's nothing to show */
|
||||
if (xctx.visible || g_queue_is_empty(displayed)) {
|
||||
return;
|
||||
@ -1079,13 +1053,12 @@ void x_win_show(void)
|
||||
XMapRaised(xctx.dc->dpy, xctx.win);
|
||||
xctx.visible = true;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Hide the window and ungrab unused keyboard_shortcuts
|
||||
*/
|
||||
void x_win_hide()
|
||||
{ // {{{
|
||||
{
|
||||
x_shortcut_ungrab(&settings.close_ks);
|
||||
x_shortcut_ungrab(&settings.close_all_ks);
|
||||
x_shortcut_ungrab(&settings.context_ks);
|
||||
@ -1095,18 +1068,15 @@ void x_win_hide()
|
||||
XFlush(xctx.dc->dpy);
|
||||
xctx.visible = false;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// }}}
|
||||
|
||||
|
||||
// {{{ X_SHORTCUT
|
||||
|
||||
|
||||
/*
|
||||
* Parse a string into a modifier mask.
|
||||
*/
|
||||
KeySym x_shortcut_string_to_mask(const char *str)
|
||||
{ // {{{
|
||||
{
|
||||
if (!strcmp(str, "ctrl")) {
|
||||
return ControlMask;
|
||||
} else if (!strcmp(str, "mod4")) {
|
||||
@ -1125,13 +1095,12 @@ KeySym x_shortcut_string_to_mask(const char *str)
|
||||
}
|
||||
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Error handler for grabbing mouse and keyboard errors.
|
||||
*/
|
||||
static int GrabXErrorHandler(Display * display, XErrorEvent * e)
|
||||
{ // {{{
|
||||
{
|
||||
dunst_grab_errored = true;
|
||||
char err_buf[BUFSIZ];
|
||||
XGetErrorText(display, e->error_code, err_buf, BUFSIZ);
|
||||
@ -1144,37 +1113,34 @@ static int GrabXErrorHandler(Display * display, XErrorEvent * e)
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Setup the Error handler.
|
||||
*/
|
||||
static void x_shortcut_setup_error_handler(void)
|
||||
{ // {{{
|
||||
{
|
||||
dunst_grab_errored = false;
|
||||
|
||||
XFlush(xctx.dc->dpy);
|
||||
XSetErrorHandler(GrabXErrorHandler);
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Tear down the Error handler.
|
||||
*/
|
||||
static int x_shortcut_tear_down_error_handler(void)
|
||||
{ // {{{
|
||||
{
|
||||
XFlush(xctx.dc->dpy);
|
||||
XSync(xctx.dc->dpy, false);
|
||||
XSetErrorHandler(NULL);
|
||||
return dunst_grab_errored;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Grab the given keyboard shortcut.
|
||||
*/
|
||||
int x_shortcut_grab(keyboard_shortcut *ks)
|
||||
{ // {{{
|
||||
{
|
||||
if (!ks->is_valid)
|
||||
return 1;
|
||||
Window root;
|
||||
@ -1193,25 +1159,23 @@ int x_shortcut_grab(keyboard_shortcut *ks)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Ungrab the given keyboard shortcut.
|
||||
*/
|
||||
void x_shortcut_ungrab(keyboard_shortcut *ks)
|
||||
{ // {{{
|
||||
{
|
||||
Window root;
|
||||
root = RootWindow(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
||||
if (ks->is_valid)
|
||||
XUngrabKey(xctx.dc->dpy, ks->code, ks->mask, root);
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Initialize the keyboard shortcut.
|
||||
*/
|
||||
void x_shortcut_init(keyboard_shortcut *ks)
|
||||
{ // {{{
|
||||
{
|
||||
if (ks == NULL || ks->str == NULL)
|
||||
return;
|
||||
|
||||
@ -1262,8 +1226,5 @@ void x_shortcut_init(keyboard_shortcut *ks)
|
||||
|
||||
free(str_begin);
|
||||
}
|
||||
// }}}
|
||||
|
||||
// }}}
|
||||
// }}}
|
||||
/* vim: set ts=8 sw=8 tw=0: */
|
||||
|
Loading…
x
Reference in New Issue
Block a user