indent -linx --no-tabs
This commit is contained in:
parent
b8004f56d8
commit
e82da9d5e7
17
config.def.h
17
config.def.h
@ -39,7 +39,6 @@ char *frame_color = "#888888";
|
|||||||
* */
|
* */
|
||||||
int startup_notification = False;
|
int startup_notification = False;
|
||||||
|
|
||||||
|
|
||||||
/* monitor to display notifications on */
|
/* monitor to display notifications on */
|
||||||
int monitor = 0;
|
int monitor = 0;
|
||||||
|
|
||||||
@ -63,25 +62,29 @@ enum follow_mode f_mode = FOLLOW_NONE;
|
|||||||
* use "none" to disable
|
* use "none" to disable
|
||||||
*/
|
*/
|
||||||
keyboard_shortcut close_ks = {.str = "none",
|
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",
|
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",
|
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",
|
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[] = {
|
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 */
|
/* name, appname, summary, body, icon, timeout, urgency, fg, bg, format, script */
|
||||||
{ "empty", NULL, NULL, NULL, NULL, -1, -1, NULL, NULL, NULL, NULL},
|
{"empty", NULL, NULL, NULL, NULL, -1, -1, NULL, NULL, NULL, NULL},
|
||||||
/* { "rule1", "notify-send", NULL, NULL, NULL, -1, -1, NULL, NULL, "%s %b", 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 }, */
|
/* { "rule2", "Pidgin", "*says*, NULL, NULL, -1, CRITICAL, NULL, NULL, NULL, NULL }, */
|
||||||
/* { "rule3", "Pidgin", "*signed on*", NULL, NULL, -1, LOW, 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 }, */
|
/* { "rule4", "Pidgin", "*signed off*", NULL, NULL, -1, LOW, NULL, NULL, NULL, NULL }, */
|
||||||
/* { "rule5", NULL, "*foobar*", NULL, NULL, -1, -1, NULL, "#00FF00", NULL, NULL }, */
|
/* { "rule5", NULL, "*foobar*", NULL, NULL, -1, -1, NULL, "#00FF00", NULL, NULL }, */
|
||||||
};
|
};
|
||||||
|
269
dbus.c
269
dbus.c
@ -10,14 +10,13 @@ GDBusConnection *dbus_conn;
|
|||||||
|
|
||||||
static GDBusNodeInfo *introspection_data = NULL;
|
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\">"
|
"<node name=\"/org/freedesktop/Notifications\">"
|
||||||
" <interface name=\"org.freedesktop.Notifications\">"
|
" <interface name=\"org.freedesktop.Notifications\">" " "
|
||||||
" "
|
|
||||||
" <method name=\"GetCapabilities\">"
|
" <method name=\"GetCapabilities\">"
|
||||||
" <arg direction=\"out\" name=\"capabilities\" type=\"as\"/>"
|
" <arg direction=\"out\" name=\"capabilities\" type=\"as\"/>"
|
||||||
" </method>"
|
" </method>" " <method name=\"Notify\">"
|
||||||
" <method name=\"Notify\">"
|
|
||||||
" <arg direction=\"in\" name=\"app_name\" type=\"s\"/>"
|
" <arg direction=\"in\" name=\"app_name\" type=\"s\"/>"
|
||||||
" <arg direction=\"in\" name=\"replaces_id\" type=\"u\"/>"
|
" <arg direction=\"in\" name=\"replaces_id\" type=\"u\"/>"
|
||||||
" <arg direction=\"in\" name=\"app_icon\" type=\"s\"/>"
|
" <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=\"hints\" type=\"a{sv}\"/>"
|
||||||
" <arg direction=\"in\" name=\"expire_timeout\" type=\"i\"/>"
|
" <arg direction=\"in\" name=\"expire_timeout\" type=\"i\"/>"
|
||||||
" <arg direction=\"out\" name=\"id\" type=\"u\"/>"
|
" <arg direction=\"out\" name=\"id\" type=\"u\"/>"
|
||||||
" </method>"
|
" </method>" " " " <method name=\"CloseNotification\">"
|
||||||
" "
|
|
||||||
" <method name=\"CloseNotification\">"
|
|
||||||
" <arg direction=\"in\" name=\"id\" type=\"u\"/>"
|
" <arg direction=\"in\" name=\"id\" type=\"u\"/>"
|
||||||
" </method>"
|
" </method>" " <method name=\"GetServerInformation\">"
|
||||||
" <method name=\"GetServerInformation\">"
|
|
||||||
" <arg direction=\"out\" name=\"name\" type=\"s\"/>"
|
" <arg direction=\"out\" name=\"name\" type=\"s\"/>"
|
||||||
" <arg direction=\"out\" name=\"vendor\" type=\"s\"/>"
|
" <arg direction=\"out\" name=\"vendor\" type=\"s\"/>"
|
||||||
" <arg direction=\"out\" name=\"version\" type=\"s\"/>"
|
" <arg direction=\"out\" name=\"version\" type=\"s\"/>"
|
||||||
" <arg direction=\"out\" name=\"spec_version\" type=\"s\"/>"
|
" <arg direction=\"out\" name=\"spec_version\" type=\"s\"/>"
|
||||||
" </method>"
|
" </method>" " <signal name=\"NotificationClosed\">"
|
||||||
" <signal name=\"NotificationClosed\">"
|
|
||||||
" <arg name=\"id\" type=\"u\"/>"
|
" <arg name=\"id\" type=\"u\"/>"
|
||||||
" <arg name=\"reason\" type=\"u\"/>"
|
" <arg name=\"reason\" type=\"u\"/>" " </signal>"
|
||||||
" </signal>"
|
|
||||||
" <signal name=\"ActionInvoked\">"
|
" <signal name=\"ActionInvoked\">"
|
||||||
" <arg name=\"id\" type=\"u\"/>"
|
" <arg name=\"id\" type=\"u\"/>"
|
||||||
" <arg name=\"action_key\" type=\"s\"/>"
|
" <arg name=\"action_key\" type=\"s\"/>" " </signal>"
|
||||||
" </signal>"
|
" </interface>" " " " <interface name=\"org.xfce.Notifyd\">"
|
||||||
" </interface>"
|
|
||||||
" "
|
|
||||||
" <interface name=\"org.xfce.Notifyd\">"
|
|
||||||
" <method name=\"Quit\"/>" " </interface>" "</node>";
|
" <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,
|
void handle_method_call(GDBusConnection * connection,
|
||||||
const gchar *sender,
|
const gchar * sender,
|
||||||
const GVariant *parameters,
|
const gchar * object_path,
|
||||||
GDBusMethodInvocation *invocation);
|
const gchar * interface_name,
|
||||||
static void onNotify(GDBusConnection *connection,
|
const gchar * method_name,
|
||||||
const gchar *sender,
|
GVariant * parameters,
|
||||||
GVariant *parameters,
|
GDBusMethodInvocation * invocation, gpointer user_data)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
if (g_strcmp0(method_name, "GetCapabilities") == 0) {
|
if (g_strcmp0(method_name, "GetCapabilities") == 0) {
|
||||||
onGetCapabilities(connection, sender, parameters, invocation);
|
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);
|
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);
|
onCloseNotification(connection, sender, parameters, invocation);
|
||||||
}
|
} else if (g_strcmp0(method_name, "GetServerInformation") == 0) {
|
||||||
else if (g_strcmp0(method_name, "GetServerInformation") == 0) {
|
onGetServerInformation(connection, sender, parameters,
|
||||||
onGetServerInformation(connection, sender, parameters, invocation);
|
invocation);
|
||||||
} else {
|
} else {
|
||||||
g_object_unref(invocation);
|
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,
|
static void onGetCapabilities(GDBusConnection * connection,
|
||||||
const gchar *sender,
|
const gchar * sender,
|
||||||
const GVariant *parameters,
|
const GVariant * parameters,
|
||||||
GDBusMethodInvocation *invocation)
|
GDBusMethodInvocation * invocation)
|
||||||
{
|
{
|
||||||
GVariantBuilder *builder;
|
GVariantBuilder *builder;
|
||||||
GVariant *value;
|
GVariant *value;
|
||||||
|
|
||||||
builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
|
builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
|
||||||
g_variant_builder_add (builder, "s", "actions");
|
g_variant_builder_add(builder, "s", "actions");
|
||||||
g_variant_builder_add (builder, "s", "body");
|
g_variant_builder_add(builder, "s", "body");
|
||||||
value = g_variant_new ("(as)", builder);
|
value = g_variant_new("(as)", builder);
|
||||||
g_variant_builder_unref (builder);
|
g_variant_builder_unref(builder);
|
||||||
g_dbus_method_invocation_return_value(invocation, value);
|
g_dbus_method_invocation_return_value(invocation, value);
|
||||||
|
|
||||||
g_dbus_connection_flush(connection, NULL, NULL, NULL);
|
g_dbus_connection_flush(connection, NULL, NULL, NULL);
|
||||||
g_variant_unref(value);
|
g_variant_unref(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onNotify(GDBusConnection *connection,
|
static void onNotify(GDBusConnection * connection,
|
||||||
const gchar *sender,
|
const gchar * sender,
|
||||||
GVariant *parameters,
|
GVariant * parameters, GDBusMethodInvocation * invocation)
|
||||||
GDBusMethodInvocation *invocation)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
gchar *appname = NULL;
|
gchar *appname = NULL;
|
||||||
@ -147,52 +133,82 @@ static void onNotify(GDBusConnection *connection,
|
|||||||
|
|
||||||
switch (idx) {
|
switch (idx) {
|
||||||
case 0:
|
case 0:
|
||||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING))
|
if (g_variant_is_of_type
|
||||||
appname = g_variant_dup_string(content, NULL);
|
(content, G_VARIANT_TYPE_STRING))
|
||||||
|
appname =
|
||||||
|
g_variant_dup_string(content, NULL);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_UINT32))
|
if (g_variant_is_of_type
|
||||||
replaces_id = g_variant_get_uint32(content);
|
(content, G_VARIANT_TYPE_UINT32))
|
||||||
|
replaces_id =
|
||||||
|
g_variant_get_uint32(content);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING))
|
if (g_variant_is_of_type
|
||||||
icon = g_variant_dup_string(content, NULL);
|
(content, G_VARIANT_TYPE_STRING))
|
||||||
|
icon =
|
||||||
|
g_variant_dup_string(content, NULL);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING))
|
if (g_variant_is_of_type
|
||||||
summary = g_variant_dup_string(content, NULL);
|
(content, G_VARIANT_TYPE_STRING))
|
||||||
|
summary =
|
||||||
|
g_variant_dup_string(content, NULL);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING))
|
if (g_variant_is_of_type
|
||||||
body = g_variant_dup_string(content, NULL);
|
(content, G_VARIANT_TYPE_STRING))
|
||||||
|
body =
|
||||||
|
g_variant_dup_string(content, NULL);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING_ARRAY))
|
if (g_variant_is_of_type
|
||||||
actions->actions = g_variant_dup_strv(content, &(actions->count));
|
(content, G_VARIANT_TYPE_STRING_ARRAY))
|
||||||
|
actions->actions =
|
||||||
|
g_variant_dup_strv(content,
|
||||||
|
&(actions->
|
||||||
|
count));
|
||||||
break;
|
break;
|
||||||
case 6:
|
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)
|
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)
|
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 =
|
||||||
if(dict_value)
|
g_variant_lookup_value(content,
|
||||||
bgcolor = g_variant_dup_string(dict_value, NULL);
|
"bgcolor",
|
||||||
|
G_VARIANT_TYPE_STRING);
|
||||||
|
if (dict_value)
|
||||||
|
bgcolor =
|
||||||
|
g_variant_dup_string
|
||||||
|
(dict_value, NULL);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 7:
|
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);
|
timeout = g_variant_get_int32(content);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,7 +225,7 @@ static void onNotify(GDBusConnection *connection,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notification *n = malloc(sizeof (notification));
|
notification *n = malloc(sizeof(notification));
|
||||||
n->appname = appname;
|
n->appname = appname;
|
||||||
n->summary = summary;
|
n->summary = summary;
|
||||||
n->body = body;
|
n->body = body;
|
||||||
@ -234,17 +250,17 @@ static void onNotify(GDBusConnection *connection,
|
|||||||
int id = notification_init(n, replaces_id);
|
int id = notification_init(n, replaces_id);
|
||||||
wake_up();
|
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_method_invocation_return_value(invocation, reply);
|
||||||
g_dbus_connection_flush(connection, NULL, NULL, NULL);
|
g_dbus_connection_flush(connection, NULL, NULL, NULL);
|
||||||
|
|
||||||
run(NULL);
|
run(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onCloseNotification(GDBusConnection *connection,
|
static void onCloseNotification(GDBusConnection * connection,
|
||||||
const gchar *sender,
|
const gchar * sender,
|
||||||
GVariant *parameters,
|
GVariant * parameters,
|
||||||
GDBusMethodInvocation *invocation)
|
GDBusMethodInvocation * invocation)
|
||||||
{
|
{
|
||||||
guint32 id;
|
guint32 id;
|
||||||
g_variant_get(parameters, "(u)", &id);
|
g_variant_get(parameters, "(u)", &id);
|
||||||
@ -253,14 +269,14 @@ static void onCloseNotification(GDBusConnection *connection,
|
|||||||
g_dbus_connection_flush(connection, NULL, NULL, NULL);
|
g_dbus_connection_flush(connection, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onGetServerInformation(GDBusConnection *connection,
|
static void onGetServerInformation(GDBusConnection * connection,
|
||||||
const gchar *sender,
|
const gchar * sender,
|
||||||
const GVariant *parameters,
|
const GVariant * parameters,
|
||||||
GDBusMethodInvocation *invocation)
|
GDBusMethodInvocation * invocation)
|
||||||
{
|
{
|
||||||
GVariant *value;
|
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_method_invocation_return_value(invocation, value);
|
||||||
|
|
||||||
g_dbus_connection_flush(connection, NULL, NULL, NULL);
|
g_dbus_connection_flush(connection, NULL, NULL, NULL);
|
||||||
@ -273,17 +289,14 @@ void notificationClosed(notification * n, int reason)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GVariant *body = g_variant_new ("(uu)", n->id, reason);
|
GVariant *body = g_variant_new("(uu)", n->id, reason);
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
|
|
||||||
g_dbus_connection_emit_signal(
|
g_dbus_connection_emit_signal(dbus_conn,
|
||||||
dbus_conn,
|
|
||||||
n->dbus_client,
|
n->dbus_client,
|
||||||
"/org/freedesktop/Notifications",
|
"/org/freedesktop/Notifications",
|
||||||
"org.freedesktop.Notifications",
|
"org.freedesktop.Notifications",
|
||||||
"NotificationClosed",
|
"NotificationClosed", body, &err);
|
||||||
body,
|
|
||||||
&err);
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
printf("notificationClosed ERROR\n");
|
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;
|
GError *err = NULL;
|
||||||
|
|
||||||
g_dbus_connection_emit_signal(
|
g_dbus_connection_emit_signal(dbus_conn,
|
||||||
dbus_conn,
|
|
||||||
n->dbus_client,
|
n->dbus_client,
|
||||||
"/org/freedesktop/Notifications",
|
"/org/freedesktop/Notifications",
|
||||||
"org.freedesktop.Notifications",
|
"org.freedesktop.Notifications",
|
||||||
"ActionInvoked",
|
"ActionInvoked", body, &err);
|
||||||
body,
|
|
||||||
&err);
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
printf("ActionInvoked ERROR\n");
|
printf("ActionInvoked ERROR\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const GDBusInterfaceVTable interface_vtable =
|
static const GDBusInterfaceVTable interface_vtable = {
|
||||||
{
|
|
||||||
handle_method_call
|
handle_method_call
|
||||||
};
|
};
|
||||||
|
|
||||||
static void on_bus_acquired(GDBusConnection *connection,
|
static void on_bus_acquired(GDBusConnection * connection,
|
||||||
const gchar *name,
|
const gchar * name, gpointer user_data)
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
guint registration_id;
|
guint registration_id;
|
||||||
|
|
||||||
registration_id = g_dbus_connection_register_object( connection,
|
registration_id = g_dbus_connection_register_object(connection,
|
||||||
"/org/freedesktop/Notifications",
|
"/org/freedesktop/Notifications",
|
||||||
introspection_data->interfaces[0],
|
introspection_data->
|
||||||
|
interfaces[0],
|
||||||
&interface_vtable,
|
&interface_vtable,
|
||||||
NULL,
|
NULL, NULL, NULL);
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (! registration_id > 0) {
|
if (!registration_id > 0) {
|
||||||
fprintf(stderr, "Unable to register\n");
|
fprintf(stderr, "Unable to register\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_name_acquired(GDBusConnection *connection,
|
static void on_name_acquired(GDBusConnection * connection,
|
||||||
const gchar *name,
|
const gchar * name, gpointer user_data)
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
dbus_conn = connection;
|
dbus_conn = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_name_lost(GDBusConnection *connection,
|
static void on_name_lost(GDBusConnection * connection,
|
||||||
const gchar *name,
|
const gchar * name, gpointer user_data)
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Name Lost\n");
|
fprintf(stderr, "Name Lost\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -359,14 +364,11 @@ int initdbus(void)
|
|||||||
introspection_data = g_dbus_node_info_new_for_xml(introspection_xml,
|
introspection_data = g_dbus_node_info_new_for_xml(introspection_xml,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
owner_id = g_bus_own_name(G_BUS_TYPE_SESSION,
|
||||||
"org.freedesktop.Notifications",
|
"org.freedesktop.Notifications",
|
||||||
G_BUS_NAME_OWNER_FLAGS_NONE,
|
G_BUS_NAME_OWNER_FLAGS_NONE,
|
||||||
on_bus_acquired,
|
on_bus_acquired,
|
||||||
on_name_acquired,
|
on_name_acquired, on_name_lost, NULL, NULL);
|
||||||
on_name_lost,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
return owner_id;
|
return owner_id;
|
||||||
}
|
}
|
||||||
@ -375,4 +377,5 @@ 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: */
|
/* 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_tear_down(int id);
|
||||||
/* void dbus_poll(int timeout); */
|
/* void dbus_poll(int timeout); */
|
||||||
void notificationClosed(notification * n, int reason);
|
void notificationClosed(notification * n, int reason);
|
||||||
void actionInvoked(notification *n, const char *identifier);
|
void actionInvoked(notification * n, const char *identifier);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
61
dunst.c
61
dunst.c
@ -37,7 +37,6 @@
|
|||||||
#include "option_parser.h"
|
#include "option_parser.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
|
|
||||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||||
|
|
||||||
#ifndef VERSION
|
#ifndef VERSION
|
||||||
@ -54,9 +53,6 @@ typedef struct _x11_source {
|
|||||||
Window w;
|
Window w;
|
||||||
} x11_source_t;
|
} x11_source_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* index of colors fit to urgency level */
|
/* index of colors fit to urgency level */
|
||||||
bool pause_display = false;
|
bool pause_display = false;
|
||||||
|
|
||||||
@ -65,37 +61,22 @@ bool timer_active = false;
|
|||||||
|
|
||||||
bool force_redraw = false;
|
bool force_redraw = false;
|
||||||
|
|
||||||
|
|
||||||
/* notification lists */
|
/* notification lists */
|
||||||
GQueue *queue = NULL; /* all new notifications get into here */
|
GQueue *queue = NULL; /* all new notifications get into here */
|
||||||
GQueue *displayed = NULL; /* currently displayed notifications */
|
GQueue *displayed = NULL; /* currently displayed notifications */
|
||||||
GQueue *history = NULL; /* history of displayed notifications */
|
GQueue *history = NULL; /* history of displayed notifications */
|
||||||
GSList *rules = NULL;
|
GSList *rules = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* misc funtions */
|
/* misc funtions */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void check_timeouts(void)
|
void check_timeouts(void)
|
||||||
{
|
{
|
||||||
/* nothing to do */
|
/* nothing to do */
|
||||||
if (displayed->length == 0)
|
if (displayed->length == 0)
|
||||||
return;
|
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;
|
notification *n = iter->data;
|
||||||
|
|
||||||
/* don't timeout when user is idle */
|
/* don't timeout when user is idle */
|
||||||
@ -128,7 +109,8 @@ void update_lists()
|
|||||||
|
|
||||||
if (pause_display) {
|
if (pause_display) {
|
||||||
while (displayed->length > 0) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@ -143,7 +125,6 @@ void update_lists()
|
|||||||
limit = xctx.geometry.h;
|
limit = xctx.geometry.h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* move notifications from queue to displayed */
|
/* move notifications from queue to displayed */
|
||||||
while (queue->length > 0) {
|
while (queue->length > 0) {
|
||||||
|
|
||||||
@ -163,11 +144,11 @@ void update_lists()
|
|||||||
notification_run_script(n);
|
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()
|
void move_all_to_history()
|
||||||
{
|
{
|
||||||
while (displayed->length > 0) {
|
while (displayed->length > 0) {
|
||||||
@ -205,7 +186,7 @@ void update(void)
|
|||||||
|
|
||||||
/* move messages from notification_queue to displayed_notifications */
|
/* move messages from notification_queue to displayed_notifications */
|
||||||
update_lists();
|
update_lists();
|
||||||
if (displayed->length > 0 && ! xctx.visible) {
|
if (displayed->length > 0 && !xctx.visible) {
|
||||||
x_win_show();
|
x_win_show();
|
||||||
}
|
}
|
||||||
if (displayed->length == 0 && xctx.visible) {
|
if (displayed->length == 0 && xctx.visible) {
|
||||||
@ -248,10 +229,6 @@ gboolean run(void *data)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -259,7 +236,6 @@ int main(int argc, char *argv[])
|
|||||||
displayed = g_queue_new();
|
displayed = g_queue_new();
|
||||||
queue = g_queue_new();
|
queue = g_queue_new();
|
||||||
|
|
||||||
|
|
||||||
cmdline_load(argc, argv);
|
cmdline_load(argc, argv);
|
||||||
|
|
||||||
if (cmdline_get_bool("-v/-version", false, "Print version")
|
if (cmdline_get_bool("-v/-version", false, "Print version")
|
||||||
@ -282,11 +258,11 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
x_setup();
|
x_setup();
|
||||||
|
|
||||||
signal (SIGUSR1, pause_signal_handler);
|
signal(SIGUSR1, pause_signal_handler);
|
||||||
signal (SIGUSR2, pause_signal_handler);
|
signal(SIGUSR2, pause_signal_handler);
|
||||||
|
|
||||||
if (settings.startup_notification) {
|
if (settings.startup_notification) {
|
||||||
notification *n = malloc(sizeof (notification));
|
notification *n = malloc(sizeof(notification));
|
||||||
n->appname = "dunst";
|
n->appname = "dunst";
|
||||||
n->summary = "startup";
|
n->summary = "startup";
|
||||||
n->body = "dunst is up and running";
|
n->body = "dunst is up and running";
|
||||||
@ -305,8 +281,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
mainloop = g_main_loop_new(NULL, FALSE);
|
mainloop = g_main_loop_new(NULL, FALSE);
|
||||||
|
|
||||||
GPollFD dpy_pollfd = {xctx.dc->dpy->fd,
|
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 = {
|
GSourceFuncs x11_source_funcs = {
|
||||||
x_mainloop_fd_prepare,
|
x_mainloop_fd_prepare,
|
||||||
@ -314,12 +291,13 @@ int main(int argc, char *argv[])
|
|||||||
x_mainloop_fd_dispatch,
|
x_mainloop_fd_dispatch,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL };
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
GSource *x11_source =
|
GSource *x11_source =
|
||||||
g_source_new(&x11_source_funcs, sizeof(x11_source_t));
|
g_source_new(&x11_source_funcs, sizeof(x11_source_t));
|
||||||
((x11_source_t*)x11_source)->dpy = xctx.dc->dpy;
|
((x11_source_t *) x11_source)->dpy = xctx.dc->dpy;
|
||||||
((x11_source_t*)x11_source)->w = xctx.win;
|
((x11_source_t *) x11_source)->w = xctx.win;
|
||||||
g_source_add_poll(x11_source, &dpy_pollfd);
|
g_source_add_poll(x11_source, &dpy_pollfd);
|
||||||
|
|
||||||
g_source_attach(x11_source, NULL);
|
g_source_attach(x11_source, NULL);
|
||||||
@ -341,7 +319,7 @@ void pause_signal_handler(int sig)
|
|||||||
pause_display = false;
|
pause_display = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
signal (sig, pause_signal_handler);
|
signal(sig, pause_signal_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(int exit_status)
|
void usage(int exit_status)
|
||||||
@ -355,7 +333,8 @@ void usage(int exit_status)
|
|||||||
|
|
||||||
void print_version(void)
|
void print_version(void)
|
||||||
{
|
{
|
||||||
printf("Dunst - A customizable and lightweight notification-daemon %s\n",
|
printf
|
||||||
|
("Dunst - A customizable and lightweight notification-daemon %s\n",
|
||||||
VERSION);
|
VERSION);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
4
dunst.h
4
dunst.h
@ -11,7 +11,6 @@
|
|||||||
#define PERR(msg, errnum) printf("(%d) %s : %s\n", __LINE__, (msg), (strerror(errnum)))
|
#define PERR(msg, errnum) printf("(%d) %s : %s\n", __LINE__, (msg), (strerror(errnum)))
|
||||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||||
|
|
||||||
|
|
||||||
#define ColLast 2
|
#define ColLast 2
|
||||||
#define ColFG 1
|
#define ColFG 1
|
||||||
#define ColBG 0
|
#define ColBG 0
|
||||||
@ -20,7 +19,6 @@ enum alignment { left, center, right };
|
|||||||
enum separator_color { FOREGROUND, AUTO, FRAME, CUSTOM };
|
enum separator_color { FOREGROUND, AUTO, FRAME, CUSTOM };
|
||||||
enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD };
|
enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD };
|
||||||
|
|
||||||
|
|
||||||
extern int verbosity;
|
extern int verbosity;
|
||||||
extern GQueue *queue;
|
extern GQueue *queue;
|
||||||
extern GQueue *displayed;
|
extern GQueue *displayed;
|
||||||
@ -30,8 +28,6 @@ extern bool pause_display;
|
|||||||
extern const char *color_strings[2][3];
|
extern const char *color_strings[2][3];
|
||||||
extern DC *dc;
|
extern DC *dc;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* return id of notification */
|
/* return id of notification */
|
||||||
gboolean run(void *data);
|
gboolean run(void *data);
|
||||||
void wake_up(void);
|
void wake_up(void);
|
||||||
|
47
menu.c
47
menu.c
@ -12,21 +12,21 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "dbus.h"
|
#include "dbus.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Exctract all urls from a given string.
|
* Exctract all urls from a given string.
|
||||||
*
|
*
|
||||||
* Return: a string of urls separated by \n
|
* 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 bool is_initialized = false;
|
||||||
static regex_t cregex;
|
static regex_t cregex;
|
||||||
|
|
||||||
if (!is_initialized) {
|
if (!is_initialized) {
|
||||||
char *regex = "((http|ftp|https)(://))?(www\\.)?[[:alnum:]_-]+\\.[^[:space:]]+";
|
char *regex =
|
||||||
int ret = regcomp(&cregex, regex, REG_EXTENDED|REG_ICASE);
|
"((http|ftp|https)(://))?(www\\.)?[[:alnum:]_-]+\\.[^[:space:]]+";
|
||||||
|
int ret = regcomp(&cregex, regex, REG_EXTENDED | REG_ICASE);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
printf("failed to compile regex\n");
|
printf("failed to compile regex\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -37,11 +37,11 @@ char *extract_urls( const char * to_match)
|
|||||||
|
|
||||||
char *urls = NULL;
|
char *urls = NULL;
|
||||||
|
|
||||||
const char * p = to_match;
|
const char *p = to_match;
|
||||||
regmatch_t m;
|
regmatch_t m;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int nomatch = regexec (&cregex, p, 1, &m, 0);
|
int nomatch = regexec(&cregex, p, 1, &m, 0);
|
||||||
if (nomatch) {
|
if (nomatch) {
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ char *extract_urls( const char * to_match)
|
|||||||
start = m.rm_so + (p - to_match);
|
start = m.rm_so + (p - to_match);
|
||||||
finish = m.rm_eo + (p - to_match);
|
finish = m.rm_eo + (p - to_match);
|
||||||
|
|
||||||
char *match = strndup(to_match+start, finish-start);
|
char *match = strndup(to_match + start, finish - start);
|
||||||
|
|
||||||
urls = string_append(urls, match, "\n");
|
urls = string_append(urls, match, "\n");
|
||||||
|
|
||||||
@ -62,31 +62,29 @@ char *extract_urls( const char * to_match)
|
|||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open url in browser.
|
* Open url in browser.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void open_browser(const char *url)
|
void open_browser(const char *url)
|
||||||
{
|
{
|
||||||
int browser_pid1 = fork();
|
int browser_pid1 = fork();
|
||||||
|
|
||||||
if (browser_pid1) {
|
if (browser_pid1) {
|
||||||
int status;
|
int status;
|
||||||
waitpid(browser_pid1, &status, 0);
|
waitpid(browser_pid1, &status, 0);
|
||||||
} else {
|
} else {
|
||||||
int browser_pid2 = fork();
|
int browser_pid2 = fork();
|
||||||
if (browser_pid2) {
|
if (browser_pid2) {
|
||||||
exit(0);
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
char *browser_cmd = string_append(settings.browser, url, " ");
|
char *browser_cmd =
|
||||||
|
string_append(settings.browser, url, " ");
|
||||||
char **cmd = g_strsplit(browser_cmd, " ", 0);
|
char **cmd = g_strsplit(browser_cmd, " ", 0);
|
||||||
execvp(cmd[0], cmd);
|
execvp(cmd[0], cmd);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Notify the corresponding client
|
* Notify the corresponding client
|
||||||
@ -104,16 +102,16 @@ void invoke_action(const char *action)
|
|||||||
}
|
}
|
||||||
name_begin++;
|
name_begin++;
|
||||||
|
|
||||||
|
for (GList * iter = g_queue_peek_head_link(displayed); iter;
|
||||||
for (GList *iter = g_queue_peek_head_link(displayed); iter; iter = iter->next) {
|
iter = iter->next) {
|
||||||
notification *n = iter->data;
|
notification *n = iter->data;
|
||||||
if (g_str_has_prefix(action, n->appname)) {
|
if (g_str_has_prefix(action, n->appname)) {
|
||||||
if (! n->actions)
|
if (!n->actions)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int i = 0; i < n->actions->count; i += 2) {
|
for (int i = 0; i < n->actions->count; i += 2) {
|
||||||
char *a_identifier = n->actions->actions[i];
|
char *a_identifier = n->actions->actions[i];
|
||||||
char *name = n->actions->actions[i+1];
|
char *name = n->actions->actions[i + 1];
|
||||||
if (g_str_has_prefix(name_begin, name)) {
|
if (g_str_has_prefix(name_begin, name)) {
|
||||||
invoked = n;
|
invoked = n;
|
||||||
action_identifier = a_identifier;
|
action_identifier = a_identifier;
|
||||||
@ -152,14 +150,16 @@ void context_menu(void)
|
|||||||
{
|
{
|
||||||
char *dmenu_input = NULL;
|
char *dmenu_input = NULL;
|
||||||
|
|
||||||
for (GList *iter = g_queue_peek_head_link(displayed); iter; iter = iter->next) {
|
for (GList * iter = g_queue_peek_head_link(displayed); iter;
|
||||||
|
iter = iter->next) {
|
||||||
notification *n = iter->data;
|
notification *n = iter->data;
|
||||||
dmenu_input = string_append(dmenu_input, n->urls, "\n");
|
dmenu_input = string_append(dmenu_input, n->urls, "\n");
|
||||||
if (n->actions)
|
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)
|
if (!dmenu_input)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -210,8 +210,5 @@ void context_menu(void)
|
|||||||
|
|
||||||
close(parent_io[0]);
|
close(parent_io[0]);
|
||||||
|
|
||||||
|
|
||||||
dispatch_menu_result(buf);
|
dispatch_menu_result(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,12 +18,8 @@
|
|||||||
#include "rules.h"
|
#include "rules.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
|
||||||
|
|
||||||
int next_notification_id = 1;
|
int next_notification_id = 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* print a human readable representation
|
* print a human readable representation
|
||||||
* of the given notification to stdout.
|
* of the given notification to stdout.
|
||||||
@ -49,7 +45,8 @@ void notification_print(notification * n)
|
|||||||
printf("\tactions:\n");
|
printf("\tactions:\n");
|
||||||
printf("\t{\n");
|
printf("\t{\n");
|
||||||
for (int i = 0; i < n->actions->count; i += 2) {
|
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("actions_dmenu: %s\n", n->actions->dmenu_str);
|
||||||
printf("\t]\n");
|
printf("\t]\n");
|
||||||
@ -62,7 +59,7 @@ void notification_print(notification * n)
|
|||||||
* Run the script associated with the
|
* Run the script associated with the
|
||||||
* given notification.
|
* given notification.
|
||||||
*/
|
*/
|
||||||
void notification_run_script(notification *n)
|
void notification_run_script(notification * n)
|
||||||
{
|
{
|
||||||
if (!n->script || strlen(n->script) < 1)
|
if (!n->script || strlen(n->script) < 1)
|
||||||
return;
|
return;
|
||||||
@ -104,8 +101,7 @@ void notification_run_script(notification *n)
|
|||||||
body,
|
body,
|
||||||
icon,
|
icon,
|
||||||
urgency,
|
urgency,
|
||||||
(char *) NULL
|
(char *)NULL);
|
||||||
);
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
PERR("Unable to run script", errno);
|
PERR("Unable to run script", errno);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -120,8 +116,8 @@ void notification_run_script(notification *n)
|
|||||||
*/
|
*/
|
||||||
int notification_cmp(const void *va, const void *vb)
|
int notification_cmp(const void *va, const void *vb)
|
||||||
{
|
{
|
||||||
notification *a = (notification*) va;
|
notification *a = (notification *) va;
|
||||||
notification *b = (notification*) vb;
|
notification *b = (notification *) vb;
|
||||||
|
|
||||||
if (!settings.sort)
|
if (!settings.sort)
|
||||||
return 1;
|
return 1;
|
||||||
@ -142,7 +138,6 @@ int notification_cmp_data(const void *va, const void *vb, void *data)
|
|||||||
return notification_cmp(va, vb);
|
return notification_cmp(va, vb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free the memory used by the given notification.
|
* Free the memory used by the given notification.
|
||||||
*/
|
*/
|
||||||
@ -265,11 +260,11 @@ int notification_init(notification * n, int id)
|
|||||||
|
|
||||||
n->msg = g_strstrip(n->msg);
|
n->msg = g_strstrip(n->msg);
|
||||||
|
|
||||||
|
|
||||||
n->dup_count = 0;
|
n->dup_count = 0;
|
||||||
|
|
||||||
/* check if n is a duplicate */
|
/* 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;
|
notification *orig = iter->data;
|
||||||
if (strcmp(orig->appname, n->appname) == 0
|
if (strcmp(orig->appname, n->appname) == 0
|
||||||
&& strcmp(orig->msg, n->msg) == 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;
|
notification *orig = iter->data;
|
||||||
if (strcmp(orig->appname, n->appname) == 0
|
if (strcmp(orig->appname, n->appname) == 0
|
||||||
&& strcmp(orig->msg, n->msg) == 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->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->start = 0;
|
||||||
|
|
||||||
n->timestamp = time(NULL);
|
n->timestamp = time(NULL);
|
||||||
@ -334,26 +331,27 @@ int notification_init(notification * n, int id)
|
|||||||
|
|
||||||
n->urls = extract_urls(tmp);
|
n->urls = extract_urls(tmp);
|
||||||
|
|
||||||
|
|
||||||
if (n->actions) {
|
if (n->actions) {
|
||||||
n->actions->dmenu_str = NULL;
|
n->actions->dmenu_str = NULL;
|
||||||
for (int i = 0; i < n->actions->count; i += 2) {
|
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", n->appname);
|
||||||
printf("debug: %s\n", human_readable);
|
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);
|
printf("debug: %s\n", tmp);
|
||||||
|
|
||||||
n->actions->dmenu_str = string_append(n->actions->dmenu_str,
|
n->actions->dmenu_str =
|
||||||
g_strdup_printf("%s(%s)",
|
string_append(n->actions->dmenu_str,
|
||||||
n->appname,
|
g_strdup_printf("%s(%s)", n->appname,
|
||||||
human_readable), "\n");
|
human_readable),
|
||||||
|
"\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|
||||||
|
|
||||||
if (settings.print_notifications)
|
if (settings.print_notifications)
|
||||||
notification_print(n);
|
notification_print(n);
|
||||||
|
|
||||||
@ -373,7 +371,8 @@ int notification_close_by_id(int id, int reason)
|
|||||||
{
|
{
|
||||||
notification *target = NULL;
|
notification *target = NULL;
|
||||||
|
|
||||||
for (GList *iter = g_queue_peek_head_link(displayed); iter; iter = iter->next) {
|
for (GList * iter = g_queue_peek_head_link(displayed); iter;
|
||||||
|
iter = iter->next) {
|
||||||
notification *n = iter->data;
|
notification *n = iter->data;
|
||||||
if (n->id == id) {
|
if (n->id == id) {
|
||||||
g_queue_remove(displayed, n);
|
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;
|
notification *n = iter->data;
|
||||||
if (n->id == id) {
|
if (n->id == id) {
|
||||||
g_queue_remove(queue, n);
|
g_queue_remove(queue, n);
|
||||||
@ -410,4 +410,3 @@ int notification_close(notification * n, int reason)
|
|||||||
return -1;
|
return -1;
|
||||||
return notification_close_by_id(n->id, reason);
|
return notification_close_by_id(n->id, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,12 +37,11 @@ typedef struct _notification {
|
|||||||
Actions *actions;
|
Actions *actions;
|
||||||
} notification;
|
} notification;
|
||||||
|
|
||||||
|
|
||||||
int notification_init(notification * n, int id);
|
int notification_init(notification * n, int id);
|
||||||
int notification_close_by_id(int id, int reason);
|
int notification_close_by_id(int id, int reason);
|
||||||
int notification_cmp(const void *a, const void *b);
|
int notification_cmp(const void *a, const void *b);
|
||||||
int notification_cmp_data(const void *a, const void *b, void *data);
|
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);
|
int notification_close(notification * n, int reason);
|
||||||
void notification_print(notification *n);
|
void notification_print(notification * n);
|
||||||
char *notification_fix_markup(char *str);
|
char *notification_fix_markup(char *str);
|
||||||
|
@ -444,13 +444,15 @@ void cmdline_usage_append(char *key, char *type, char *description)
|
|||||||
key_type = g_strdup(key);
|
key_type = g_strdup(key);
|
||||||
|
|
||||||
if (!usage_str) {
|
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);
|
free(key_type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *tmp;
|
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(key_type);
|
||||||
|
|
||||||
free(usage_str);
|
free(usage_str);
|
||||||
|
11
rules.c
11
rules.c
@ -7,7 +7,7 @@
|
|||||||
/*
|
/*
|
||||||
* Apply rule to notification.
|
* Apply rule to notification.
|
||||||
*/
|
*/
|
||||||
void rule_apply(rule_t *r, notification *n)
|
void rule_apply(rule_t * r, notification * n)
|
||||||
{
|
{
|
||||||
if (r->timeout != -1)
|
if (r->timeout != -1)
|
||||||
n->timeout = r->timeout;
|
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.
|
* 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;
|
rule_t *r = iter->data;
|
||||||
if (rule_matches_notification(r, n)) {
|
if (rule_matches_notification(r, n)) {
|
||||||
rule_apply(r, n);
|
rule_apply(r, n);
|
||||||
@ -39,7 +39,7 @@ void rule_apply_all(notification *n)
|
|||||||
/*
|
/*
|
||||||
* Initialize rule with default values.
|
* Initialize rule with default values.
|
||||||
*/
|
*/
|
||||||
void rule_init(rule_t *r)
|
void rule_init(rule_t * r)
|
||||||
{
|
{
|
||||||
r->name = NULL;
|
r->name = NULL;
|
||||||
r->appname = NULL;
|
r->appname = NULL;
|
||||||
@ -53,11 +53,10 @@ void rule_init(rule_t *r)
|
|||||||
r->format = NULL;
|
r->format = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check whether rule should be applied to n.
|
* 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))
|
return ((!r->appname || !fnmatch(r->appname, n->appname, 0))
|
||||||
|
8
rules.h
8
rules.h
@ -24,7 +24,7 @@ typedef struct _rule_t {
|
|||||||
|
|
||||||
extern GSList *rules;
|
extern GSList *rules;
|
||||||
|
|
||||||
void rule_init(rule_t *r);
|
void rule_init(rule_t * r);
|
||||||
void rule_apply(rule_t *r, notification *n);
|
void rule_apply(rule_t * r, notification * n);
|
||||||
void rule_apply_all(notification *n);
|
void rule_apply_all(notification * n);
|
||||||
bool rule_matches_notification(rule_t *r, notification *n);
|
bool rule_matches_notification(rule_t * r, notification * n);
|
||||||
|
46
settings.c
46
settings.c
@ -74,7 +74,8 @@ void load_settings(char *cmdline_config_path)
|
|||||||
|
|
||||||
settings.ignore_newline =
|
settings.ignore_newline =
|
||||||
option_get_bool("global", "ignore_newline", "-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 =
|
settings.idle_threshold =
|
||||||
option_get_int("global", "idle_threshold", "-idle_threshold",
|
option_get_int("global", "idle_threshold", "-idle_threshold",
|
||||||
idle_threshold,
|
idle_threshold,
|
||||||
@ -83,8 +84,7 @@ void load_settings(char *cmdline_config_path)
|
|||||||
option_get_int("global", "monitor", "-mon", monitor,
|
option_get_int("global", "monitor", "-mon", monitor,
|
||||||
"On which monitor should the notifications be displayed");
|
"On which monitor should the notifications be displayed");
|
||||||
{
|
{
|
||||||
char *c =
|
char *c = option_get_string("global", "follow", "-follow", "",
|
||||||
option_get_string("global", "follow", "-follow", "",
|
|
||||||
"Follow mouse, keyboard or none?");
|
"Follow mouse, keyboard or none?");
|
||||||
if (strlen(c) > 0) {
|
if (strlen(c) > 0) {
|
||||||
parse_follow_mode(c);
|
parse_follow_mode(c);
|
||||||
@ -103,8 +103,7 @@ void load_settings(char *cmdline_config_path)
|
|||||||
bounce_freq,
|
bounce_freq,
|
||||||
"Make long text bounce from side to side");
|
"Make long text bounce from side to side");
|
||||||
{
|
{
|
||||||
char *c =
|
char *c = option_get_string("global", "alignment",
|
||||||
option_get_string("global", "alignment",
|
|
||||||
"-align/-alignment", "",
|
"-align/-alignment", "",
|
||||||
"Align notifications left/center/right");
|
"Align notifications left/center/right");
|
||||||
if (strlen(c) > 0) {
|
if (strlen(c) > 0) {
|
||||||
@ -136,14 +135,14 @@ void load_settings(char *cmdline_config_path)
|
|||||||
option_get_int("global", "padding", "-padding", padding,
|
option_get_int("global", "padding", "-padding", padding,
|
||||||
"Padding between text and separator");
|
"Padding between text and separator");
|
||||||
settings.h_padding =
|
settings.h_padding =
|
||||||
option_get_int("global", "horizontal_padding", "-horizontal_padding",
|
option_get_int("global", "horizontal_padding",
|
||||||
h_padding, "horizontal padding");
|
"-horizontal_padding", h_padding,
|
||||||
|
"horizontal padding");
|
||||||
settings.transparency =
|
settings.transparency =
|
||||||
option_get_int("global", "transparency", "-transparency",
|
option_get_int("global", "transparency", "-transparency",
|
||||||
transparency, "Transparency. range 0-100");
|
transparency, "Transparency. range 0-100");
|
||||||
{
|
{
|
||||||
char *c =
|
char *c = option_get_string("global", "separator_color",
|
||||||
option_get_string("global", "separator_color",
|
|
||||||
"-sep_color/-separator_color", "",
|
"-sep_color/-separator_color", "",
|
||||||
"Color of the separator line (or 'auto')");
|
"Color of the separator line (or 'auto')");
|
||||||
if (strlen(c) > 0) {
|
if (strlen(c) > 0) {
|
||||||
@ -161,20 +160,27 @@ void load_settings(char *cmdline_config_path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.startup_notification = option_get_bool("global", "startup_notification",
|
settings.startup_notification =
|
||||||
"-startup_notification", false, "print notification on startup");
|
option_get_bool("global", "startup_notification",
|
||||||
|
"-startup_notification", false,
|
||||||
|
"print notification on startup");
|
||||||
|
|
||||||
|
settings.dmenu =
|
||||||
settings.dmenu = option_get_string("global", "dmenu", "-dmenu", dmenu, "path to dmenu");
|
option_get_string("global", "dmenu", "-dmenu", dmenu,
|
||||||
|
"path to dmenu");
|
||||||
settings.dmenu_cmd = g_strsplit(dmenu, " ", 0);
|
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");
|
"Width of frame around window");
|
||||||
|
|
||||||
settings.frame_color = option_get_string("frame", "color", "-frame_color",
|
settings.frame_color =
|
||||||
frame_color, "Color of the frame around window");
|
option_get_string("frame", "color", "-frame_color", frame_color,
|
||||||
|
"Color of the frame around window");
|
||||||
|
|
||||||
settings.lowbgcolor =
|
settings.lowbgcolor =
|
||||||
option_get_string("urgency_low", "background", "-lb", lowbgcolor,
|
option_get_string("urgency_low", "background", "-lb", lowbgcolor,
|
||||||
@ -223,8 +229,7 @@ void load_settings(char *cmdline_config_path)
|
|||||||
|
|
||||||
settings.context_ks.str =
|
settings.context_ks.str =
|
||||||
option_get_string("shortcuts", "context", "-context_key",
|
option_get_string("shortcuts", "context", "-context_key",
|
||||||
context_ks.str,
|
context_ks.str, "Shortcut for context menu");
|
||||||
"Shortcut for context menu");
|
|
||||||
|
|
||||||
settings.print_notifications =
|
settings.print_notifications =
|
||||||
cmdline_get_bool("-print", false,
|
cmdline_get_bool("-print", false,
|
||||||
@ -249,7 +254,7 @@ void load_settings(char *cmdline_config_path)
|
|||||||
|
|
||||||
/* check for existing rule with same name */
|
/* check for existing rule with same name */
|
||||||
rule_t *r = NULL;
|
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;
|
rule_t *match = iter->data;
|
||||||
if (match->name &&
|
if (match->name &&
|
||||||
strcmp(match->name, cur_section) == 0)
|
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);
|
r->script = ini_get_string(cur_section, "script", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef STATIC_CONFIG
|
#ifndef STATIC_CONFIG
|
||||||
fclose(config_file);
|
fclose(config_file);
|
||||||
free_ini();
|
free_ini();
|
||||||
|
4
utils.c
4
utils.c
@ -14,7 +14,7 @@ char *string_replace_all(const char *needle, const char *replacement,
|
|||||||
{
|
{
|
||||||
char *start;
|
char *start;
|
||||||
start = strstr(haystack, needle);
|
start = strstr(haystack, needle);
|
||||||
while(start != NULL) {
|
while (start != NULL) {
|
||||||
haystack = string_replace(needle, replacement, haystack);
|
haystack = string_replace(needle, replacement, haystack);
|
||||||
start = strstr(haystack, needle);
|
start = strstr(haystack, needle);
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ char *string_append(char *a, const char *b, const char *sep)
|
|||||||
|
|
||||||
char *new;
|
char *new;
|
||||||
if (!sep)
|
if (!sep)
|
||||||
new = g_strconcat(a,b, NULL);
|
new = g_strconcat(a, b, NULL);
|
||||||
else
|
else
|
||||||
new = g_strconcat(a, sep, b, NULL);
|
new = g_strconcat(a, sep, b, NULL);
|
||||||
free(a);
|
free(a);
|
||||||
|
206
x.c
206
x.c
@ -301,32 +301,30 @@ int textw(DC * dc, const char *text)
|
|||||||
return textnw(dc, text, strlen(text)) + dc->font.height;
|
return textnw(dc, text, strlen(text)) + dc->font.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper function to use glib's mainloop mechanic
|
* Helper function to use glib's mainloop mechanic
|
||||||
* with Xlib
|
* with Xlib
|
||||||
*/
|
*/
|
||||||
gboolean x_mainloop_fd_prepare(GSource *source, gint *timeout)
|
gboolean x_mainloop_fd_prepare(GSource * source, gint * timeout)
|
||||||
{
|
{
|
||||||
*timeout = -1;
|
*timeout = -1;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper function to use glib's mainloop mechanic
|
* Helper function to use glib's mainloop mechanic
|
||||||
* with Xlib
|
* with Xlib
|
||||||
*/
|
*/
|
||||||
gboolean x_mainloop_fd_check(GSource *source)
|
gboolean x_mainloop_fd_check(GSource * source)
|
||||||
{
|
{
|
||||||
return XPending(xctx.dc->dpy) > 0;
|
return XPending(xctx.dc->dpy) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main Dispatcher for XEvents
|
* Main Dispatcher for XEvents
|
||||||
*/
|
*/
|
||||||
gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
|
gboolean x_mainloop_fd_dispatch(GSource * source, GSourceFunc callback,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
while (XPending(xctx.dc->dpy) > 0) {
|
while (XPending(xctx.dc->dpy) > 0) {
|
||||||
@ -350,24 +348,30 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer
|
|||||||
break;
|
break;
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
if (settings.close_ks.str
|
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) {
|
&& settings.close_ks.mask == ev.xkey.state) {
|
||||||
if (displayed) {
|
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
|
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) {
|
&& settings.history_ks.mask == ev.xkey.state) {
|
||||||
history_pop();
|
history_pop();
|
||||||
}
|
}
|
||||||
if (settings.close_all_ks.str
|
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) {
|
&& settings.close_all_ks.mask == ev.xkey.state) {
|
||||||
move_all_to_history();
|
move_all_to_history();
|
||||||
}
|
}
|
||||||
if (settings.context_ks.str
|
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) {
|
&& settings.context_ks.mask == ev.xkey.state) {
|
||||||
context_menu();
|
context_menu();
|
||||||
}
|
}
|
||||||
@ -377,8 +381,6 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check whether the user is currently idle.
|
* Check whether the user is currently idle.
|
||||||
*/
|
*/
|
||||||
@ -407,9 +409,12 @@ void x_handle_click(XEvent ev)
|
|||||||
if (ev.xbutton.button == Button1) {
|
if (ev.xbutton.button == Button1) {
|
||||||
int y = settings.separator_height;
|
int y = settings.separator_height;
|
||||||
notification *n = NULL;
|
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;
|
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 padding = 2 * settings.h_padding;
|
||||||
|
|
||||||
int height = text_h + padding;
|
int height = text_h + padding;
|
||||||
@ -424,8 +429,6 @@ void x_handle_click(XEvent ev)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the window that currently has
|
* Return the window that currently has
|
||||||
* the keyboard focus.
|
* the keyboard focus.
|
||||||
@ -460,12 +463,15 @@ Window get_focused_window(void)
|
|||||||
int select_screen(XineramaScreenInfo * info, int info_len)
|
int select_screen(XineramaScreenInfo * info, int info_len)
|
||||||
{
|
{
|
||||||
if (settings.f_mode == FOLLOW_NONE) {
|
if (settings.f_mode == FOLLOW_NONE) {
|
||||||
return settings.monitor >= 0 ? settings.monitor : XDefaultScreen(xctx.dc->dpy);
|
return settings.monitor >=
|
||||||
|
0 ? settings.monitor : XDefaultScreen(xctx.dc->dpy);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
int x, y;
|
int x, y;
|
||||||
assert(settings.f_mode == FOLLOW_MOUSE || settings.f_mode == FOLLOW_KEYBOARD);
|
assert(settings.f_mode == FOLLOW_MOUSE
|
||||||
Window root = RootWindow(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
|| settings.f_mode == FOLLOW_KEYBOARD);
|
||||||
|
Window root =
|
||||||
|
RootWindow(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
||||||
|
|
||||||
if (settings.f_mode == FOLLOW_MOUSE) {
|
if (settings.f_mode == FOLLOW_MOUSE) {
|
||||||
int dummy;
|
int dummy;
|
||||||
@ -483,7 +489,10 @@ int select_screen(XineramaScreenInfo * info, int info_len)
|
|||||||
|
|
||||||
if (focused == 0) {
|
if (focused == 0) {
|
||||||
/* something went wrong. Fallback to default */
|
/* 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;
|
Window child_return;
|
||||||
@ -500,7 +509,8 @@ int select_screen(XineramaScreenInfo * info, int info_len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* something seems to be wrong. Fallback to default */
|
/* 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
|
#endif
|
||||||
@ -509,7 +519,7 @@ int select_screen(XineramaScreenInfo * info, int info_len)
|
|||||||
* Update the information about the monitor
|
* Update the information about the monitor
|
||||||
* geometry.
|
* geometry.
|
||||||
*/
|
*/
|
||||||
void x_screen_info(screen_info *scr)
|
void x_screen_info(screen_info * scr)
|
||||||
{
|
{
|
||||||
#ifdef XINERAMA
|
#ifdef XINERAMA
|
||||||
int n;
|
int n;
|
||||||
@ -542,7 +552,6 @@ void x_screen_info(screen_info *scr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup X11 stuff
|
* Setup X11 stuff
|
||||||
*/
|
*/
|
||||||
@ -579,7 +588,8 @@ void x_setup(void)
|
|||||||
xctx.framec = getcolor(xctx.dc, settings.frame_color);
|
xctx.framec = getcolor(xctx.dc, settings.frame_color);
|
||||||
|
|
||||||
if (settings.sep_color == CUSTOM) {
|
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 {
|
} else {
|
||||||
xctx.sep_custom_col = 0;
|
xctx.sep_custom_col = 0;
|
||||||
}
|
}
|
||||||
@ -596,16 +606,12 @@ void x_setup(void)
|
|||||||
&xctx.geometry.x, &xctx.geometry.y,
|
&xctx.geometry.x, &xctx.geometry.y,
|
||||||
&xctx.geometry.w, &xctx.geometry.h);
|
&xctx.geometry.w, &xctx.geometry.h);
|
||||||
|
|
||||||
|
|
||||||
xctx.screensaver_info = XScreenSaverAllocInfo();
|
xctx.screensaver_info = XScreenSaverAllocInfo();
|
||||||
|
|
||||||
|
|
||||||
x_win_setup();
|
x_win_setup();
|
||||||
x_shortcut_grab(&settings.history_ks);
|
x_shortcut_grab(&settings.history_ks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* TODO comments and naming */
|
/* TODO comments and naming */
|
||||||
|
|
||||||
GSList *do_word_wrap(char *text, int max_width)
|
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') {
|
if (*end == '\n') {
|
||||||
*end = ' ';
|
*end = ' ';
|
||||||
result = g_slist_append(result, g_strndup(begin, end - begin));
|
result =
|
||||||
|
g_slist_append(result,
|
||||||
|
g_strndup(begin, end - begin));
|
||||||
begin = ++end;
|
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 */
|
/* find previous space */
|
||||||
char *space = end;
|
char *space = end;
|
||||||
while (space > begin && !isspace(*space))
|
while (space > begin && !isspace(*space))
|
||||||
@ -640,7 +649,9 @@ GSList *do_word_wrap(char *text, int max_width)
|
|||||||
if (space > begin) {
|
if (space > begin) {
|
||||||
end = space;
|
end = space;
|
||||||
}
|
}
|
||||||
result = g_slist_append(result, g_strndup(begin, end - begin));
|
result =
|
||||||
|
g_slist_append(result,
|
||||||
|
g_strndup(begin, end - begin));
|
||||||
begin = ++end;
|
begin = ++end;
|
||||||
}
|
}
|
||||||
end++;
|
end++;
|
||||||
@ -649,24 +660,21 @@ GSList *do_word_wrap(char *text, int max_width)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *generate_final_text(notification * n)
|
||||||
char *generate_final_text(notification *n)
|
|
||||||
{
|
{
|
||||||
char *msg = g_strstrip(n->msg);
|
char *msg = g_strstrip(n->msg);
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
/* print dup_count and msg*/
|
/* print dup_count and msg */
|
||||||
if (n->dup_count > 0 && (n->actions || n->urls)) {
|
if (n->dup_count > 0 && (n->actions || n->urls)) {
|
||||||
buf = g_strdup_printf("(%d%s%s) %s",
|
buf = g_strdup_printf("(%d%s%s) %s",
|
||||||
n->dup_count,
|
n->dup_count,
|
||||||
n->actions ? "A" : "",
|
n->actions ? "A" : "",
|
||||||
n->urls ? "U" : "",
|
n->urls ? "U" : "", msg);
|
||||||
msg);
|
|
||||||
} else if (n->actions || n->urls) {
|
} else if (n->actions || n->urls) {
|
||||||
buf = g_strdup_printf("(%s%s) %s",
|
buf = g_strdup_printf("(%s%s) %s",
|
||||||
n->actions ? "A" : "",
|
n->actions ? "A" : "",
|
||||||
n->urls ? "U" : "",
|
n->urls ? "U" : "", msg);
|
||||||
msg);
|
|
||||||
} else {
|
} else {
|
||||||
buf = g_strdup(msg);
|
buf = g_strdup(msg);
|
||||||
}
|
}
|
||||||
@ -675,17 +683,20 @@ char *generate_final_text(notification *n)
|
|||||||
int hours, minutes, seconds;
|
int hours, minutes, seconds;
|
||||||
time_t t_delta = time(NULL) - n->timestamp;
|
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;
|
hours = t_delta / 3600;
|
||||||
minutes = t_delta / 60 % 60;
|
minutes = t_delta / 60 % 60;
|
||||||
seconds = t_delta % 60;
|
seconds = t_delta % 60;
|
||||||
|
|
||||||
char *new_buf;
|
char *new_buf;
|
||||||
if (hours > 0) {
|
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);
|
minutes, seconds);
|
||||||
} else if (minutes > 0) {
|
} 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);
|
seconds);
|
||||||
} else {
|
} else {
|
||||||
new_buf = g_strdup_printf("%s (%ds old)", buf, seconds);
|
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;
|
struct timeval t;
|
||||||
float pos;
|
float pos;
|
||||||
/* If the text is wider than the frame, bouncing is enabled and word_wrap disabled */
|
/* 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);
|
gettimeofday(&t, NULL);
|
||||||
pos =
|
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;
|
return (1 + sinf(2 * 3.14159 * pos)) * leftover / 2;
|
||||||
}
|
}
|
||||||
switch (settings.align) {
|
switch (settings.align) {
|
||||||
case left:
|
case left:
|
||||||
return settings.frame_width + settings.h_padding;
|
return settings.frame_width + settings.h_padding;
|
||||||
case center:
|
case center:
|
||||||
return settings.frame_width + settings.h_padding + (leftover / 2);
|
return settings.frame_width + settings.h_padding +
|
||||||
|
(leftover / 2);
|
||||||
case right:
|
case right:
|
||||||
return settings.frame_width + settings.h_padding + leftover;
|
return settings.frame_width + settings.h_padding + leftover;
|
||||||
default:
|
default:
|
||||||
@ -725,7 +739,8 @@ int calculate_x_offset(int line_width, int text_width)
|
|||||||
|
|
||||||
unsigned long calculate_foreground_color(unsigned long source_color)
|
unsigned long calculate_foreground_color(unsigned long source_color)
|
||||||
{
|
{
|
||||||
Colormap cmap = DefaultColormap(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
Colormap cmap =
|
||||||
|
DefaultColormap(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
||||||
XColor color;
|
XColor color;
|
||||||
|
|
||||||
color.pixel = source_color;
|
color.pixel = source_color;
|
||||||
@ -792,7 +807,7 @@ int calculate_width(void)
|
|||||||
void move_and_map(int width, int height)
|
void move_and_map(int width, int height)
|
||||||
{
|
{
|
||||||
|
|
||||||
int x,y;
|
int x, y;
|
||||||
screen_info scr;
|
screen_info scr;
|
||||||
x_screen_info(&scr);
|
x_screen_info(&scr);
|
||||||
/* calculate window position */
|
/* calculate window position */
|
||||||
@ -829,10 +844,11 @@ GSList *generate_render_texts(int width)
|
|||||||
{
|
{
|
||||||
GSList *render_texts = NULL;
|
GSList *render_texts = NULL;
|
||||||
|
|
||||||
for (GList *iter = g_queue_peek_head_link(displayed); iter; iter = iter->next) {
|
for (GList * iter = g_queue_peek_head_link(displayed); iter;
|
||||||
|
iter = iter->next) {
|
||||||
render_text *rt = g_malloc(sizeof(render_text));
|
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);
|
char *text = generate_final_text(iter->data);
|
||||||
rt->lines = do_word_wrap(text, width);
|
rt->lines = do_word_wrap(text, width);
|
||||||
free(text);
|
free(text);
|
||||||
@ -843,14 +859,22 @@ GSList *generate_render_texts(int width)
|
|||||||
if (settings.indicate_hidden && queue->length > 0) {
|
if (settings.indicate_hidden && queue->length > 0) {
|
||||||
if (xctx.geometry.h != 1) {
|
if (xctx.geometry.h != 1) {
|
||||||
render_text *rt = g_malloc(sizeof(render_text));
|
render_text *rt = g_malloc(sizeof(render_text));
|
||||||
rt->colors = ((render_text *) g_slist_last(render_texts)->data)->colors;
|
rt->colors =
|
||||||
rt->lines = g_slist_append(NULL, g_strdup_printf("%d more)", queue->length));
|
((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);
|
render_texts = g_slist_append(render_texts, rt);
|
||||||
} else {
|
} 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);
|
GSList *last_line = g_slist_last(last_lines);
|
||||||
char *old = last_line->data;
|
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);
|
free(old);
|
||||||
last_line->data = new;
|
last_line->data = new;
|
||||||
}
|
}
|
||||||
@ -859,18 +883,16 @@ GSList *generate_render_texts(int width)
|
|||||||
return render_texts;
|
return render_texts;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_render_text(void *data) {
|
void free_render_text(void *data)
|
||||||
|
{
|
||||||
g_slist_free_full(((render_text *) data)->lines, g_free);
|
g_slist_free_full(((render_text *) data)->lines, g_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_render_texts(GSList *texts) {
|
void free_render_texts(GSList * texts)
|
||||||
|
{
|
||||||
g_slist_free_full(texts, free_render_text);
|
g_slist_free_full(texts, free_render_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void x_win_draw(void)
|
void x_win_draw(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -878,38 +900,42 @@ void x_win_draw(void)
|
|||||||
screen_info scr;
|
screen_info scr;
|
||||||
x_screen_info(&scr);
|
x_screen_info(&scr);
|
||||||
|
|
||||||
|
|
||||||
settings.line_height = MAX(settings.line_height, xctx.font_h);
|
settings.line_height = MAX(settings.line_height, xctx.font_h);
|
||||||
|
|
||||||
int width;
|
int width;
|
||||||
if (outer_width == 0)
|
if (outer_width == 0)
|
||||||
width = 0;
|
width = 0;
|
||||||
else
|
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);
|
GSList *texts = generate_render_texts(width);
|
||||||
int line_count = 0;
|
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;
|
render_text *tmp = iter->data;
|
||||||
line_count += g_slist_length(tmp->lines);
|
line_count += g_slist_length(tmp->lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we have a dynamic width, calculate the actual width */
|
/* if we have a dynamic width, calculate the actual width */
|
||||||
if (width == 0) {
|
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;
|
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));
|
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 */
|
/* resize xctx.dc to correct width */
|
||||||
|
|
||||||
int height = (line_count * settings.line_height)
|
int height = (line_count * settings.line_height)
|
||||||
+ displayed->length * 2 * settings.padding
|
+ 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))
|
+ (settings.separator_height * (displayed->length - 1))
|
||||||
+ (2 * settings.frame_width);
|
+ (2 * settings.frame_width);
|
||||||
|
|
||||||
@ -928,15 +954,14 @@ void x_win_draw(void)
|
|||||||
xctx.dc->y = settings.frame_width;
|
xctx.dc->y = settings.frame_width;
|
||||||
xctx.dc->x = 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;
|
render_text *cur = iter->data;
|
||||||
ColorSet *colors = cur->colors;
|
ColorSet *colors = cur->colors;
|
||||||
|
|
||||||
|
|
||||||
int line_count = 0;
|
int line_count = 0;
|
||||||
bool first_line = true;
|
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;
|
char *line = iiter->data;
|
||||||
line_count++;
|
line_count++;
|
||||||
|
|
||||||
@ -944,24 +969,30 @@ void x_win_draw(void)
|
|||||||
bool last_line = iiter->next == NULL;
|
bool last_line = iiter->next == NULL;
|
||||||
|
|
||||||
if (first_line && last_line)
|
if (first_line && last_line)
|
||||||
pad = 2*settings.padding;
|
pad = 2 * settings.padding;
|
||||||
else if (first_line || last_line)
|
else if (first_line || last_line)
|
||||||
pad = settings.padding;
|
pad = settings.padding;
|
||||||
|
|
||||||
xctx.dc->x = settings.frame_width;
|
xctx.dc->x = settings.frame_width;
|
||||||
|
|
||||||
/* draw background */
|
/* 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 */
|
/* 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;
|
xctx.dc->y += first_line ? settings.padding : 0;
|
||||||
|
|
||||||
drawtextn(xctx.dc, line, strlen(line), colors);
|
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;
|
xctx.dc->y += last_line ? settings.padding : 0;
|
||||||
|
|
||||||
first_line = false;
|
first_line = false;
|
||||||
@ -981,7 +1012,9 @@ void x_win_draw(void)
|
|||||||
/* CUSTOM */
|
/* CUSTOM */
|
||||||
color = xctx.sep_custom_col;
|
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;
|
xctx.dc->y += settings.separator_height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1020,13 +1053,17 @@ void x_win_setup(void)
|
|||||||
xctx.win =
|
xctx.win =
|
||||||
XCreateWindow(xctx.dc->dpy, root, scr.dim.x, scr.dim.y, scr.dim.w,
|
XCreateWindow(xctx.dc->dpy, root, scr.dim.x, scr.dim.y, scr.dim.w,
|
||||||
xctx.font_h, 0, DefaultDepth(xctx.dc->dpy,
|
xctx.font_h, 0, DefaultDepth(xctx.dc->dpy,
|
||||||
DefaultScreen(xctx.dc->dpy)),
|
DefaultScreen(xctx.dc->
|
||||||
|
dpy)),
|
||||||
CopyFromParent, DefaultVisual(xctx.dc->dpy,
|
CopyFromParent, DefaultVisual(xctx.dc->dpy,
|
||||||
DefaultScreen(xctx.dc->dpy)),
|
DefaultScreen(xctx.dc->
|
||||||
|
dpy)),
|
||||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
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,
|
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;
|
xctx.visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse a string into a modifier mask.
|
* 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.
|
* Grab the given keyboard shortcut.
|
||||||
*/
|
*/
|
||||||
int x_shortcut_grab(keyboard_shortcut *ks)
|
int x_shortcut_grab(keyboard_shortcut * ks)
|
||||||
{
|
{
|
||||||
if (!ks->is_valid)
|
if (!ks->is_valid)
|
||||||
return 1;
|
return 1;
|
||||||
@ -1163,7 +1197,7 @@ int x_shortcut_grab(keyboard_shortcut *ks)
|
|||||||
/*
|
/*
|
||||||
* Ungrab the given keyboard shortcut.
|
* Ungrab the given keyboard shortcut.
|
||||||
*/
|
*/
|
||||||
void x_shortcut_ungrab(keyboard_shortcut *ks)
|
void x_shortcut_ungrab(keyboard_shortcut * ks)
|
||||||
{
|
{
|
||||||
Window root;
|
Window root;
|
||||||
root = RootWindow(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
root = RootWindow(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
||||||
@ -1174,7 +1208,7 @@ void x_shortcut_ungrab(keyboard_shortcut *ks)
|
|||||||
/*
|
/*
|
||||||
* Initialize the keyboard shortcut.
|
* Initialize the keyboard shortcut.
|
||||||
*/
|
*/
|
||||||
void x_shortcut_init(keyboard_shortcut *ks)
|
void x_shortcut_init(keyboard_shortcut * ks)
|
||||||
{
|
{
|
||||||
if (ks == NULL || ks->str == NULL)
|
if (ks == NULL || ks->str == NULL)
|
||||||
return;
|
return;
|
||||||
|
16
x.h
16
x.h
@ -46,7 +46,6 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
|
|
||||||
#include <X11/Xft/Xft.h>
|
#include <X11/Xft/Xft.h>
|
||||||
|
|
||||||
|
|
||||||
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
|
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
|
||||||
#define FONT_HEIGHT_BORDER 2
|
#define FONT_HEIGHT_BORDER 2
|
||||||
#define DEFFONT "Monospace-11"
|
#define DEFFONT "Monospace-11"
|
||||||
@ -144,20 +143,21 @@ void x_win_show(void);
|
|||||||
void x_win_setup(void);
|
void x_win_setup(void);
|
||||||
|
|
||||||
/* shortcut */
|
/* shortcut */
|
||||||
void x_shortcut_init(keyboard_shortcut *shortcut);
|
void x_shortcut_init(keyboard_shortcut * shortcut);
|
||||||
void x_shortcut_ungrab(keyboard_shortcut *ks);
|
void x_shortcut_ungrab(keyboard_shortcut * ks);
|
||||||
int x_shortcut_grab(keyboard_shortcut *ks);
|
int x_shortcut_grab(keyboard_shortcut * ks);
|
||||||
KeySym x_shortcut_string_to_mask(const char *str);
|
KeySym x_shortcut_string_to_mask(const char *str);
|
||||||
|
|
||||||
/* X misc */
|
/* X misc */
|
||||||
void x_handle_click(XEvent ev);
|
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);
|
bool x_is_idle(void);
|
||||||
void x_setup(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,
|
||||||
gboolean x_mainloop_fd_check(GSource *source);
|
gpointer user_data);
|
||||||
gboolean x_mainloop_fd_prepare(GSource *source, gint *timeout);
|
gboolean x_mainloop_fd_check(GSource * source);
|
||||||
|
gboolean x_mainloop_fd_prepare(GSource * source, gint * timeout);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/* vim: set ts=8 sw=8 tw=0: */
|
/* vim: set ts=8 sw=8 tw=0: */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user