indent -linx --no-tabs
This commit is contained in:
parent
b8004f56d8
commit
e82da9d5e7
13
config.def.h
13
config.def.h
@ -39,7 +39,6 @@ char *frame_color = "#888888";
|
||||
* */
|
||||
int startup_notification = False;
|
||||
|
||||
|
||||
/* monitor to display notifications on */
|
||||
int monitor = 0;
|
||||
|
||||
@ -63,16 +62,20 @@ enum follow_mode f_mode = FOLLOW_NONE;
|
||||
* use "none" to disable
|
||||
*/
|
||||
keyboard_shortcut close_ks = {.str = "none",
|
||||
.code = 0, .sym = NoSymbol,.is_valid = False}; /* ignore this */
|
||||
.code = 0,.sym = NoSymbol,.is_valid = False
|
||||
}; /* ignore this */
|
||||
|
||||
keyboard_shortcut close_all_ks = {.str = "none",
|
||||
.code = 0, .sym = NoSymbol,.is_valid = False}; /* ignore this */
|
||||
.code = 0,.sym = NoSymbol,.is_valid = False
|
||||
}; /* ignore this */
|
||||
|
||||
keyboard_shortcut history_ks = {.str = "none",
|
||||
.code = 0, .sym = NoSymbol,.is_valid = False}; /* ignore this */
|
||||
.code = 0,.sym = NoSymbol,.is_valid = False
|
||||
}; /* ignore this */
|
||||
|
||||
keyboard_shortcut context_ks = {.str = "none",
|
||||
.code = 0, .sym = NoSymbol,.is_valid = False}; /* ignore this */
|
||||
.code = 0,.sym = NoSymbol,.is_valid = False
|
||||
}; /* ignore this */
|
||||
|
||||
rule_t default_rules[] = {
|
||||
/* name can be any unique string. It is used to identify the rule in dunstrc to override it there */
|
||||
|
165
dbus.c
165
dbus.c
@ -10,14 +10,13 @@ GDBusConnection *dbus_conn;
|
||||
|
||||
static GDBusNodeInfo *introspection_data = NULL;
|
||||
|
||||
static const char *introspection_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
static const char *introspection_xml =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
"<node name=\"/org/freedesktop/Notifications\">"
|
||||
" <interface name=\"org.freedesktop.Notifications\">"
|
||||
" "
|
||||
" <interface name=\"org.freedesktop.Notifications\">" " "
|
||||
" <method name=\"GetCapabilities\">"
|
||||
" <arg direction=\"out\" name=\"capabilities\" type=\"as\"/>"
|
||||
" </method>"
|
||||
" <method name=\"Notify\">"
|
||||
" </method>" " <method name=\"Notify\">"
|
||||
" <arg direction=\"in\" name=\"app_name\" type=\"s\"/>"
|
||||
" <arg direction=\"in\" name=\"replaces_id\" type=\"u\"/>"
|
||||
" <arg direction=\"in\" name=\"app_icon\" type=\"s\"/>"
|
||||
@ -27,39 +26,29 @@ static const char *introspection_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"
|
||||
" <arg direction=\"in\" name=\"hints\" type=\"a{sv}\"/>"
|
||||
" <arg direction=\"in\" name=\"expire_timeout\" type=\"i\"/>"
|
||||
" <arg direction=\"out\" name=\"id\" type=\"u\"/>"
|
||||
" </method>"
|
||||
" "
|
||||
" <method name=\"CloseNotification\">"
|
||||
" </method>" " " " <method name=\"CloseNotification\">"
|
||||
" <arg direction=\"in\" name=\"id\" type=\"u\"/>"
|
||||
" </method>"
|
||||
" <method name=\"GetServerInformation\">"
|
||||
" </method>" " <method name=\"GetServerInformation\">"
|
||||
" <arg direction=\"out\" name=\"name\" type=\"s\"/>"
|
||||
" <arg direction=\"out\" name=\"vendor\" type=\"s\"/>"
|
||||
" <arg direction=\"out\" name=\"version\" type=\"s\"/>"
|
||||
" <arg direction=\"out\" name=\"spec_version\" type=\"s\"/>"
|
||||
" </method>"
|
||||
" <signal name=\"NotificationClosed\">"
|
||||
" </method>" " <signal name=\"NotificationClosed\">"
|
||||
" <arg name=\"id\" type=\"u\"/>"
|
||||
" <arg name=\"reason\" type=\"u\"/>"
|
||||
" </signal>"
|
||||
" <arg name=\"reason\" type=\"u\"/>" " </signal>"
|
||||
" <signal name=\"ActionInvoked\">"
|
||||
" <arg name=\"id\" type=\"u\"/>"
|
||||
" <arg name=\"action_key\" type=\"s\"/>"
|
||||
" </signal>"
|
||||
" </interface>"
|
||||
" "
|
||||
" <interface name=\"org.xfce.Notifyd\">"
|
||||
" <arg name=\"action_key\" type=\"s\"/>" " </signal>"
|
||||
" </interface>" " " " <interface name=\"org.xfce.Notifyd\">"
|
||||
" <method name=\"Quit\"/>" " </interface>" "</node>";
|
||||
|
||||
|
||||
static void onGetCapabilities(GDBusConnection * connection,
|
||||
const gchar * sender,
|
||||
const GVariant * parameters,
|
||||
GDBusMethodInvocation * invocation);
|
||||
static void onNotify(GDBusConnection * connection,
|
||||
const gchar * sender,
|
||||
GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation);
|
||||
GVariant * parameters, GDBusMethodInvocation * invocation);
|
||||
static void onCloseNotification(GDBusConnection * connection,
|
||||
const gchar * sender,
|
||||
GVariant * parameters,
|
||||
@ -75,23 +64,21 @@ void handle_method_call(GDBusConnection *connection,
|
||||
const gchar * interface_name,
|
||||
const gchar * method_name,
|
||||
GVariant * parameters,
|
||||
GDBusMethodInvocation *invocation,
|
||||
gpointer user_data)
|
||||
GDBusMethodInvocation * invocation, gpointer user_data)
|
||||
{
|
||||
if (g_strcmp0(method_name, "GetCapabilities") == 0) {
|
||||
onGetCapabilities(connection, sender, parameters, invocation);
|
||||
}
|
||||
else if (g_strcmp0(method_name, "Notify") == 0) {
|
||||
} else if (g_strcmp0(method_name, "Notify") == 0) {
|
||||
onNotify(connection, sender, parameters, invocation);
|
||||
}
|
||||
else if (g_strcmp0(method_name, "CloseNotification") == 0) {
|
||||
} else if (g_strcmp0(method_name, "CloseNotification") == 0) {
|
||||
onCloseNotification(connection, sender, parameters, invocation);
|
||||
}
|
||||
else if (g_strcmp0(method_name, "GetServerInformation") == 0) {
|
||||
onGetServerInformation(connection, sender, parameters, invocation);
|
||||
} else if (g_strcmp0(method_name, "GetServerInformation") == 0) {
|
||||
onGetServerInformation(connection, sender, parameters,
|
||||
invocation);
|
||||
} else {
|
||||
g_object_unref(invocation);
|
||||
printf("WARNING: sender: %s; unknown method_name: %s\n", sender, method_name);
|
||||
printf("WARNING: sender: %s; unknown method_name: %s\n", sender,
|
||||
method_name);
|
||||
}
|
||||
|
||||
}
|
||||
@ -117,8 +104,7 @@ static void onGetCapabilities(GDBusConnection *connection,
|
||||
|
||||
static void onNotify(GDBusConnection * connection,
|
||||
const gchar * sender,
|
||||
GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation)
|
||||
GVariant * parameters, GDBusMethodInvocation * invocation)
|
||||
{
|
||||
|
||||
gchar *appname = NULL;
|
||||
@ -147,52 +133,82 @@ static void onNotify(GDBusConnection *connection,
|
||||
|
||||
switch (idx) {
|
||||
case 0:
|
||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING))
|
||||
appname = g_variant_dup_string(content, NULL);
|
||||
if (g_variant_is_of_type
|
||||
(content, G_VARIANT_TYPE_STRING))
|
||||
appname =
|
||||
g_variant_dup_string(content, NULL);
|
||||
break;
|
||||
case 1:
|
||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_UINT32))
|
||||
replaces_id = g_variant_get_uint32(content);
|
||||
if (g_variant_is_of_type
|
||||
(content, G_VARIANT_TYPE_UINT32))
|
||||
replaces_id =
|
||||
g_variant_get_uint32(content);
|
||||
break;
|
||||
case 2:
|
||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING))
|
||||
icon = g_variant_dup_string(content, NULL);
|
||||
if (g_variant_is_of_type
|
||||
(content, G_VARIANT_TYPE_STRING))
|
||||
icon =
|
||||
g_variant_dup_string(content, NULL);
|
||||
break;
|
||||
case 3:
|
||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING))
|
||||
summary = g_variant_dup_string(content, NULL);
|
||||
if (g_variant_is_of_type
|
||||
(content, G_VARIANT_TYPE_STRING))
|
||||
summary =
|
||||
g_variant_dup_string(content, NULL);
|
||||
break;
|
||||
case 4:
|
||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING))
|
||||
body = g_variant_dup_string(content, NULL);
|
||||
if (g_variant_is_of_type
|
||||
(content, G_VARIANT_TYPE_STRING))
|
||||
body =
|
||||
g_variant_dup_string(content, NULL);
|
||||
break;
|
||||
case 5:
|
||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING_ARRAY))
|
||||
actions->actions = g_variant_dup_strv(content, &(actions->count));
|
||||
if (g_variant_is_of_type
|
||||
(content, G_VARIANT_TYPE_STRING_ARRAY))
|
||||
actions->actions =
|
||||
g_variant_dup_strv(content,
|
||||
&(actions->
|
||||
count));
|
||||
break;
|
||||
case 6:
|
||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_DICTIONARY)) {
|
||||
if (g_variant_is_of_type
|
||||
(content, G_VARIANT_TYPE_DICTIONARY)) {
|
||||
|
||||
dict_value = g_variant_lookup_value(content, "urgency", G_VARIANT_TYPE_BYTE);
|
||||
dict_value =
|
||||
g_variant_lookup_value(content,
|
||||
"urgency",
|
||||
G_VARIANT_TYPE_BYTE);
|
||||
if (dict_value)
|
||||
urgency = g_variant_get_byte(dict_value);
|
||||
urgency =
|
||||
g_variant_get_byte
|
||||
(dict_value);
|
||||
|
||||
dict_value = g_variant_lookup_value(content, "fgcolor", G_VARIANT_TYPE_STRING);
|
||||
dict_value =
|
||||
g_variant_lookup_value(content,
|
||||
"fgcolor",
|
||||
G_VARIANT_TYPE_STRING);
|
||||
if (dict_value)
|
||||
fgcolor = g_variant_dup_string(dict_value, NULL);
|
||||
fgcolor =
|
||||
g_variant_dup_string
|
||||
(dict_value, NULL);
|
||||
|
||||
dict_value = g_variant_lookup_value(content, "bgcolor", G_VARIANT_TYPE_STRING);
|
||||
dict_value =
|
||||
g_variant_lookup_value(content,
|
||||
"bgcolor",
|
||||
G_VARIANT_TYPE_STRING);
|
||||
if (dict_value)
|
||||
bgcolor = g_variant_dup_string(dict_value, NULL);
|
||||
bgcolor =
|
||||
g_variant_dup_string
|
||||
(dict_value, NULL);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_INT32))
|
||||
if (g_variant_is_of_type
|
||||
(content, G_VARIANT_TYPE_INT32))
|
||||
timeout = g_variant_get_int32(content);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
idx++;
|
||||
}
|
||||
|
||||
@ -276,14 +292,11 @@ void notificationClosed(notification * n, int reason)
|
||||
GVariant *body = g_variant_new("(uu)", n->id, reason);
|
||||
GError *err = NULL;
|
||||
|
||||
g_dbus_connection_emit_signal(
|
||||
dbus_conn,
|
||||
g_dbus_connection_emit_signal(dbus_conn,
|
||||
n->dbus_client,
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications",
|
||||
"NotificationClosed",
|
||||
body,
|
||||
&err);
|
||||
"NotificationClosed", body, &err);
|
||||
|
||||
if (err) {
|
||||
printf("notificationClosed ERROR\n");
|
||||
@ -296,38 +309,32 @@ void actionInvoked(notification *n, const char *identifier)
|
||||
GVariant *body = g_variant_new("(us)", n->id, identifier);
|
||||
GError *err = NULL;
|
||||
|
||||
g_dbus_connection_emit_signal(
|
||||
dbus_conn,
|
||||
g_dbus_connection_emit_signal(dbus_conn,
|
||||
n->dbus_client,
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications",
|
||||
"ActionInvoked",
|
||||
body,
|
||||
&err);
|
||||
"ActionInvoked", body, &err);
|
||||
|
||||
if (err) {
|
||||
printf("ActionInvoked ERROR\n");
|
||||
}
|
||||
}
|
||||
|
||||
static const GDBusInterfaceVTable interface_vtable =
|
||||
{
|
||||
static const GDBusInterfaceVTable interface_vtable = {
|
||||
handle_method_call
|
||||
};
|
||||
|
||||
static void on_bus_acquired(GDBusConnection * connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
const gchar * name, gpointer user_data)
|
||||
{
|
||||
guint registration_id;
|
||||
|
||||
registration_id = g_dbus_connection_register_object(connection,
|
||||
"/org/freedesktop/Notifications",
|
||||
introspection_data->interfaces[0],
|
||||
introspection_data->
|
||||
interfaces[0],
|
||||
&interface_vtable,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
NULL, NULL, NULL);
|
||||
|
||||
if (!registration_id > 0) {
|
||||
fprintf(stderr, "Unable to register\n");
|
||||
@ -336,15 +343,13 @@ static void on_bus_acquired(GDBusConnection *connection,
|
||||
}
|
||||
|
||||
static void on_name_acquired(GDBusConnection * connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
const gchar * name, gpointer user_data)
|
||||
{
|
||||
dbus_conn = connection;
|
||||
}
|
||||
|
||||
static void on_name_lost(GDBusConnection * connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
const gchar * name, gpointer user_data)
|
||||
{
|
||||
fprintf(stderr, "Name Lost\n");
|
||||
exit(1);
|
||||
@ -363,10 +368,7 @@ int initdbus(void)
|
||||
"org.freedesktop.Notifications",
|
||||
G_BUS_NAME_OWNER_FLAGS_NONE,
|
||||
on_bus_acquired,
|
||||
on_name_acquired,
|
||||
on_name_lost,
|
||||
NULL,
|
||||
NULL);
|
||||
on_name_acquired, on_name_lost, NULL, NULL);
|
||||
|
||||
return owner_id;
|
||||
}
|
||||
@ -375,4 +377,5 @@ void dbus_tear_down(int owner_id)
|
||||
{
|
||||
g_bus_unown_name(owner_id);
|
||||
}
|
||||
|
||||
/* vim: set ts=8 sw=8 tw=0: */
|
||||
|
45
dunst.c
45
dunst.c
@ -37,7 +37,6 @@
|
||||
#include "option_parser.h"
|
||||
#include "settings.h"
|
||||
|
||||
|
||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||
|
||||
#ifndef VERSION
|
||||
@ -54,9 +53,6 @@ typedef struct _x11_source {
|
||||
Window w;
|
||||
} x11_source_t;
|
||||
|
||||
|
||||
|
||||
|
||||
/* index of colors fit to urgency level */
|
||||
bool pause_display = false;
|
||||
|
||||
@ -65,37 +61,22 @@ bool timer_active = false;
|
||||
|
||||
bool force_redraw = false;
|
||||
|
||||
|
||||
/* notification lists */
|
||||
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;
|
||||
|
||||
|
||||
|
||||
|
||||
/* misc funtions */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void check_timeouts(void)
|
||||
{
|
||||
/* nothing to do */
|
||||
if (displayed->length == 0)
|
||||
return;
|
||||
|
||||
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) {
|
||||
notification *n = iter->data;
|
||||
|
||||
/* don't timeout when user is idle */
|
||||
@ -128,7 +109,8 @@ void update_lists()
|
||||
|
||||
if (pause_display) {
|
||||
while (displayed->length > 0) {
|
||||
g_queue_insert_sorted(queue, g_queue_pop_head(queue), notification_cmp_data, NULL);
|
||||
g_queue_insert_sorted(queue, g_queue_pop_head(queue),
|
||||
notification_cmp_data, NULL);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -143,7 +125,6 @@ void update_lists()
|
||||
limit = xctx.geometry.h;
|
||||
}
|
||||
|
||||
|
||||
/* move notifications from queue to displayed */
|
||||
while (queue->length > 0) {
|
||||
|
||||
@ -163,11 +144,11 @@ void update_lists()
|
||||
notification_run_script(n);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
while (displayed->length > 0) {
|
||||
@ -248,10 +229,6 @@ gboolean run(void *data)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
@ -259,7 +236,6 @@ int main(int argc, char *argv[])
|
||||
displayed = g_queue_new();
|
||||
queue = g_queue_new();
|
||||
|
||||
|
||||
cmdline_load(argc, argv);
|
||||
|
||||
if (cmdline_get_bool("-v/-version", false, "Print version")
|
||||
@ -306,7 +282,8 @@ int main(int argc, char *argv[])
|
||||
mainloop = g_main_loop_new(NULL, FALSE);
|
||||
|
||||
GPollFD dpy_pollfd = { xctx.dc->dpy->fd,
|
||||
G_IO_IN | G_IO_HUP | G_IO_ERR, 0 };
|
||||
G_IO_IN | G_IO_HUP | G_IO_ERR, 0
|
||||
};
|
||||
|
||||
GSourceFuncs x11_source_funcs = {
|
||||
x_mainloop_fd_prepare,
|
||||
@ -314,7 +291,8 @@ int main(int argc, char *argv[])
|
||||
x_mainloop_fd_dispatch,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL };
|
||||
NULL
|
||||
};
|
||||
|
||||
GSource *x11_source =
|
||||
g_source_new(&x11_source_funcs, sizeof(x11_source_t));
|
||||
@ -355,7 +333,8 @@ void usage(int exit_status)
|
||||
|
||||
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);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
4
dunst.h
4
dunst.h
@ -11,7 +11,6 @@
|
||||
#define PERR(msg, errnum) printf("(%d) %s : %s\n", __LINE__, (msg), (strerror(errnum)))
|
||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||
|
||||
|
||||
#define ColLast 2
|
||||
#define ColFG 1
|
||||
#define ColBG 0
|
||||
@ -20,7 +19,6 @@ enum alignment { left, center, right };
|
||||
enum separator_color { FOREGROUND, AUTO, FRAME, CUSTOM };
|
||||
enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD };
|
||||
|
||||
|
||||
extern int verbosity;
|
||||
extern GQueue *queue;
|
||||
extern GQueue *displayed;
|
||||
@ -30,8 +28,6 @@ extern bool pause_display;
|
||||
extern const char *color_strings[2][3];
|
||||
extern DC *dc;
|
||||
|
||||
|
||||
|
||||
/* return id of notification */
|
||||
gboolean run(void *data);
|
||||
void wake_up(void);
|
||||
|
25
menu.c
25
menu.c
@ -12,7 +12,6 @@
|
||||
#include "settings.h"
|
||||
#include "dbus.h"
|
||||
|
||||
|
||||
/*
|
||||
* Exctract all urls from a given string.
|
||||
*
|
||||
@ -25,7 +24,8 @@ char *extract_urls( const char * to_match)
|
||||
static regex_t cregex;
|
||||
|
||||
if (!is_initialized) {
|
||||
char *regex = "((http|ftp|https)(://))?(www\\.)?[[:alnum:]_-]+\\.[^[:space:]]+";
|
||||
char *regex =
|
||||
"((http|ftp|https)(://))?(www\\.)?[[:alnum:]_-]+\\.[^[:space:]]+";
|
||||
int ret = regcomp(&cregex, regex, REG_EXTENDED | REG_ICASE);
|
||||
if (ret != 0) {
|
||||
printf("failed to compile regex\n");
|
||||
@ -62,8 +62,6 @@ char *extract_urls( const char * to_match)
|
||||
return urls;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Open url in browser.
|
||||
*
|
||||
@ -80,14 +78,14 @@ if (browser_pid1) {
|
||||
if (browser_pid2) {
|
||||
exit(0);
|
||||
} else {
|
||||
char *browser_cmd = string_append(settings.browser, url, " ");
|
||||
char *browser_cmd =
|
||||
string_append(settings.browser, url, " ");
|
||||
char **cmd = g_strsplit(browser_cmd, " ", 0);
|
||||
execvp(cmd[0], cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Notify the corresponding client
|
||||
* that an action has been invoked
|
||||
@ -104,8 +102,8 @@ void invoke_action(const char *action)
|
||||
}
|
||||
name_begin++;
|
||||
|
||||
|
||||
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) {
|
||||
notification *n = iter->data;
|
||||
if (g_str_has_prefix(action, n->appname)) {
|
||||
if (!n->actions)
|
||||
@ -152,14 +150,16 @@ void context_menu(void)
|
||||
{
|
||||
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) {
|
||||
notification *n = iter->data;
|
||||
dmenu_input = string_append(dmenu_input, n->urls, "\n");
|
||||
if (n->actions)
|
||||
dmenu_input = string_append(dmenu_input, n->actions->dmenu_str, "\n");
|
||||
dmenu_input =
|
||||
string_append(dmenu_input, n->actions->dmenu_str,
|
||||
"\n");
|
||||
}
|
||||
|
||||
|
||||
if (!dmenu_input)
|
||||
return;
|
||||
|
||||
@ -210,8 +210,5 @@ void context_menu(void)
|
||||
|
||||
close(parent_io[0]);
|
||||
|
||||
|
||||
dispatch_menu_result(buf);
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,12 +18,8 @@
|
||||
#include "rules.h"
|
||||
#include "menu.h"
|
||||
|
||||
|
||||
int next_notification_id = 1;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* print a human readable representation
|
||||
* of the given notification to stdout.
|
||||
@ -49,7 +45,8 @@ void notification_print(notification * n)
|
||||
printf("\tactions:\n");
|
||||
printf("\t{\n");
|
||||
for (int i = 0; i < n->actions->count; i += 2) {
|
||||
printf("\t\t [%s,%s]\n", n->actions->actions[i], n->actions->actions[i+1]);
|
||||
printf("\t\t [%s,%s]\n", n->actions->actions[i],
|
||||
n->actions->actions[i + 1]);
|
||||
}
|
||||
printf("actions_dmenu: %s\n", n->actions->dmenu_str);
|
||||
printf("\t]\n");
|
||||
@ -104,8 +101,7 @@ void notification_run_script(notification *n)
|
||||
body,
|
||||
icon,
|
||||
urgency,
|
||||
(char *) NULL
|
||||
);
|
||||
(char *)NULL);
|
||||
if (ret != 0) {
|
||||
PERR("Unable to run script", errno);
|
||||
exit(EXIT_FAILURE);
|
||||
@ -142,7 +138,6 @@ 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.
|
||||
*/
|
||||
@ -265,11 +260,11 @@ int notification_init(notification * n, int id)
|
||||
|
||||
n->msg = g_strstrip(n->msg);
|
||||
|
||||
|
||||
n->dup_count = 0;
|
||||
|
||||
/* check if n is a duplicate */
|
||||
for (GList *iter = g_queue_peek_head_link(queue); iter; iter = iter->next) {
|
||||
for (GList * iter = g_queue_peek_head_link(queue); iter;
|
||||
iter = iter->next) {
|
||||
notification *orig = iter->data;
|
||||
if (strcmp(orig->appname, n->appname) == 0
|
||||
&& strcmp(orig->msg, n->msg) == 0) {
|
||||
@ -280,7 +275,8 @@ int notification_init(notification * n, int id)
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
notification *orig = iter->data;
|
||||
if (strcmp(orig->appname, n->appname) == 0
|
||||
&& strcmp(orig->msg, n->msg) == 0) {
|
||||
@ -309,7 +305,8 @@ int notification_init(notification * n, int id)
|
||||
|
||||
n->colors = initcolor(xctx.dc, fg, bg);
|
||||
|
||||
n->timeout = n->timeout == -1 ? settings.timeouts[n->urgency] : n->timeout;
|
||||
n->timeout =
|
||||
n->timeout == -1 ? settings.timeouts[n->urgency] : n->timeout;
|
||||
n->start = 0;
|
||||
|
||||
n->timestamp = time(NULL);
|
||||
@ -334,26 +331,27 @@ int notification_init(notification * n, int id)
|
||||
|
||||
n->urls = extract_urls(tmp);
|
||||
|
||||
|
||||
if (n->actions) {
|
||||
n->actions->dmenu_str = NULL;
|
||||
for (int i = 0; i < n->actions->count; i += 2) {
|
||||
char *human_readable = n->actions->actions[i + 1];
|
||||
printf("debug: %s\n", n->appname);
|
||||
printf("debug: %s\n", human_readable);
|
||||
char *tmp = g_strdup_printf("%s %s", n->appname, human_readable);
|
||||
char *tmp =
|
||||
g_strdup_printf("%s %s", n->appname,
|
||||
human_readable);
|
||||
printf("debug: %s\n", tmp);
|
||||
|
||||
n->actions->dmenu_str = string_append(n->actions->dmenu_str,
|
||||
g_strdup_printf("%s(%s)",
|
||||
n->appname,
|
||||
human_readable), "\n");
|
||||
n->actions->dmenu_str =
|
||||
string_append(n->actions->dmenu_str,
|
||||
g_strdup_printf("%s(%s)", n->appname,
|
||||
human_readable),
|
||||
"\n");
|
||||
}
|
||||
}
|
||||
|
||||
free(tmp);
|
||||
|
||||
|
||||
if (settings.print_notifications)
|
||||
notification_print(n);
|
||||
|
||||
@ -373,7 +371,8 @@ 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) {
|
||||
for (GList * iter = g_queue_peek_head_link(displayed); iter;
|
||||
iter = iter->next) {
|
||||
notification *n = iter->data;
|
||||
if (n->id == id) {
|
||||
g_queue_remove(displayed, n);
|
||||
@ -383,7 +382,8 @@ int notification_close_by_id(int id, int reason)
|
||||
}
|
||||
}
|
||||
|
||||
for (GList *iter = g_queue_peek_head_link(queue); iter; iter = iter->next) {
|
||||
for (GList * iter = g_queue_peek_head_link(queue); iter;
|
||||
iter = iter->next) {
|
||||
notification *n = iter->data;
|
||||
if (n->id == id) {
|
||||
g_queue_remove(queue, n);
|
||||
@ -410,4 +410,3 @@ int notification_close(notification * n, int reason)
|
||||
return -1;
|
||||
return notification_close_by_id(n->id, reason);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,6 @@ typedef struct _notification {
|
||||
Actions *actions;
|
||||
} notification;
|
||||
|
||||
|
||||
int notification_init(notification * n, int id);
|
||||
int notification_close_by_id(int id, int reason);
|
||||
int notification_cmp(const void *a, const void *b);
|
||||
|
@ -444,13 +444,15 @@ void cmdline_usage_append(char *key, char *type, char *description)
|
||||
key_type = g_strdup(key);
|
||||
|
||||
if (!usage_str) {
|
||||
usage_str = g_strdup_printf("%-40s - %s\n", key_type, description);
|
||||
usage_str =
|
||||
g_strdup_printf("%-40s - %s\n", key_type, description);
|
||||
free(key_type);
|
||||
return;
|
||||
}
|
||||
|
||||
char *tmp;
|
||||
tmp = g_strdup_printf("%s%-40s - %s\n", usage_str, key_type, description);
|
||||
tmp =
|
||||
g_strdup_printf("%s%-40s - %s\n", usage_str, key_type, description);
|
||||
free(key_type);
|
||||
|
||||
free(usage_str);
|
||||
|
1
rules.c
1
rules.c
@ -53,7 +53,6 @@ void rule_init(rule_t *r)
|
||||
r->format = NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check whether rule should be applied to n.
|
||||
*/
|
||||
|
44
settings.c
44
settings.c
@ -74,7 +74,8 @@ void load_settings(char *cmdline_config_path)
|
||||
|
||||
settings.ignore_newline =
|
||||
option_get_bool("global", "ignore_newline", "-ignore_newline",
|
||||
ignore_newline, "Ignore newline characters in notifications");
|
||||
ignore_newline,
|
||||
"Ignore newline characters in notifications");
|
||||
settings.idle_threshold =
|
||||
option_get_int("global", "idle_threshold", "-idle_threshold",
|
||||
idle_threshold,
|
||||
@ -83,8 +84,7 @@ void load_settings(char *cmdline_config_path)
|
||||
option_get_int("global", "monitor", "-mon", monitor,
|
||||
"On which monitor should the notifications be displayed");
|
||||
{
|
||||
char *c =
|
||||
option_get_string("global", "follow", "-follow", "",
|
||||
char *c = option_get_string("global", "follow", "-follow", "",
|
||||
"Follow mouse, keyboard or none?");
|
||||
if (strlen(c) > 0) {
|
||||
parse_follow_mode(c);
|
||||
@ -103,8 +103,7 @@ void load_settings(char *cmdline_config_path)
|
||||
bounce_freq,
|
||||
"Make long text bounce from side to side");
|
||||
{
|
||||
char *c =
|
||||
option_get_string("global", "alignment",
|
||||
char *c = option_get_string("global", "alignment",
|
||||
"-align/-alignment", "",
|
||||
"Align notifications left/center/right");
|
||||
if (strlen(c) > 0) {
|
||||
@ -136,14 +135,14 @@ void load_settings(char *cmdline_config_path)
|
||||
option_get_int("global", "padding", "-padding", padding,
|
||||
"Padding between text and separator");
|
||||
settings.h_padding =
|
||||
option_get_int("global", "horizontal_padding", "-horizontal_padding",
|
||||
h_padding, "horizontal padding");
|
||||
option_get_int("global", "horizontal_padding",
|
||||
"-horizontal_padding", h_padding,
|
||||
"horizontal padding");
|
||||
settings.transparency =
|
||||
option_get_int("global", "transparency", "-transparency",
|
||||
transparency, "Transparency. range 0-100");
|
||||
{
|
||||
char *c =
|
||||
option_get_string("global", "separator_color",
|
||||
char *c = option_get_string("global", "separator_color",
|
||||
"-sep_color/-separator_color", "",
|
||||
"Color of the separator line (or 'auto')");
|
||||
if (strlen(c) > 0) {
|
||||
@ -161,20 +160,27 @@ void load_settings(char *cmdline_config_path)
|
||||
}
|
||||
}
|
||||
|
||||
settings.startup_notification = option_get_bool("global", "startup_notification",
|
||||
"-startup_notification", false, "print notification on startup");
|
||||
settings.startup_notification =
|
||||
option_get_bool("global", "startup_notification",
|
||||
"-startup_notification", false,
|
||||
"print notification on startup");
|
||||
|
||||
|
||||
settings.dmenu = option_get_string("global", "dmenu", "-dmenu", dmenu, "path to dmenu");
|
||||
settings.dmenu =
|
||||
option_get_string("global", "dmenu", "-dmenu", dmenu,
|
||||
"path to dmenu");
|
||||
settings.dmenu_cmd = g_strsplit(dmenu, " ", 0);
|
||||
|
||||
settings.browser = option_get_string("global", "browser", "-browser", browser, "path to browser");
|
||||
settings.browser =
|
||||
option_get_string("global", "browser", "-browser", browser,
|
||||
"path to browser");
|
||||
|
||||
settings.frame_width = option_get_int("frame", "width", "-frame_width", frame_width,
|
||||
settings.frame_width =
|
||||
option_get_int("frame", "width", "-frame_width", frame_width,
|
||||
"Width of frame around window");
|
||||
|
||||
settings.frame_color = option_get_string("frame", "color", "-frame_color",
|
||||
frame_color, "Color of the frame around window");
|
||||
settings.frame_color =
|
||||
option_get_string("frame", "color", "-frame_color", frame_color,
|
||||
"Color of the frame around window");
|
||||
|
||||
settings.lowbgcolor =
|
||||
option_get_string("urgency_low", "background", "-lb", lowbgcolor,
|
||||
@ -223,8 +229,7 @@ void load_settings(char *cmdline_config_path)
|
||||
|
||||
settings.context_ks.str =
|
||||
option_get_string("shortcuts", "context", "-context_key",
|
||||
context_ks.str,
|
||||
"Shortcut for context menu");
|
||||
context_ks.str, "Shortcut for context menu");
|
||||
|
||||
settings.print_notifications =
|
||||
cmdline_get_bool("-print", false,
|
||||
@ -290,7 +295,6 @@ void load_settings(char *cmdline_config_path)
|
||||
r->script = ini_get_string(cur_section, "script", NULL);
|
||||
}
|
||||
|
||||
|
||||
#ifndef STATIC_CONFIG
|
||||
fclose(config_file);
|
||||
free_ini();
|
||||
|
174
x.c
174
x.c
@ -301,7 +301,6 @@ int textw(DC * dc, const char *text)
|
||||
return textnw(dc, text, strlen(text)) + dc->font.height;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Helper function to use glib's mainloop mechanic
|
||||
* with Xlib
|
||||
@ -312,7 +311,6 @@ gboolean x_mainloop_fd_prepare(GSource *source, gint *timeout)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Helper function to use glib's mainloop mechanic
|
||||
* with Xlib
|
||||
@ -322,11 +320,11 @@ 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)
|
||||
gboolean x_mainloop_fd_dispatch(GSource * source, GSourceFunc callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
XEvent ev;
|
||||
while (XPending(xctx.dc->dpy) > 0) {
|
||||
@ -350,24 +348,30 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer
|
||||
break;
|
||||
case KeyPress:
|
||||
if (settings.close_ks.str
|
||||
&& XLookupKeysym(&ev.xkey, 0) == settings.close_ks.sym
|
||||
&& XLookupKeysym(&ev.xkey,
|
||||
0) == settings.close_ks.sym
|
||||
&& settings.close_ks.mask == ev.xkey.state) {
|
||||
if (displayed) {
|
||||
notification_close(g_queue_peek_head_link(displayed)->data, 2);
|
||||
notification_close
|
||||
(g_queue_peek_head_link(displayed)->
|
||||
data, 2);
|
||||
}
|
||||
}
|
||||
if (settings.history_ks.str
|
||||
&& XLookupKeysym(&ev.xkey, 0) == settings.history_ks.sym
|
||||
&& XLookupKeysym(&ev.xkey,
|
||||
0) == settings.history_ks.sym
|
||||
&& settings.history_ks.mask == ev.xkey.state) {
|
||||
history_pop();
|
||||
}
|
||||
if (settings.close_all_ks.str
|
||||
&& XLookupKeysym(&ev.xkey, 0) == settings.close_all_ks.sym
|
||||
&& XLookupKeysym(&ev.xkey,
|
||||
0) == settings.close_all_ks.sym
|
||||
&& settings.close_all_ks.mask == ev.xkey.state) {
|
||||
move_all_to_history();
|
||||
}
|
||||
if (settings.context_ks.str
|
||||
&& XLookupKeysym(&ev.xkey, 0) == settings.context_ks.sym
|
||||
&& XLookupKeysym(&ev.xkey,
|
||||
0) == settings.context_ks.sym
|
||||
&& settings.context_ks.mask == ev.xkey.state) {
|
||||
context_menu();
|
||||
}
|
||||
@ -377,8 +381,6 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Check whether the user is currently idle.
|
||||
*/
|
||||
@ -407,9 +409,12 @@ void x_handle_click(XEvent ev)
|
||||
if (ev.xbutton.button == Button1) {
|
||||
int y = settings.separator_height;
|
||||
notification *n = 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) {
|
||||
n = iter->data;
|
||||
int text_h = MAX(xctx.font_h, settings.line_height) * n->line_count;
|
||||
int text_h =
|
||||
MAX(xctx.font_h,
|
||||
settings.line_height) * n->line_count;
|
||||
int padding = 2 * settings.h_padding;
|
||||
|
||||
int height = text_h + padding;
|
||||
@ -424,8 +429,6 @@ void x_handle_click(XEvent ev)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Return the window that currently has
|
||||
* the keyboard focus.
|
||||
@ -460,12 +463,15 @@ Window get_focused_window(void)
|
||||
int select_screen(XineramaScreenInfo * info, int info_len)
|
||||
{
|
||||
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);
|
||||
|
||||
} else {
|
||||
int x, y;
|
||||
assert(settings.f_mode == FOLLOW_MOUSE || settings.f_mode == FOLLOW_KEYBOARD);
|
||||
Window root = RootWindow(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
||||
assert(settings.f_mode == FOLLOW_MOUSE
|
||||
|| settings.f_mode == FOLLOW_KEYBOARD);
|
||||
Window root =
|
||||
RootWindow(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
||||
|
||||
if (settings.f_mode == FOLLOW_MOUSE) {
|
||||
int dummy;
|
||||
@ -483,7 +489,10 @@ int select_screen(XineramaScreenInfo * info, int info_len)
|
||||
|
||||
if (focused == 0) {
|
||||
/* something went wrong. Fallback to default */
|
||||
return settings.monitor >= 0 ? settings.monitor : XDefaultScreen(xctx.dc->dpy);
|
||||
return settings.monitor >=
|
||||
0 ? settings.monitor : XDefaultScreen(xctx.
|
||||
dc->
|
||||
dpy);
|
||||
}
|
||||
|
||||
Window child_return;
|
||||
@ -500,7 +509,8 @@ int select_screen(XineramaScreenInfo * info, int info_len)
|
||||
}
|
||||
|
||||
/* something seems to be wrong. Fallback to default */
|
||||
return settings.monitor >= 0 ? settings.monitor : XDefaultScreen(xctx.dc->dpy);
|
||||
return settings.monitor >=
|
||||
0 ? settings.monitor : XDefaultScreen(xctx.dc->dpy);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -542,7 +552,6 @@ void x_screen_info(screen_info *scr)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Setup X11 stuff
|
||||
*/
|
||||
@ -579,7 +588,8 @@ void x_setup(void)
|
||||
xctx.framec = getcolor(xctx.dc, settings.frame_color);
|
||||
|
||||
if (settings.sep_color == CUSTOM) {
|
||||
xctx.sep_custom_col = getcolor(xctx.dc, settings.sep_custom_color_str);
|
||||
xctx.sep_custom_col =
|
||||
getcolor(xctx.dc, settings.sep_custom_color_str);
|
||||
} else {
|
||||
xctx.sep_custom_col = 0;
|
||||
}
|
||||
@ -596,16 +606,12 @@ void x_setup(void)
|
||||
&xctx.geometry.x, &xctx.geometry.y,
|
||||
&xctx.geometry.w, &xctx.geometry.h);
|
||||
|
||||
|
||||
xctx.screensaver_info = XScreenSaverAllocInfo();
|
||||
|
||||
|
||||
x_win_setup();
|
||||
x_shortcut_grab(&settings.history_ks);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* TODO comments and naming */
|
||||
|
||||
GSList *do_word_wrap(char *text, int max_width)
|
||||
@ -627,11 +633,14 @@ GSList *do_word_wrap(char *text, int max_width)
|
||||
}
|
||||
if (*end == '\n') {
|
||||
*end = ' ';
|
||||
result = g_slist_append(result, g_strndup(begin, end - begin));
|
||||
result =
|
||||
g_slist_append(result,
|
||||
g_strndup(begin, end - begin));
|
||||
begin = ++end;
|
||||
}
|
||||
|
||||
if (settings.word_wrap && max_width > 0 && textnw(xctx.dc, begin, (end - begin) + 1) > max_width) {
|
||||
if (settings.word_wrap && max_width > 0
|
||||
&& textnw(xctx.dc, begin, (end - begin) + 1) > max_width) {
|
||||
/* find previous space */
|
||||
char *space = end;
|
||||
while (space > begin && !isspace(*space))
|
||||
@ -640,7 +649,9 @@ GSList *do_word_wrap(char *text, int max_width)
|
||||
if (space > begin) {
|
||||
end = space;
|
||||
}
|
||||
result = g_slist_append(result, g_strndup(begin, end - begin));
|
||||
result =
|
||||
g_slist_append(result,
|
||||
g_strndup(begin, end - begin));
|
||||
begin = ++end;
|
||||
}
|
||||
end++;
|
||||
@ -649,7 +660,6 @@ GSList *do_word_wrap(char *text, int max_width)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
char *generate_final_text(notification * n)
|
||||
{
|
||||
char *msg = g_strstrip(n->msg);
|
||||
@ -660,13 +670,11 @@ char *generate_final_text(notification *n)
|
||||
buf = g_strdup_printf("(%d%s%s) %s",
|
||||
n->dup_count,
|
||||
n->actions ? "A" : "",
|
||||
n->urls ? "U" : "",
|
||||
msg);
|
||||
n->urls ? "U" : "", msg);
|
||||
} else if (n->actions || n->urls) {
|
||||
buf = g_strdup_printf("(%s%s) %s",
|
||||
n->actions ? "A" : "",
|
||||
n->urls ? "U" : "",
|
||||
msg);
|
||||
n->urls ? "U" : "", msg);
|
||||
} else {
|
||||
buf = g_strdup(msg);
|
||||
}
|
||||
@ -675,17 +683,20 @@ char *generate_final_text(notification *n)
|
||||
int hours, minutes, seconds;
|
||||
time_t t_delta = time(NULL) - n->timestamp;
|
||||
|
||||
if (settings.show_age_threshold >= 0 && t_delta >= settings.show_age_threshold) {
|
||||
if (settings.show_age_threshold >= 0
|
||||
&& t_delta >= settings.show_age_threshold) {
|
||||
hours = t_delta / 3600;
|
||||
minutes = t_delta / 60 % 60;
|
||||
seconds = t_delta % 60;
|
||||
|
||||
char *new_buf;
|
||||
if (hours > 0) {
|
||||
new_buf = g_strdup_printf("%s (%dh %dm %ds old)", buf, hours,
|
||||
new_buf =
|
||||
g_strdup_printf("%s (%dh %dm %ds old)", buf, hours,
|
||||
minutes, seconds);
|
||||
} else if (minutes > 0) {
|
||||
new_buf = g_strdup_printf("%s (%dm %ds old)", buf, minutes,
|
||||
new_buf =
|
||||
g_strdup_printf("%s (%dm %ds old)", buf, minutes,
|
||||
seconds);
|
||||
} else {
|
||||
new_buf = g_strdup_printf("%s (%ds old)", buf, seconds);
|
||||
@ -704,17 +715,20 @@ int calculate_x_offset(int line_width, int text_width)
|
||||
struct timeval t;
|
||||
float pos;
|
||||
/* If the text is wider than the frame, bouncing is enabled and word_wrap disabled */
|
||||
if (line_width < text_width && settings.bounce_freq > 0.0001 && !settings.word_wrap) {
|
||||
if (line_width < text_width && settings.bounce_freq > 0.0001
|
||||
&& !settings.word_wrap) {
|
||||
gettimeofday(&t, NULL);
|
||||
pos =
|
||||
((t.tv_sec % 100) * 1e6 + t.tv_usec) / (1e6 / settings.bounce_freq);
|
||||
((t.tv_sec % 100) * 1e6 +
|
||||
t.tv_usec) / (1e6 / settings.bounce_freq);
|
||||
return (1 + sinf(2 * 3.14159 * pos)) * leftover / 2;
|
||||
}
|
||||
switch (settings.align) {
|
||||
case left:
|
||||
return settings.frame_width + settings.h_padding;
|
||||
case center:
|
||||
return settings.frame_width + settings.h_padding + (leftover / 2);
|
||||
return settings.frame_width + settings.h_padding +
|
||||
(leftover / 2);
|
||||
case right:
|
||||
return settings.frame_width + settings.h_padding + leftover;
|
||||
default:
|
||||
@ -725,7 +739,8 @@ int calculate_x_offset(int line_width, int text_width)
|
||||
|
||||
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;
|
||||
|
||||
color.pixel = source_color;
|
||||
@ -829,7 +844,8 @@ GSList *generate_render_texts(int width)
|
||||
{
|
||||
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) {
|
||||
render_text *rt = g_malloc(sizeof(render_text));
|
||||
|
||||
rt->colors = ((notification *) iter->data)->colors;
|
||||
@ -843,14 +859,22 @@ GSList *generate_render_texts(int width)
|
||||
if (settings.indicate_hidden && queue->length > 0) {
|
||||
if (xctx.geometry.h != 1) {
|
||||
render_text *rt = g_malloc(sizeof(render_text));
|
||||
rt->colors = ((render_text *) g_slist_last(render_texts)->data)->colors;
|
||||
rt->lines = g_slist_append(NULL, g_strdup_printf("%d more)", queue->length));
|
||||
rt->colors =
|
||||
((render_text *) g_slist_last(render_texts)->data)->
|
||||
colors;
|
||||
rt->lines =
|
||||
g_slist_append(NULL,
|
||||
g_strdup_printf("%d more)",
|
||||
queue->length));
|
||||
render_texts = g_slist_append(render_texts, rt);
|
||||
} else {
|
||||
GSList *last_lines = ((render_text *) g_slist_last(render_texts)->data)->lines;
|
||||
GSList *last_lines =
|
||||
((render_text *) g_slist_last(render_texts)->data)->
|
||||
lines;
|
||||
GSList *last_line = g_slist_last(last_lines);
|
||||
char *old = last_line->data;
|
||||
char *new = g_strdup_printf("%s (%d more)", old, queue->length);
|
||||
char *new =
|
||||
g_strdup_printf("%s (%d more)", old, queue->length);
|
||||
free(old);
|
||||
last_line->data = new;
|
||||
}
|
||||
@ -859,18 +883,16 @@ GSList *generate_render_texts(int width)
|
||||
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);
|
||||
}
|
||||
|
||||
void free_render_texts(GSList *texts) {
|
||||
void free_render_texts(GSList * texts)
|
||||
{
|
||||
g_slist_free_full(texts, free_render_text);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void x_win_draw(void)
|
||||
{
|
||||
|
||||
@ -878,15 +900,15 @@ void x_win_draw(void)
|
||||
screen_info scr;
|
||||
x_screen_info(&scr);
|
||||
|
||||
|
||||
settings.line_height = MAX(settings.line_height, xctx.font_h);
|
||||
|
||||
int width;
|
||||
if (outer_width == 0)
|
||||
width = 0;
|
||||
else
|
||||
width = outer_width - (2 * settings.frame_width) - (2 * settings.h_padding);
|
||||
|
||||
width =
|
||||
outer_width - (2 * settings.frame_width) -
|
||||
(2 * settings.h_padding);
|
||||
|
||||
GSList *texts = generate_render_texts(width);
|
||||
int line_count = 0;
|
||||
@ -902,14 +924,18 @@ void x_win_draw(void)
|
||||
for (GSList * iiter = lines; iiter; iiter = iiter->next)
|
||||
width = MAX(width, textw(xctx.dc, iiter->data));
|
||||
}
|
||||
outer_width = width + (2 * settings.frame_width) + (2 * settings.h_padding);
|
||||
outer_width =
|
||||
width + (2 * settings.frame_width) +
|
||||
(2 * settings.h_padding);
|
||||
}
|
||||
|
||||
/* resize xctx.dc to correct width */
|
||||
|
||||
int height = (line_count * settings.line_height)
|
||||
+ displayed->length * 2 * settings.padding
|
||||
+ ((settings.indicate_hidden && queue->length > 0 && xctx.geometry.h != 1) ? 2 * settings.padding : 0)
|
||||
+
|
||||
((settings.indicate_hidden && queue->length > 0
|
||||
&& xctx.geometry.h != 1) ? 2 * settings.padding : 0)
|
||||
+ (settings.separator_height * (displayed->length - 1))
|
||||
+ (2 * settings.frame_width);
|
||||
|
||||
@ -933,7 +959,6 @@ void x_win_draw(void)
|
||||
render_text *cur = iter->data;
|
||||
ColorSet *colors = cur->colors;
|
||||
|
||||
|
||||
int line_count = 0;
|
||||
bool first_line = true;
|
||||
for (GSList * iiter = cur->lines; iiter; iiter = iiter->next) {
|
||||
@ -951,17 +976,23 @@ void x_win_draw(void)
|
||||
xctx.dc->x = settings.frame_width;
|
||||
|
||||
/* draw background */
|
||||
drawrect(xctx.dc, 0, 0, width + (2*settings.h_padding), pad + settings.line_height, true, colors->BG);
|
||||
drawrect(xctx.dc, 0, 0,
|
||||
width + (2 * settings.h_padding),
|
||||
pad + settings.line_height, true, colors->BG);
|
||||
|
||||
/* draw text */
|
||||
xctx.dc->x = calculate_x_offset(width, textw(xctx.dc, line));
|
||||
xctx.dc->x =
|
||||
calculate_x_offset(width, textw(xctx.dc, line));
|
||||
|
||||
xctx.dc->y += ((settings.line_height - xctx.font_h) / 2);
|
||||
xctx.dc->y +=
|
||||
((settings.line_height - xctx.font_h) / 2);
|
||||
xctx.dc->y += first_line ? settings.padding : 0;
|
||||
|
||||
drawtextn(xctx.dc, line, strlen(line), colors);
|
||||
|
||||
xctx.dc->y += settings.line_height - ((settings.line_height - xctx.font_h) / 2);
|
||||
xctx.dc->y +=
|
||||
settings.line_height -
|
||||
((settings.line_height - xctx.font_h) / 2);
|
||||
xctx.dc->y += last_line ? settings.padding : 0;
|
||||
|
||||
first_line = false;
|
||||
@ -981,7 +1012,9 @@ void x_win_draw(void)
|
||||
/* CUSTOM */
|
||||
color = xctx.sep_custom_col;
|
||||
}
|
||||
drawrect(xctx.dc, 0, 0, width + (2*settings.h_padding), settings.separator_height, true, color);
|
||||
drawrect(xctx.dc, 0, 0,
|
||||
width + (2 * settings.h_padding),
|
||||
settings.separator_height, true, color);
|
||||
xctx.dc->y += settings.separator_height;
|
||||
}
|
||||
}
|
||||
@ -1020,13 +1053,17 @@ void x_win_setup(void)
|
||||
xctx.win =
|
||||
XCreateWindow(xctx.dc->dpy, root, scr.dim.x, scr.dim.y, scr.dim.w,
|
||||
xctx.font_h, 0, DefaultDepth(xctx.dc->dpy,
|
||||
DefaultScreen(xctx.dc->dpy)),
|
||||
DefaultScreen(xctx.dc->
|
||||
dpy)),
|
||||
CopyFromParent, DefaultVisual(xctx.dc->dpy,
|
||||
DefaultScreen(xctx.dc->dpy)),
|
||||
DefaultScreen(xctx.dc->
|
||||
dpy)),
|
||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
||||
settings.transparency = settings.transparency > 100 ? 100 : settings.transparency;
|
||||
settings.transparency =
|
||||
settings.transparency > 100 ? 100 : settings.transparency;
|
||||
setopacity(xctx.dc, xctx.win,
|
||||
(unsigned long)((100 - settings.transparency) * (0xffffffff / 100)));
|
||||
(unsigned long)((100 - settings.transparency) *
|
||||
(0xffffffff / 100)));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1069,9 +1106,6 @@ void x_win_hide()
|
||||
xctx.visible = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Parse a string into a modifier mask.
|
||||
*/
|
||||
|
4
x.h
4
x.h
@ -46,7 +46,6 @@ DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#include <X11/Xft/Xft.h>
|
||||
|
||||
|
||||
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
|
||||
#define FONT_HEIGHT_BORDER 2
|
||||
#define DEFFONT "Monospace-11"
|
||||
@ -155,7 +154,8 @@ void x_screen_info(screen_info *scr);
|
||||
bool x_is_idle(void);
|
||||
void x_setup(void);
|
||||
|
||||
gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data);
|
||||
gboolean x_mainloop_fd_dispatch(GSource * source, GSourceFunc callback,
|
||||
gpointer user_data);
|
||||
gboolean x_mainloop_fd_check(GSource * source);
|
||||
gboolean x_mainloop_fd_prepare(GSource * source, gint * timeout);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user