commit 3097d0698dfb729f66590d39cdd8a877818099da
parent aa0f5c22797d3e60d3f016c794aabbb840bad40a
Author: Bastien Dejean <nihilhill@gmail.com>
Date: Fri, 27 Dec 2013 11:19:55 +0100
Add an option to specify the motion events maximum frequency
Diffstat:
4 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/doc/sxhkd.1 b/doc/sxhkd.1
@@ -2,12 +2,12 @@
.\" Title: sxhkd
.\" Author: [see the "Author" section]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
-.\" Date: 12/05/2013
+.\" Date: 12/27/2013
.\" Manual: Sxhkd Manual
.\" Source: Sxhkd 0.5.3
.\" Language: English
.\"
-.TH "SXHKD" "1" "12/05/2013" "Sxhkd 0\&.5\&.3" "Sxhkd Manual"
+.TH "SXHKD" "1" "12/27/2013" "Sxhkd 0\&.5\&.3" "Sxhkd Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -71,6 +71,11 @@ Redirect the commands output to the given file\&.
.RS 4
Output status information to the given FIFO\&.
.RE
+.PP
+\fB\-f\fR \fIFREQUENCY\fR
+.RS 4
+Set the maximum frequency for motion events\&.
+.RE
.SH "CONFIGURATION"
.sp
Each line of the configuration file is interpreted as so:
diff --git a/doc/sxhkd.1.txt b/doc/sxhkd.1.txt
@@ -45,6 +45,9 @@ Options
*-s* _STATUS_FIFO_::
Output status information to the given FIFO.
+*-f* _FREQUENCY_::
+ Set the maximum frequency for motion events.
+
Configuration
-------------
diff --git a/sxhkd.c b/sxhkd.c
@@ -44,8 +44,11 @@ int main(int argc, char *argv[])
config_path = NULL;
ignore_mapping = false;
timeout = TIMEOUT;
+ unsigned int max_freq = 0;
+ motion_interval = 0;
+ last_motion_time = 0;
- while ((opt = getopt(argc, argv, "vhnt:c:r:s:")) != (char)-1) {
+ while ((opt = getopt(argc, argv, "vhnt:c:r:s:f:")) != (char)-1) {
switch (opt) {
case 'v':
printf("%s\n", VERSION);
@@ -72,6 +75,10 @@ int main(int argc, char *argv[])
case 's':
fifo_path = optarg;
break;
+ case 'f':
+ if (sscanf(optarg, "%u", &max_freq) != 1)
+ warn("Can't parse maximum pointer frequency.\n");
+ break;
}
}
@@ -96,6 +103,9 @@ int main(int argc, char *argv[])
warn("Couldn't open status fifo.\n");
}
+ if (max_freq != 0)
+ motion_interval = 1000.0 / max_freq;
+
signal(SIGINT, hold);
signal(SIGHUP, hold);
signal(SIGTERM, hold);
@@ -221,6 +231,9 @@ void motion_notify(xcb_generic_event_t *evt, uint8_t event_type)
{
xcb_motion_notify_event_t *e = (xcb_motion_notify_event_t *) evt;
/* PRINTF("motion notify %X %X %u\n", e->child, e->detail, e->state); */
+ if (motion_interval > 0 && (e->time - last_motion_time) < motion_interval)
+ return;
+ last_motion_time = e->time;
uint16_t lockfield = num_lock | caps_lock | scroll_lock;
uint16_t buttonfield = e->state >> 8;
uint16_t modfield = e->state & ~lockfield & MOD_STATE_FIELD;
diff --git a/sxhkd.h b/sxhkd.h
@@ -54,6 +54,8 @@ FILE *status_fifo;
char progress[3 * MAXLEN];
bool ignore_mapping;
int timeout;
+double motion_interval;
+xcb_timestamp_t last_motion_time;
hotkey_t *hotkeys_head, *hotkeys_tail;
bool running, reload, bell, chained, locked;