Fix code style
* Move mouse_left/middle/right_click to global section * Match the enum value style * Ignore unknow mouse event * Split copy-paste code into a function * Fix typo
This commit is contained in:
parent
fbcc26b5e1
commit
7a22fa0e5f
@ -472,6 +472,30 @@ single notification.
|
|||||||
To avoid the corners clipping the icon or text the corner radius will be
|
To avoid the corners clipping the icon or text the corner radius will be
|
||||||
automatically lowered to half of the notification height if it exceeds it.
|
automatically lowered to half of the notification height if it exceeds it.
|
||||||
|
|
||||||
|
=item B<mouse_left/middle/right_click> (values: [none/do_action/close_current/close_all])
|
||||||
|
|
||||||
|
Defines action of mouse click.
|
||||||
|
|
||||||
|
=over 4
|
||||||
|
|
||||||
|
=item B<none>
|
||||||
|
|
||||||
|
Don't do anything.
|
||||||
|
|
||||||
|
=item B<do_action> (default for mouse_middle_click)
|
||||||
|
|
||||||
|
If the notification has exactly one action, or one is marked as default, invoke it. If there are multiple and no default, open the context menu.
|
||||||
|
|
||||||
|
=item B<close_current> (default for mouse_left_click)
|
||||||
|
|
||||||
|
Close current notification.
|
||||||
|
|
||||||
|
=item B<close_all> (default for mouse_right_click)
|
||||||
|
|
||||||
|
Close all notifications.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=head2 Shortcut section
|
=head2 Shortcut section
|
||||||
|
24
dunstrc
24
dunstrc
@ -226,6 +226,19 @@
|
|||||||
# layout changes.
|
# layout changes.
|
||||||
force_xinerama = false
|
force_xinerama = false
|
||||||
|
|
||||||
|
### mouse
|
||||||
|
|
||||||
|
# Defines action of mouse event
|
||||||
|
# Possible values are:
|
||||||
|
# * none: Don't do anything.
|
||||||
|
# * do_action: If the notification has exactly one action, or one is marked as default,
|
||||||
|
# invoke it. If there are multiple and no default, open the context menu.
|
||||||
|
# * close_current: Close current notification.
|
||||||
|
# * close_all: Close all notifications.
|
||||||
|
mouse_left_click = close_current
|
||||||
|
mouse_middle_click = do_action
|
||||||
|
mouse_right_click = close_all
|
||||||
|
|
||||||
# Experimental features that may or may not work correctly. Do not expect them
|
# Experimental features that may or may not work correctly. Do not expect them
|
||||||
# to have a consistent behaviour across releases.
|
# to have a consistent behaviour across releases.
|
||||||
[experimental]
|
[experimental]
|
||||||
@ -258,17 +271,6 @@
|
|||||||
# Context menu.
|
# Context menu.
|
||||||
context = ctrl+shift+period
|
context = ctrl+shift+period
|
||||||
|
|
||||||
# Defines action of mouse event
|
|
||||||
# Possible values are:
|
|
||||||
# * do_action: If the notification has exactly one action, or one is marked as default,
|
|
||||||
# invoke it. If there are multiple and no default, open the context menu.
|
|
||||||
# * close_current: Close current notification.
|
|
||||||
# * push_all: Push all waiting and displayed notifications to history.
|
|
||||||
[mouse]
|
|
||||||
left_click = close_current
|
|
||||||
middle_click = do_action
|
|
||||||
right_click = push_all
|
|
||||||
|
|
||||||
[urgency_low]
|
[urgency_low]
|
||||||
# IMPORTANT: colors have to be defined in quotation marks.
|
# IMPORTANT: colors have to be defined in quotation marks.
|
||||||
# Otherwise the "#" and following would be interpreted as a comment.
|
# Otherwise the "#" and following would be interpreted as a comment.
|
||||||
|
@ -49,6 +49,23 @@ static enum markup_mode parse_markup_mode(const char *mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static enum mouse_action parse_mouse_action(const char *action)
|
||||||
|
{
|
||||||
|
if (strcmp(action, "none") == 0)
|
||||||
|
return MOUSE_NONE;
|
||||||
|
else if (strcmp(action, "do_action") == 0)
|
||||||
|
return MOUSE_DO_ACTION;
|
||||||
|
else if (strcmp(action, "close_current") == 0)
|
||||||
|
return MOUSE_CLOSE_CURRENT;
|
||||||
|
else if (strcmp(action, "close_all") == 0)
|
||||||
|
return MOUSE_CLOSE_ALL;
|
||||||
|
else {
|
||||||
|
LOG_W("Unknown mouse action: '%s'", action);
|
||||||
|
return MOUSE_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static enum urgency ini_get_urgency(const char *section, const char *key, const int def)
|
static enum urgency ini_get_urgency(const char *section, const char *key, const int def)
|
||||||
{
|
{
|
||||||
int ret = def;
|
int ret = def;
|
||||||
@ -519,64 +536,34 @@ void load_settings(char *cmdline_config_path)
|
|||||||
|
|
||||||
{
|
{
|
||||||
char *c = option_get_string(
|
char *c = option_get_string(
|
||||||
"mouse",
|
"global",
|
||||||
"left_click", "-left_click", "close_current",
|
"mouse_left_click", "-left_click", "close_current",
|
||||||
"Action of Left click event"
|
"Action of Left click event"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (strlen(c) > 0) {
|
settings.mouse_left_click = parse_mouse_action(c);
|
||||||
if (strcmp(c, "do_action") == 0)
|
|
||||||
settings.left_click = do_action;
|
|
||||||
else if (strcmp(c, "close_current") == 0)
|
|
||||||
settings.left_click = close_current;
|
|
||||||
else if (strcmp(c, "push_all") == 0)
|
|
||||||
settings.left_click = push_all;
|
|
||||||
else {
|
|
||||||
LOG_W("Unknown left_click position: '%s'", c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_free(c);
|
g_free(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
char *c = option_get_string(
|
char *c = option_get_string(
|
||||||
"mouse",
|
"global",
|
||||||
"middle_click", "-middel_click", "do_action",
|
"mouse_middle_click", "-mouse_middle_click", "do_action",
|
||||||
"Action of middle click event"
|
"Action of middle click event"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (strlen(c) > 0) {
|
settings.mouse_middle_click = parse_mouse_action(c);
|
||||||
if (strcmp(c, "do_action") == 0)
|
|
||||||
settings.middle_click = do_action;
|
|
||||||
else if (strcmp(c, "close_current") == 0)
|
|
||||||
settings.middle_click = close_current;
|
|
||||||
else if (strcmp(c, "push_all") == 0)
|
|
||||||
settings.middle_click = push_all;
|
|
||||||
else {
|
|
||||||
LOG_W("Unknown middle_click position: '%s'", c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_free(c);
|
g_free(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
char *c = option_get_string(
|
char *c = option_get_string(
|
||||||
"mouse",
|
"global",
|
||||||
"right_click", "-right_click", "push_all",
|
"mouse_right_click", "-mouse_right_click", "close_all",
|
||||||
"Action of right click event"
|
"Action of right click event"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (strlen(c) > 0) {
|
settings.mouse_right_click = parse_mouse_action(c);
|
||||||
if (strcmp(c, "do_action") == 0)
|
|
||||||
settings.right_click = do_action;
|
|
||||||
else if (strcmp(c, "close_current") == 0)
|
|
||||||
settings.right_click = close_current;
|
|
||||||
else if (strcmp(c, "push_all") == 0)
|
|
||||||
settings.right_click = push_all;
|
|
||||||
else {
|
|
||||||
LOG_W("Unknown right_click position: '%s'", c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_free(c);
|
g_free(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ enum icon_position_t { icons_left, icons_right, icons_off };
|
|||||||
enum separator_color { SEP_FOREGROUND, SEP_AUTO, SEP_FRAME, SEP_CUSTOM };
|
enum separator_color { SEP_FOREGROUND, SEP_AUTO, SEP_FRAME, SEP_CUSTOM };
|
||||||
enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD };
|
enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD };
|
||||||
enum markup_mode { MARKUP_NULL, MARKUP_NO, MARKUP_STRIP, MARKUP_FULL };
|
enum markup_mode { MARKUP_NULL, MARKUP_NO, MARKUP_STRIP, MARKUP_FULL };
|
||||||
enum mouse_action { do_action, close_current, push_all };
|
enum mouse_action { MOUSE_NONE, MOUSE_DO_ACTION, MOUSE_CLOSE_CURRENT, MOUSE_CLOSE_ALL };
|
||||||
|
|
||||||
struct geometry {
|
struct geometry {
|
||||||
int x;
|
int x;
|
||||||
@ -86,9 +86,9 @@ typedef struct _settings {
|
|||||||
keyboard_shortcut context_ks;
|
keyboard_shortcut context_ks;
|
||||||
bool force_xinerama;
|
bool force_xinerama;
|
||||||
int corner_radius;
|
int corner_radius;
|
||||||
enum mouse_action left_click;
|
enum mouse_action mouse_left_click;
|
||||||
enum mouse_action middle_click;
|
enum mouse_action mouse_middle_click;
|
||||||
enum mouse_action right_click;
|
enum mouse_action mouse_right_click;
|
||||||
} settings_t;
|
} settings_t;
|
||||||
|
|
||||||
extern settings_t settings;
|
extern settings_t settings;
|
||||||
|
15
src/x11/x.c
15
src/x11/x.c
@ -390,23 +390,26 @@ static void x_handle_click(XEvent ev)
|
|||||||
|
|
||||||
switch (ev.xbutton.button) {
|
switch (ev.xbutton.button) {
|
||||||
case Button1:
|
case Button1:
|
||||||
act = settings.left_click;
|
act = settings.mouse_left_click;
|
||||||
break;
|
break;
|
||||||
case Button2:
|
case Button2:
|
||||||
act = settings.middle_click;
|
act = settings.mouse_middle_click;
|
||||||
break;
|
break;
|
||||||
case Button3:
|
case Button3:
|
||||||
act = settings.right_click;
|
act = settings.mouse_right_click;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
LOG_W("Unsupported mouse button: '%d'", ev.xbutton.button);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (act == push_all) {
|
if (act == MOUSE_CLOSE_ALL) {
|
||||||
queues_history_push_all();
|
queues_history_push_all();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (act == do_action || act == close_current) {
|
if (act == MOUSE_DO_ACTION || act == MOUSE_CLOSE_CURRENT) {
|
||||||
int y = settings.separator_height;
|
int y = settings.separator_height;
|
||||||
notification *n = NULL;
|
notification *n = NULL;
|
||||||
int first = true;
|
int first = true;
|
||||||
@ -422,7 +425,7 @@ static void x_handle_click(XEvent ev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (n) {
|
if (n) {
|
||||||
if (act == close_current)
|
if (act == MOUSE_CLOSE_CURRENT)
|
||||||
queues_notification_close(n, REASON_USER);
|
queues_notification_close(n, REASON_USER);
|
||||||
else
|
else
|
||||||
notification_do_action(n);
|
notification_do_action(n);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user