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