indent -linx --no-tabs
This commit is contained in:
parent
b8004f56d8
commit
e82da9d5e7
41
config.def.h
41
config.def.h
@ -23,13 +23,13 @@ int sticky_history = True;
|
||||
int verbosity = 0;
|
||||
int word_wrap = False;
|
||||
int ignore_newline = False;
|
||||
int line_height = 0; /* if line height < font height, it will be raised to font height */
|
||||
int line_height = 0; /* if line height < font height, it will be raised to font height */
|
||||
|
||||
int separator_height = 2; /* height of the separator line between two notifications */
|
||||
int separator_height = 2; /* height of the separator line between two notifications */
|
||||
int padding = 0;
|
||||
int h_padding = 0; /* horizontal padding */
|
||||
enum separator_color sep_color = AUTO; /* AUTO, FOREGROUND, FRAME, CUSTOM */
|
||||
char *sep_custom_color_str = NULL; /* custom color if sep_color is set to CUSTOM */
|
||||
int h_padding = 0; /* horizontal padding */
|
||||
enum separator_color sep_color = AUTO; /* AUTO, FOREGROUND, FRAME, CUSTOM */
|
||||
char *sep_custom_color_str = NULL; /* custom color if sep_color is set to CUSTOM */
|
||||
|
||||
int frame_width = 0;
|
||||
char *frame_color = "#888888";
|
||||
@ -39,7 +39,6 @@ char *frame_color = "#888888";
|
||||
* */
|
||||
int startup_notification = False;
|
||||
|
||||
|
||||
/* monitor to display notifications on */
|
||||
int monitor = 0;
|
||||
|
||||
@ -63,25 +62,29 @@ 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 */
|
||||
/* name can be any unique string. It is used to identify the rule in dunstrc to override it there */
|
||||
|
||||
/* name, appname, summary, body, icon, timeout, urgency, fg, bg, format, script */
|
||||
{ "empty", NULL, NULL, NULL, NULL, -1, -1, NULL, NULL, NULL, NULL},
|
||||
/* { "rule1", "notify-send", NULL, NULL, NULL, -1, -1, NULL, NULL, "%s %b", NULL }, */
|
||||
/* { "rule2", "Pidgin", "*says*, NULL, NULL, -1, CRITICAL, NULL, NULL, NULL, NULL }, */
|
||||
/* { "rule3", "Pidgin", "*signed on*", NULL, NULL, -1, LOW, NULL, NULL, NULL, NULL }, */
|
||||
/* { "rule4", "Pidgin", "*signed off*", NULL, NULL, -1, LOW, NULL, NULL, NULL, NULL }, */
|
||||
/* { "rule5", NULL, "*foobar*", NULL, NULL, -1, -1, NULL, "#00FF00", NULL, NULL }, */
|
||||
};
|
||||
/* name, appname, summary, body, icon, timeout, urgency, fg, bg, format, script */
|
||||
{"empty", NULL, NULL, NULL, NULL, -1, -1, NULL, NULL, NULL, NULL},
|
||||
/* { "rule1", "notify-send", NULL, NULL, NULL, -1, -1, NULL, NULL, "%s %b", NULL }, */
|
||||
/* { "rule2", "Pidgin", "*says*, NULL, NULL, -1, CRITICAL, NULL, NULL, NULL, NULL }, */
|
||||
/* { "rule3", "Pidgin", "*signed on*", NULL, NULL, -1, LOW, NULL, NULL, NULL, NULL }, */
|
||||
/* { "rule4", "Pidgin", "*signed off*", NULL, NULL, -1, LOW, NULL, NULL, NULL, NULL }, */
|
||||
/* { "rule5", NULL, "*foobar*", NULL, NULL, -1, -1, NULL, "#00FF00", NULL, NULL }, */
|
||||
};
|
||||
|
345
dbus.c
345
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,98 +26,85 @@ 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);
|
||||
static void onCloseNotification(GDBusConnection * connection,
|
||||
const gchar * sender,
|
||||
GVariant * parameters,
|
||||
GDBusMethodInvocation * invocation);
|
||||
static void onGetServerInformation(GDBusConnection * connection,
|
||||
const gchar * sender,
|
||||
const GVariant * parameters,
|
||||
GDBusMethodInvocation * invocation);
|
||||
|
||||
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);
|
||||
static void onCloseNotification(GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation);
|
||||
static void onGetServerInformation(GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
const GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation);
|
||||
|
||||
void handle_method_call(GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
const gchar *object_path,
|
||||
const gchar *interface_name,
|
||||
const gchar *method_name,
|
||||
GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation,
|
||||
gpointer user_data)
|
||||
void handle_method_call(GDBusConnection * connection,
|
||||
const gchar * sender,
|
||||
const gchar * object_path,
|
||||
const gchar * interface_name,
|
||||
const gchar * method_name,
|
||||
GVariant * parameters,
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void onGetCapabilities(GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
const GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation)
|
||||
static void onGetCapabilities(GDBusConnection * connection,
|
||||
const gchar * sender,
|
||||
const GVariant * parameters,
|
||||
GDBusMethodInvocation * invocation)
|
||||
{
|
||||
GVariantBuilder *builder;
|
||||
GVariant *value;
|
||||
|
||||
builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
|
||||
g_variant_builder_add (builder, "s", "actions");
|
||||
g_variant_builder_add (builder, "s", "body");
|
||||
value = g_variant_new ("(as)", builder);
|
||||
g_variant_builder_unref (builder);
|
||||
builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
|
||||
g_variant_builder_add(builder, "s", "actions");
|
||||
g_variant_builder_add(builder, "s", "body");
|
||||
value = g_variant_new("(as)", builder);
|
||||
g_variant_builder_unref(builder);
|
||||
g_dbus_method_invocation_return_value(invocation, value);
|
||||
|
||||
g_dbus_connection_flush(connection, NULL, NULL, NULL);
|
||||
g_variant_unref(value);
|
||||
}
|
||||
|
||||
static void onNotify(GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation)
|
||||
static void onNotify(GDBusConnection * connection,
|
||||
const gchar * sender,
|
||||
GVariant * parameters, GDBusMethodInvocation * invocation)
|
||||
{
|
||||
|
||||
gchar *appname = NULL;
|
||||
@ -146,53 +132,83 @@ static void onNotify(GDBusConnection *connection,
|
||||
while ((content = g_variant_iter_next_value(iter))) {
|
||||
|
||||
switch (idx) {
|
||||
case 0:
|
||||
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);
|
||||
break;
|
||||
case 2:
|
||||
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);
|
||||
break;
|
||||
case 4:
|
||||
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));
|
||||
break;
|
||||
case 6:
|
||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_DICTIONARY)) {
|
||||
case 0:
|
||||
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);
|
||||
break;
|
||||
case 2:
|
||||
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);
|
||||
break;
|
||||
case 4:
|
||||
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));
|
||||
break;
|
||||
case 6:
|
||||
if (g_variant_is_of_type
|
||||
(content, G_VARIANT_TYPE_DICTIONARY)) {
|
||||
|
||||
dict_value = g_variant_lookup_value(content, "urgency", G_VARIANT_TYPE_BYTE);
|
||||
if (dict_value)
|
||||
urgency = g_variant_get_byte(dict_value);
|
||||
dict_value =
|
||||
g_variant_lookup_value(content,
|
||||
"urgency",
|
||||
G_VARIANT_TYPE_BYTE);
|
||||
if (dict_value)
|
||||
urgency =
|
||||
g_variant_get_byte
|
||||
(dict_value);
|
||||
|
||||
dict_value = g_variant_lookup_value(content, "fgcolor", G_VARIANT_TYPE_STRING);
|
||||
if (dict_value)
|
||||
fgcolor = g_variant_dup_string(dict_value, NULL);
|
||||
dict_value =
|
||||
g_variant_lookup_value(content,
|
||||
"fgcolor",
|
||||
G_VARIANT_TYPE_STRING);
|
||||
if (dict_value)
|
||||
fgcolor =
|
||||
g_variant_dup_string
|
||||
(dict_value, NULL);
|
||||
|
||||
dict_value = g_variant_lookup_value(content, "bgcolor", G_VARIANT_TYPE_STRING);
|
||||
if(dict_value)
|
||||
bgcolor = g_variant_dup_string(dict_value, NULL);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_INT32))
|
||||
timeout = g_variant_get_int32(content);
|
||||
break;
|
||||
dict_value =
|
||||
g_variant_lookup_value(content,
|
||||
"bgcolor",
|
||||
G_VARIANT_TYPE_STRING);
|
||||
if (dict_value)
|
||||
bgcolor =
|
||||
g_variant_dup_string
|
||||
(dict_value, NULL);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if (g_variant_is_of_type
|
||||
(content, G_VARIANT_TYPE_INT32))
|
||||
timeout = g_variant_get_int32(content);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
idx++;
|
||||
}
|
||||
|
||||
@ -209,7 +225,7 @@ static void onNotify(GDBusConnection *connection,
|
||||
}
|
||||
}
|
||||
|
||||
notification *n = malloc(sizeof (notification));
|
||||
notification *n = malloc(sizeof(notification));
|
||||
n->appname = appname;
|
||||
n->summary = summary;
|
||||
n->body = body;
|
||||
@ -219,10 +235,10 @@ static void onNotify(GDBusConnection *connection,
|
||||
n->urgency = urgency;
|
||||
n->dbus_client = strdup(sender);
|
||||
if (actions->count > 0) {
|
||||
n->actions = actions;
|
||||
n->actions = actions;
|
||||
} else {
|
||||
n->actions = NULL;
|
||||
free(actions);
|
||||
n->actions = NULL;
|
||||
free(actions);
|
||||
}
|
||||
|
||||
for (int i = 0; i < ColLast; i++) {
|
||||
@ -234,17 +250,17 @@ static void onNotify(GDBusConnection *connection,
|
||||
int id = notification_init(n, replaces_id);
|
||||
wake_up();
|
||||
|
||||
GVariant *reply = g_variant_new ("(u)", id);
|
||||
GVariant *reply = g_variant_new("(u)", id);
|
||||
g_dbus_method_invocation_return_value(invocation, reply);
|
||||
g_dbus_connection_flush(connection, NULL, NULL, NULL);
|
||||
|
||||
run(NULL);
|
||||
}
|
||||
|
||||
static void onCloseNotification(GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation)
|
||||
static void onCloseNotification(GDBusConnection * connection,
|
||||
const gchar * sender,
|
||||
GVariant * parameters,
|
||||
GDBusMethodInvocation * invocation)
|
||||
{
|
||||
guint32 id;
|
||||
g_variant_get(parameters, "(u)", &id);
|
||||
@ -253,14 +269,14 @@ static void onCloseNotification(GDBusConnection *connection,
|
||||
g_dbus_connection_flush(connection, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static void onGetServerInformation(GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
const GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation)
|
||||
static void onGetServerInformation(GDBusConnection * connection,
|
||||
const gchar * sender,
|
||||
const GVariant * parameters,
|
||||
GDBusMethodInvocation * invocation)
|
||||
{
|
||||
GVariant *value;
|
||||
|
||||
value = g_variant_new ("(ssss)", "dunst", "knopwob", VERSION, "1.2");
|
||||
value = g_variant_new("(ssss)", "dunst", "knopwob", VERSION, "1.2");
|
||||
g_dbus_method_invocation_return_value(invocation, value);
|
||||
|
||||
g_dbus_connection_flush(connection, NULL, NULL, NULL);
|
||||
@ -269,21 +285,18 @@ static void onGetServerInformation(GDBusConnection *connection,
|
||||
void notificationClosed(notification * n, int reason)
|
||||
{
|
||||
if (!dbus_conn) {
|
||||
printf("DEBUG: notificationClosed but not (yet) connected\n");
|
||||
return;
|
||||
printf("DEBUG: notificationClosed but not (yet) connected\n");
|
||||
return;
|
||||
}
|
||||
|
||||
GVariant *body = g_variant_new ("(uu)", n->id, reason);
|
||||
GVariant *body = g_variant_new("(uu)", n->id, reason);
|
||||
GError *err = NULL;
|
||||
|
||||
g_dbus_connection_emit_signal(
|
||||
dbus_conn,
|
||||
n->dbus_client,
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications",
|
||||
"NotificationClosed",
|
||||
body,
|
||||
&err);
|
||||
g_dbus_connection_emit_signal(dbus_conn,
|
||||
n->dbus_client,
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications",
|
||||
"NotificationClosed", body, &err);
|
||||
|
||||
if (err) {
|
||||
printf("notificationClosed ERROR\n");
|
||||
@ -291,60 +304,52 @@ void notificationClosed(notification * n, int reason)
|
||||
|
||||
}
|
||||
|
||||
void actionInvoked(notification *n, const char *identifier)
|
||||
void actionInvoked(notification * n, const char *identifier)
|
||||
{
|
||||
GVariant *body = g_variant_new ("(us)", n->id, identifier);
|
||||
GVariant *body = g_variant_new("(us)", n->id, identifier);
|
||||
GError *err = NULL;
|
||||
|
||||
g_dbus_connection_emit_signal(
|
||||
dbus_conn,
|
||||
n->dbus_client,
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications",
|
||||
"ActionInvoked",
|
||||
body,
|
||||
&err);
|
||||
g_dbus_connection_emit_signal(dbus_conn,
|
||||
n->dbus_client,
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications",
|
||||
"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)
|
||||
static void on_bus_acquired(GDBusConnection * connection,
|
||||
const gchar * name, gpointer user_data)
|
||||
{
|
||||
guint registration_id;
|
||||
|
||||
registration_id = g_dbus_connection_register_object( connection,
|
||||
"/org/freedesktop/Notifications",
|
||||
introspection_data->interfaces[0],
|
||||
&interface_vtable,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
registration_id = g_dbus_connection_register_object(connection,
|
||||
"/org/freedesktop/Notifications",
|
||||
introspection_data->
|
||||
interfaces[0],
|
||||
&interface_vtable,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
if (! registration_id > 0) {
|
||||
if (!registration_id > 0) {
|
||||
fprintf(stderr, "Unable to register\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_name_acquired(GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
static void on_name_acquired(GDBusConnection * connection,
|
||||
const gchar * name, gpointer user_data)
|
||||
{
|
||||
dbus_conn = connection;
|
||||
}
|
||||
|
||||
static void on_name_lost(GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
static void on_name_lost(GDBusConnection * connection,
|
||||
const gchar * name, gpointer user_data)
|
||||
{
|
||||
fprintf(stderr, "Name Lost\n");
|
||||
exit(1);
|
||||
@ -357,22 +362,20 @@ int initdbus(void)
|
||||
g_type_init();
|
||||
|
||||
introspection_data = g_dbus_node_info_new_for_xml(introspection_xml,
|
||||
NULL);
|
||||
NULL);
|
||||
|
||||
owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
||||
"org.freedesktop.Notifications",
|
||||
G_BUS_NAME_OWNER_FLAGS_NONE,
|
||||
on_bus_acquired,
|
||||
on_name_acquired,
|
||||
on_name_lost,
|
||||
NULL,
|
||||
NULL);
|
||||
owner_id = g_bus_own_name(G_BUS_TYPE_SESSION,
|
||||
"org.freedesktop.Notifications",
|
||||
G_BUS_NAME_OWNER_FLAGS_NONE,
|
||||
on_bus_acquired,
|
||||
on_name_acquired, on_name_lost, NULL, NULL);
|
||||
|
||||
return owner_id;
|
||||
}
|
||||
|
||||
void dbus_tear_down(int owner_id)
|
||||
{
|
||||
g_bus_unown_name(owner_id);
|
||||
g_bus_unown_name(owner_id);
|
||||
}
|
||||
|
||||
/* vim: set ts=8 sw=8 tw=0: */
|
||||
|
2
dbus.h
2
dbus.h
@ -11,7 +11,7 @@ int initdbus(void);
|
||||
void dbus_tear_down(int id);
|
||||
/* void dbus_poll(int timeout); */
|
||||
void notificationClosed(notification * n, int reason);
|
||||
void actionInvoked(notification *n, const char *identifier);
|
||||
void actionInvoked(notification * n, const char *identifier);
|
||||
|
||||
#endif
|
||||
|
||||
|
81
dunst.c
81
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 */
|
||||
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) {
|
||||
@ -205,7 +186,7 @@ void update(void)
|
||||
|
||||
/* move messages from notification_queue to displayed_notifications */
|
||||
update_lists();
|
||||
if (displayed->length > 0 && ! xctx.visible) {
|
||||
if (displayed->length > 0 && !xctx.visible) {
|
||||
x_win_show();
|
||||
}
|
||||
if (displayed->length == 0 && xctx.visible) {
|
||||
@ -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")
|
||||
@ -282,11 +258,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
x_setup();
|
||||
|
||||
signal (SIGUSR1, pause_signal_handler);
|
||||
signal (SIGUSR2, pause_signal_handler);
|
||||
signal(SIGUSR1, pause_signal_handler);
|
||||
signal(SIGUSR2, pause_signal_handler);
|
||||
|
||||
if (settings.startup_notification) {
|
||||
notification *n = malloc(sizeof (notification));
|
||||
notification *n = malloc(sizeof(notification));
|
||||
n->appname = "dunst";
|
||||
n->summary = "startup";
|
||||
n->body = "dunst is up and running";
|
||||
@ -305,8 +281,9 @@ 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 };
|
||||
GPollFD dpy_pollfd = { xctx.dc->dpy->fd,
|
||||
G_IO_IN | G_IO_HUP | G_IO_ERR, 0
|
||||
};
|
||||
|
||||
GSourceFuncs x11_source_funcs = {
|
||||
x_mainloop_fd_prepare,
|
||||
@ -314,20 +291,21 @@ 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));
|
||||
((x11_source_t*)x11_source)->dpy = xctx.dc->dpy;
|
||||
((x11_source_t*)x11_source)->w = xctx.win;
|
||||
g_source_add_poll(x11_source, &dpy_pollfd);
|
||||
g_source_new(&x11_source_funcs, sizeof(x11_source_t));
|
||||
((x11_source_t *) x11_source)->dpy = xctx.dc->dpy;
|
||||
((x11_source_t *) x11_source)->w = xctx.win;
|
||||
g_source_add_poll(x11_source, &dpy_pollfd);
|
||||
|
||||
g_source_attach(x11_source, NULL);
|
||||
g_source_attach(x11_source, NULL);
|
||||
|
||||
run(NULL);
|
||||
g_main_loop_run(mainloop);
|
||||
run(NULL);
|
||||
g_main_loop_run(mainloop);
|
||||
|
||||
dbus_tear_down(owner_id);
|
||||
dbus_tear_down(owner_id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -341,7 +319,7 @@ void pause_signal_handler(int sig)
|
||||
pause_display = false;
|
||||
}
|
||||
|
||||
signal (sig, pause_signal_handler);
|
||||
signal(sig, pause_signal_handler);
|
||||
}
|
||||
|
||||
void usage(int exit_status)
|
||||
@ -355,8 +333,9 @@ void usage(int exit_status)
|
||||
|
||||
void print_version(void)
|
||||
{
|
||||
printf("Dunst - A customizable and lightweight notification-daemon %s\n",
|
||||
VERSION);
|
||||
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);
|
||||
|
245
menu.c
245
menu.c
@ -12,81 +12,79 @@
|
||||
#include "settings.h"
|
||||
#include "dbus.h"
|
||||
|
||||
|
||||
/*
|
||||
* Exctract all urls from a given string.
|
||||
*
|
||||
* Return: a string of urls separated by \n
|
||||
*
|
||||
*/
|
||||
char *extract_urls( const char * to_match)
|
||||
char *extract_urls(const char *to_match)
|
||||
{
|
||||
static bool is_initialized = false;
|
||||
static regex_t cregex;
|
||||
static bool is_initialized = false;
|
||||
static regex_t cregex;
|
||||
|
||||
if (!is_initialized) {
|
||||
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");
|
||||
return NULL;
|
||||
} else {
|
||||
is_initialized = true;
|
||||
if (!is_initialized) {
|
||||
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");
|
||||
return NULL;
|
||||
} else {
|
||||
is_initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char *urls = NULL;
|
||||
char *urls = NULL;
|
||||
|
||||
const char * p = to_match;
|
||||
regmatch_t m;
|
||||
const char *p = to_match;
|
||||
regmatch_t m;
|
||||
|
||||
while (1) {
|
||||
int nomatch = regexec (&cregex, p, 1, &m, 0);
|
||||
if (nomatch) {
|
||||
return urls;
|
||||
while (1) {
|
||||
int nomatch = regexec(&cregex, p, 1, &m, 0);
|
||||
if (nomatch) {
|
||||
return urls;
|
||||
}
|
||||
int start;
|
||||
int finish;
|
||||
if (m.rm_so == -1) {
|
||||
break;
|
||||
}
|
||||
start = m.rm_so + (p - to_match);
|
||||
finish = m.rm_eo + (p - to_match);
|
||||
|
||||
char *match = strndup(to_match + start, finish - start);
|
||||
|
||||
urls = string_append(urls, match, "\n");
|
||||
|
||||
p += m.rm_eo;
|
||||
}
|
||||
int start;
|
||||
int finish;
|
||||
if (m.rm_so == -1) {
|
||||
break;
|
||||
}
|
||||
start = m.rm_so + (p - to_match);
|
||||
finish = m.rm_eo + (p - to_match);
|
||||
|
||||
char *match = strndup(to_match+start, finish-start);
|
||||
|
||||
urls = string_append(urls, match, "\n");
|
||||
|
||||
p += m.rm_eo;
|
||||
}
|
||||
return urls;
|
||||
return urls;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Open url in browser.
|
||||
*
|
||||
*/
|
||||
void open_browser(const char *url)
|
||||
{
|
||||
int browser_pid1 = fork();
|
||||
int browser_pid1 = fork();
|
||||
|
||||
if (browser_pid1) {
|
||||
int status;
|
||||
waitpid(browser_pid1, &status, 0);
|
||||
} else {
|
||||
int browser_pid2 = fork();
|
||||
if (browser_pid2) {
|
||||
exit(0);
|
||||
if (browser_pid1) {
|
||||
int status;
|
||||
waitpid(browser_pid1, &status, 0);
|
||||
} else {
|
||||
char *browser_cmd = string_append(settings.browser, url, " ");
|
||||
char **cmd = g_strsplit(browser_cmd, " ", 0);
|
||||
execvp(cmd[0], cmd);
|
||||
int browser_pid2 = fork();
|
||||
if (browser_pid2) {
|
||||
exit(0);
|
||||
} else {
|
||||
char *browser_cmd =
|
||||
string_append(settings.browser, url, " ");
|
||||
char **cmd = g_strsplit(browser_cmd, " ", 0);
|
||||
execvp(cmd[0], cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Notify the corresponding client
|
||||
@ -94,38 +92,38 @@ if (browser_pid1) {
|
||||
*/
|
||||
void invoke_action(const char *action)
|
||||
{
|
||||
notification *invoked = NULL;
|
||||
char *action_identifier = NULL;
|
||||
notification *invoked = NULL;
|
||||
char *action_identifier = NULL;
|
||||
|
||||
char *name_begin = strstr(action, "(");
|
||||
if (!name_begin) {
|
||||
printf("invalid action: %s\n", action);
|
||||
return;
|
||||
}
|
||||
name_begin++;
|
||||
char *name_begin = strstr(action, "(");
|
||||
if (!name_begin) {
|
||||
printf("invalid action: %s\n", action);
|
||||
return;
|
||||
}
|
||||
name_begin++;
|
||||
|
||||
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)
|
||||
continue;
|
||||
|
||||
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)
|
||||
continue;
|
||||
for (int i = 0; i < n->actions->count; i += 2) {
|
||||
char *a_identifier = n->actions->actions[i];
|
||||
char *name = n->actions->actions[i + 1];
|
||||
if (g_str_has_prefix(name_begin, name)) {
|
||||
invoked = n;
|
||||
action_identifier = a_identifier;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n->actions->count; i += 2) {
|
||||
char *a_identifier = n->actions->actions[i];
|
||||
char *name = n->actions->actions[i+1];
|
||||
if (g_str_has_prefix(name_begin, name)) {
|
||||
invoked = n;
|
||||
action_identifier = a_identifier;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (invoked && action_identifier) {
|
||||
actionInvoked(invoked, action_identifier);
|
||||
}
|
||||
if (invoked && action_identifier) {
|
||||
actionInvoked(invoked, action_identifier);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -134,14 +132,14 @@ void invoke_action(const char *action)
|
||||
*/
|
||||
void dispatch_menu_result(const char *input)
|
||||
{
|
||||
char *maybe_url = extract_urls(input);
|
||||
if (maybe_url) {
|
||||
open_browser(maybe_url);
|
||||
free(maybe_url);
|
||||
return;
|
||||
}
|
||||
char *maybe_url = extract_urls(input);
|
||||
if (maybe_url) {
|
||||
open_browser(maybe_url);
|
||||
free(maybe_url);
|
||||
return;
|
||||
}
|
||||
|
||||
invoke_action(input);
|
||||
invoke_action(input);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -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;
|
||||
|
||||
@ -176,42 +176,39 @@ void context_menu(void)
|
||||
}
|
||||
int pid = fork();
|
||||
|
||||
if (pid == 0) {
|
||||
close(child_io[1]);
|
||||
if (pid == 0) {
|
||||
close(child_io[1]);
|
||||
close(parent_io[0]);
|
||||
close(0);
|
||||
if (dup(child_io[0]) == -1) {
|
||||
PERR("dup()", errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
close(1);
|
||||
if (dup(parent_io[1]) == -1) {
|
||||
PERR("dup()", errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
execvp(settings.dmenu_cmd[0], settings.dmenu_cmd);
|
||||
} else {
|
||||
close(child_io[0]);
|
||||
close(parent_io[1]);
|
||||
size_t wlen = strlen(dmenu_input);
|
||||
if (write(child_io[1], dmenu_input, wlen) != wlen) {
|
||||
PERR("write()", errno);
|
||||
}
|
||||
close(child_io[1]);
|
||||
|
||||
size_t len = read(parent_io[0], buf, 1023);
|
||||
if (len == 0)
|
||||
return;
|
||||
buf[len - 1] = '\0';
|
||||
|
||||
int status;
|
||||
waitpid(pid, &status, 0);
|
||||
}
|
||||
|
||||
close(parent_io[0]);
|
||||
close(0);
|
||||
if (dup(child_io[0]) == -1) {
|
||||
PERR("dup()", errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
close(1);
|
||||
if (dup(parent_io[1]) == -1) {
|
||||
PERR("dup()", errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
execvp(settings.dmenu_cmd[0], settings.dmenu_cmd);
|
||||
} else {
|
||||
close(child_io[0]);
|
||||
close(parent_io[1]);
|
||||
size_t wlen = strlen(dmenu_input);
|
||||
if (write(child_io[1], dmenu_input, wlen) != wlen) {
|
||||
PERR("write()", errno);
|
||||
}
|
||||
close(child_io[1]);
|
||||
|
||||
size_t len = read(parent_io[0], buf, 1023);
|
||||
if (len == 0)
|
||||
return;
|
||||
buf[len - 1] = '\0';
|
||||
|
||||
int status;
|
||||
waitpid(pid, &status, 0);
|
||||
}
|
||||
|
||||
close(parent_io[0]);
|
||||
|
||||
|
||||
dispatch_menu_result(buf);
|
||||
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");
|
||||
@ -62,7 +59,7 @@ void notification_print(notification * n)
|
||||
* Run the script associated with the
|
||||
* given notification.
|
||||
*/
|
||||
void notification_run_script(notification *n)
|
||||
void notification_run_script(notification * n)
|
||||
{
|
||||
if (!n->script || strlen(n->script) < 1)
|
||||
return;
|
||||
@ -74,18 +71,18 @@ void notification_run_script(notification *n)
|
||||
|
||||
char *urgency;
|
||||
switch (n->urgency) {
|
||||
case LOW:
|
||||
urgency = "LOW";
|
||||
break;
|
||||
case NORM:
|
||||
urgency = "NORMAL";
|
||||
break;
|
||||
case CRIT:
|
||||
urgency = "CRITICAL";
|
||||
break;
|
||||
default:
|
||||
urgency = "NORMAL";
|
||||
break;
|
||||
case LOW:
|
||||
urgency = "LOW";
|
||||
break;
|
||||
case NORM:
|
||||
urgency = "NORMAL";
|
||||
break;
|
||||
case CRIT:
|
||||
urgency = "CRITICAL";
|
||||
break;
|
||||
default:
|
||||
urgency = "NORMAL";
|
||||
break;
|
||||
}
|
||||
|
||||
int pid1 = fork();
|
||||
@ -99,13 +96,12 @@ void notification_run_script(notification *n)
|
||||
exit(0);
|
||||
} else {
|
||||
int ret = execlp(n->script, n->script,
|
||||
appname,
|
||||
summary,
|
||||
body,
|
||||
icon,
|
||||
urgency,
|
||||
(char *) NULL
|
||||
);
|
||||
appname,
|
||||
summary,
|
||||
body,
|
||||
icon,
|
||||
urgency,
|
||||
(char *)NULL);
|
||||
if (ret != 0) {
|
||||
PERR("Unable to run script", errno);
|
||||
exit(EXIT_FAILURE);
|
||||
@ -120,8 +116,8 @@ void notification_run_script(notification *n)
|
||||
*/
|
||||
int notification_cmp(const void *va, const void *vb)
|
||||
{
|
||||
notification *a = (notification*) va;
|
||||
notification *b = (notification*) vb;
|
||||
notification *a = (notification *) va;
|
||||
notification *b = (notification *) vb;
|
||||
|
||||
if (!settings.sort)
|
||||
return 1;
|
||||
@ -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];
|
||||
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,12 +37,11 @@ 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);
|
||||
int notification_cmp_data(const void *a, const void *b, void *data);
|
||||
void notification_run_script(notification *n);
|
||||
void notification_run_script(notification * n);
|
||||
int notification_close(notification * n, int reason);
|
||||
void notification_print(notification *n);
|
||||
void notification_print(notification * n);
|
||||
char *notification_fix_markup(char *str);
|
||||
|
@ -110,7 +110,7 @@ char *ini_get_string(char *section, char *key, const char *def)
|
||||
if (def == NULL)
|
||||
return NULL;
|
||||
else
|
||||
return def ? g_strdup(def) : NULL;
|
||||
return def ? g_strdup(def) : NULL;
|
||||
}
|
||||
|
||||
int ini_get_int(char *section, char *key, int def)
|
||||
@ -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);
|
||||
|
19
rules.c
19
rules.c
@ -7,7 +7,7 @@
|
||||
/*
|
||||
* Apply rule to notification.
|
||||
*/
|
||||
void rule_apply(rule_t *r, notification *n)
|
||||
void rule_apply(rule_t * r, notification * n)
|
||||
{
|
||||
if (r->timeout != -1)
|
||||
n->timeout = r->timeout;
|
||||
@ -26,9 +26,9 @@ void rule_apply(rule_t *r, notification *n)
|
||||
/*
|
||||
* Check all rules if they match n and apply.
|
||||
*/
|
||||
void rule_apply_all(notification *n)
|
||||
void rule_apply_all(notification * n)
|
||||
{
|
||||
for (GSList *iter = rules; iter; iter = iter->next) {
|
||||
for (GSList * iter = rules; iter; iter = iter->next) {
|
||||
rule_t *r = iter->data;
|
||||
if (rule_matches_notification(r, n)) {
|
||||
rule_apply(r, n);
|
||||
@ -39,7 +39,7 @@ void rule_apply_all(notification *n)
|
||||
/*
|
||||
* Initialize rule with default values.
|
||||
*/
|
||||
void rule_init(rule_t *r)
|
||||
void rule_init(rule_t * r)
|
||||
{
|
||||
r->name = NULL;
|
||||
r->appname = NULL;
|
||||
@ -53,15 +53,14 @@ void rule_init(rule_t *r)
|
||||
r->format = NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check whether rule should be applied to n.
|
||||
*/
|
||||
bool rule_matches_notification(rule_t *r, notification *n)
|
||||
bool rule_matches_notification(rule_t * r, notification * n)
|
||||
{
|
||||
|
||||
return ((!r->appname || !fnmatch(r->appname, n->appname, 0))
|
||||
&& (!r->summary || !fnmatch(r->summary, n->summary, 0))
|
||||
&& (!r->body || !fnmatch(r->body, n->body, 0))
|
||||
&& (!r->icon || !fnmatch(r->icon, n->icon, 0)));
|
||||
return ((!r->appname || !fnmatch(r->appname, n->appname, 0))
|
||||
&& (!r->summary || !fnmatch(r->summary, n->summary, 0))
|
||||
&& (!r->body || !fnmatch(r->body, n->body, 0))
|
||||
&& (!r->icon || !fnmatch(r->icon, n->icon, 0)));
|
||||
}
|
||||
|
8
rules.h
8
rules.h
@ -24,7 +24,7 @@ typedef struct _rule_t {
|
||||
|
||||
extern GSList *rules;
|
||||
|
||||
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);
|
||||
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);
|
||||
|
62
settings.c
62
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,9 +84,8 @@ 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", "",
|
||||
"Follow mouse, keyboard or none?");
|
||||
char *c = option_get_string("global", "follow", "-follow", "",
|
||||
"Follow mouse, keyboard or none?");
|
||||
if (strlen(c) > 0) {
|
||||
parse_follow_mode(c);
|
||||
free(c);
|
||||
@ -103,10 +103,9 @@ void load_settings(char *cmdline_config_path)
|
||||
bounce_freq,
|
||||
"Make long text bounce from side to side");
|
||||
{
|
||||
char *c =
|
||||
option_get_string("global", "alignment",
|
||||
"-align/-alignment", "",
|
||||
"Align notifications left/center/right");
|
||||
char *c = option_get_string("global", "alignment",
|
||||
"-align/-alignment", "",
|
||||
"Align notifications left/center/right");
|
||||
if (strlen(c) > 0) {
|
||||
if (strcmp(c, "left") == 0)
|
||||
settings.align = left;
|
||||
@ -134,18 +133,18 @@ void load_settings(char *cmdline_config_path)
|
||||
"height of the separator line");
|
||||
settings.padding =
|
||||
option_get_int("global", "padding", "-padding", padding,
|
||||
"Padding between text and separator");
|
||||
"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",
|
||||
"-sep_color/-separator_color", "",
|
||||
"Color of the separator line (or 'auto')");
|
||||
char *c = option_get_string("global", "separator_color",
|
||||
"-sep_color/-separator_color", "",
|
||||
"Color of the separator line (or 'auto')");
|
||||
if (strlen(c) > 0) {
|
||||
if (strcmp(c, "auto") == 0)
|
||||
settings.sep_color = AUTO;
|
||||
@ -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,
|
||||
"Width of frame around window");
|
||||
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,
|
||||
@ -222,9 +228,8 @@ void load_settings(char *cmdline_config_path)
|
||||
"Shortcut to pop the last notification from history");
|
||||
|
||||
settings.context_ks.str =
|
||||
option_get_string("shortcuts", "context", "-context_key",
|
||||
context_ks.str,
|
||||
"Shortcut for context menu");
|
||||
option_get_string("shortcuts", "context", "-context_key",
|
||||
context_ks.str, "Shortcut for context menu");
|
||||
|
||||
settings.print_notifications =
|
||||
cmdline_get_bool("-print", false,
|
||||
@ -249,7 +254,7 @@ void load_settings(char *cmdline_config_path)
|
||||
|
||||
/* check for existing rule with same name */
|
||||
rule_t *r = NULL;
|
||||
for (GSList *iter = rules; iter; iter = iter->next) {
|
||||
for (GSList * iter = rules; iter; iter = iter->next) {
|
||||
rule_t *match = iter->data;
|
||||
if (match->name &&
|
||||
strcmp(match->name, cur_section) == 0)
|
||||
@ -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();
|
||||
|
4
utils.c
4
utils.c
@ -14,7 +14,7 @@ char *string_replace_all(const char *needle, const char *replacement,
|
||||
{
|
||||
char *start;
|
||||
start = strstr(haystack, needle);
|
||||
while(start != NULL) {
|
||||
while (start != NULL) {
|
||||
haystack = string_replace(needle, replacement, haystack);
|
||||
start = strstr(haystack, needle);
|
||||
}
|
||||
@ -51,7 +51,7 @@ char *string_append(char *a, const char *b, const char *sep)
|
||||
|
||||
char *new;
|
||||
if (!sep)
|
||||
new = g_strconcat(a,b, NULL);
|
||||
new = g_strconcat(a, b, NULL);
|
||||
else
|
||||
new = g_strconcat(a, sep, b, NULL);
|
||||
free(a);
|
||||
|
226
x.c
226
x.c
@ -301,32 +301,30 @@ 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
|
||||
*/
|
||||
gboolean x_mainloop_fd_prepare(GSource *source, gint *timeout)
|
||||
gboolean x_mainloop_fd_prepare(GSource * source, gint * timeout)
|
||||
{
|
||||
*timeout = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Helper function to use glib's mainloop mechanic
|
||||
* with Xlib
|
||||
*/
|
||||
gboolean x_mainloop_fd_check(GSource *source)
|
||||
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
|
||||
@ -509,7 +519,7 @@ int select_screen(XineramaScreenInfo * info, int info_len)
|
||||
* Update the information about the monitor
|
||||
* geometry.
|
||||
*/
|
||||
void x_screen_info(screen_info *scr)
|
||||
void x_screen_info(screen_info * scr)
|
||||
{
|
||||
#ifdef XINERAMA
|
||||
int n;
|
||||
@ -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;
|
||||
}
|
||||
@ -593,19 +603,15 @@ void x_setup(void)
|
||||
}
|
||||
|
||||
xctx.geometry.mask = XParseGeometry(settings.geom,
|
||||
&xctx.geometry.x, &xctx.geometry.y,
|
||||
&xctx.geometry.w, &xctx.geometry.h);
|
||||
|
||||
&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,24 +660,21 @@ GSList *do_word_wrap(char *text, int max_width)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
char *generate_final_text(notification *n)
|
||||
char *generate_final_text(notification * n)
|
||||
{
|
||||
char *msg = g_strstrip(n->msg);
|
||||
char *buf;
|
||||
|
||||
/* print dup_count and msg*/
|
||||
/* print dup_count and msg */
|
||||
if (n->dup_count > 0 && (n->actions || n->urls)) {
|
||||
buf = g_strdup_printf("(%d%s%s) %s",
|
||||
n->dup_count,
|
||||
n->actions ? "A" : "",
|
||||
n->urls ? "U" : "",
|
||||
msg);
|
||||
n->dup_count,
|
||||
n->actions ? "A" : "",
|
||||
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->actions ? "A" : "",
|
||||
n->urls ? "U" : "", msg);
|
||||
} else {
|
||||
buf = g_strdup(msg);
|
||||
}
|
||||
@ -675,18 +683,21 @@ 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,
|
||||
minutes, seconds);
|
||||
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,
|
||||
seconds);
|
||||
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;
|
||||
@ -792,7 +807,7 @@ int calculate_width(void)
|
||||
void move_and_map(int width, int height)
|
||||
{
|
||||
|
||||
int x,y;
|
||||
int x, y;
|
||||
screen_info scr;
|
||||
x_screen_info(&scr);
|
||||
/* calculate window position */
|
||||
@ -829,10 +844,11 @@ 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;
|
||||
rt->colors = ((notification *) iter->data)->colors;
|
||||
char *text = generate_final_text(iter->data);
|
||||
rt->lines = do_word_wrap(text, width);
|
||||
free(text);
|
||||
@ -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,40 +900,44 @@ 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;
|
||||
for (GSList *iter = texts; iter; iter = iter->next) {
|
||||
for (GSList * iter = texts; iter; iter = iter->next) {
|
||||
render_text *tmp = iter->data;
|
||||
line_count += g_slist_length(tmp->lines);
|
||||
}
|
||||
|
||||
/* if we have a dynamic width, calculate the actual width */
|
||||
if (width == 0) {
|
||||
for (GSList *iter = texts; iter; iter = iter->next) {
|
||||
for (GSList * iter = texts; iter; iter = iter->next) {
|
||||
GSList *lines = ((render_text *) iter->data)->lines;
|
||||
for (GSList *iiter = lines; iiter; iiter = iiter->next)
|
||||
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.separator_height * (displayed->length - 1))
|
||||
+ (2 * settings.frame_width);
|
||||
+ displayed->length * 2 * settings.padding
|
||||
+
|
||||
((settings.indicate_hidden && queue->length > 0
|
||||
&& xctx.geometry.h != 1) ? 2 * settings.padding : 0)
|
||||
+ (settings.separator_height * (displayed->length - 1))
|
||||
+ (2 * settings.frame_width);
|
||||
|
||||
resizedc(xctx.dc, outer_width, height);
|
||||
|
||||
@ -928,15 +954,14 @@ void x_win_draw(void)
|
||||
xctx.dc->y = settings.frame_width;
|
||||
xctx.dc->x = settings.frame_width;
|
||||
|
||||
for (GSList *iter = texts; iter; iter = iter->next) {
|
||||
for (GSList * iter = texts; iter; iter = iter->next) {
|
||||
|
||||
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) {
|
||||
for (GSList * iiter = cur->lines; iiter; iiter = iiter->next) {
|
||||
char *line = iiter->data;
|
||||
line_count++;
|
||||
|
||||
@ -944,24 +969,30 @@ void x_win_draw(void)
|
||||
bool last_line = iiter->next == NULL;
|
||||
|
||||
if (first_line && last_line)
|
||||
pad = 2*settings.padding;
|
||||
pad = 2 * settings.padding;
|
||||
else if (first_line || last_line)
|
||||
pad = settings.padding;
|
||||
|
||||
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.
|
||||
*/
|
||||
@ -1139,7 +1173,7 @@ static int x_shortcut_tear_down_error_handler(void)
|
||||
/*
|
||||
* Grab the given keyboard shortcut.
|
||||
*/
|
||||
int x_shortcut_grab(keyboard_shortcut *ks)
|
||||
int x_shortcut_grab(keyboard_shortcut * ks)
|
||||
{
|
||||
if (!ks->is_valid)
|
||||
return 1;
|
||||
@ -1163,7 +1197,7 @@ int x_shortcut_grab(keyboard_shortcut *ks)
|
||||
/*
|
||||
* Ungrab the given keyboard shortcut.
|
||||
*/
|
||||
void x_shortcut_ungrab(keyboard_shortcut *ks)
|
||||
void x_shortcut_ungrab(keyboard_shortcut * ks)
|
||||
{
|
||||
Window root;
|
||||
root = RootWindow(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
||||
@ -1174,7 +1208,7 @@ void x_shortcut_ungrab(keyboard_shortcut *ks)
|
||||
/*
|
||||
* Initialize the keyboard shortcut.
|
||||
*/
|
||||
void x_shortcut_init(keyboard_shortcut *ks)
|
||||
void x_shortcut_init(keyboard_shortcut * ks)
|
||||
{
|
||||
if (ks == NULL || ks->str == NULL)
|
||||
return;
|
||||
|
16
x.h
16
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"
|
||||
@ -144,20 +143,21 @@ void x_win_show(void);
|
||||
void x_win_setup(void);
|
||||
|
||||
/* shortcut */
|
||||
void x_shortcut_init(keyboard_shortcut *shortcut);
|
||||
void x_shortcut_ungrab(keyboard_shortcut *ks);
|
||||
int x_shortcut_grab(keyboard_shortcut *ks);
|
||||
void x_shortcut_init(keyboard_shortcut * shortcut);
|
||||
void x_shortcut_ungrab(keyboard_shortcut * ks);
|
||||
int x_shortcut_grab(keyboard_shortcut * ks);
|
||||
KeySym x_shortcut_string_to_mask(const char *str);
|
||||
|
||||
/* X misc */
|
||||
void x_handle_click(XEvent ev);
|
||||
void x_screen_info(screen_info *scr);
|
||||
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_check(GSource *source);
|
||||
gboolean x_mainloop_fd_prepare(GSource *source, gint *timeout);
|
||||
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);
|
||||
|
||||
#endif
|
||||
/* vim: set ts=8 sw=8 tw=0: */
|
||||
|
Loading…
x
Reference in New Issue
Block a user