* [PATCH] input: Add soft kill switch for input devices
@ 2015-01-04 6:24 Tristan Lelong
2015-01-06 21:17 ` Bruno Prémont
0 siblings, 1 reply; 3+ messages in thread
From: Tristan Lelong @ 2015-01-04 6:24 UTC (permalink / raw)
To: dmitry.torokhov; +Cc: linux-input, linux-kernel, Tristan Lelong
This adds a sysfs attribute named 'mute' to all input devices.
It allows to disable them by software in a generic way.
It can be set to 0 or 1:
echo 1 > /sys/class/input/inputX/mute: will set all the input_events() call to return immediately.
echo 0 > /sys/class/input/inputX/mute: will reset to default behavior.
mute is set to 0 by default when calling alloc_input_device().
Signed-off-by: Tristan Lelong <tristan@lelong.xyz>
---
Hi,
I created this patch to answer a need on my machine: I want to be able to disable momentarily the touchscreen
in order to wipe out a dust or clean the display without creating a mess on my desktop and opened docs.
It seemed consistent to have that kill switch at a central point, and moreover,
it doesn't depend on any tool linked to a specifc X server, graphical toolkit, desktop environment...
This patch uses the 0/1 values to enable or disable the mute, but I could update it to use
enable/disable instead if it is preferred.
Also, the permissions are write for group or ownoer only.
I thought about setting it world writable in order to allow easy shortcut creation, but it might also be a security flaw.
Let me know what you think about all this, at least it is really useful in my case, linked to a keyboard shortcut.
Best regards
---
drivers/input/input.c | 30 +++++++++++++++++++++++++++++-
include/linux/input.h | 1 +
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/drivers/input/input.c b/drivers/input/input.c
index a1e609a..2f80fee 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -425,7 +425,7 @@ void input_event(struct input_dev *dev,
{
unsigned long flags;
- if (is_event_supported(type, dev->evbit, EV_MAX)) {
+ if (!dev->mute && is_event_supported(type, dev->evbit, EV_MAX)) {
spin_lock_irqsave(&dev->event_lock, flags);
input_handle_event(dev, type, code, value);
@@ -1384,10 +1384,38 @@ static ssize_t input_dev_show_properties(struct device *dev,
}
static DEVICE_ATTR(properties, S_IRUGO, input_dev_show_properties, NULL);
+static ssize_t input_dev_show_mute(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct input_dev *input_dev = to_input_dev(dev);
+
+ return scnprintf(buf, PAGE_SIZE, "%d\n", input_dev->mute);
+}
+
+static ssize_t input_dev_store_mute(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ int err;
+ long mute;
+ struct input_dev *input_dev = to_input_dev(dev);
+
+ err = kstrtol(buf, 0, &mute);
+ if (err < 0)
+ return err;
+ input_dev->mute = mute;
+
+ return count;
+}
+static DEVICE_ATTR(mute, S_IRUGO | S_IWUSR | S_IWGRP, input_dev_show_mute,
+ input_dev_store_mute);
+
static struct attribute *input_dev_attrs[] = {
&dev_attr_name.attr,
&dev_attr_phys.attr,
&dev_attr_uniq.attr,
+ &dev_attr_mute.attr,
&dev_attr_modalias.attr,
&dev_attr_properties.attr,
NULL
diff --git a/include/linux/input.h b/include/linux/input.h
index 3b4c32f..e45672f 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -151,6 +151,7 @@ struct input_dev {
struct ff_device *ff;
+ unsigned int mute;
unsigned int repeat_key;
struct timer_list timer;
--
2.1.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] input: Add soft kill switch for input devices
2015-01-04 6:24 [PATCH] input: Add soft kill switch for input devices Tristan Lelong
@ 2015-01-06 21:17 ` Bruno Prémont
2015-01-07 6:40 ` Tristan Lelong
0 siblings, 1 reply; 3+ messages in thread
From: Bruno Prémont @ 2015-01-06 21:17 UTC (permalink / raw)
To: Tristan Lelong; +Cc: linux-input, dmitry.torokhov, linux-kernel
On Sat, 03 January 2015 Tristan Lelong <tristan@lelong.xyz> wrote:
> This adds a sysfs attribute named 'mute' to all input devices.
> It allows to disable them by software in a generic way.
>
> It can be set to 0 or 1:
> echo 1 > /sys/class/input/inputX/mute: will set all the input_events() call to return immediately.
> echo 0 > /sys/class/input/inputX/mute: will reset to default behavior.
>
> mute is set to 0 by default when calling alloc_input_device().
>
> Signed-off-by: Tristan Lelong <tristan@lelong.xyz>
> ---
> Hi,
>
> I created this patch to answer a need on my machine: I want to be able to disable momentarily the touchscreen
> in order to wipe out a dust or clean the display without creating a mess on my desktop and opened docs.
> It seemed consistent to have that kill switch at a central point, and moreover,
> it doesn't depend on any tool linked to a specifc X server, graphical toolkit, desktop environment...
>
> This patch uses the 0/1 values to enable or disable the mute, but I could update it to use
> enable/disable instead if it is preferred.
> Also, the permissions are write for group or ownoer only.
> I thought about setting it world writable in order to allow easy shortcut creation, but it might also be a security flaw.
>
> Let me know what you think about all this, at least it is really useful in my case, linked to a keyboard shortcut.
>
> Best regards
> ---
> drivers/input/input.c | 30 +++++++++++++++++++++++++++++-
> include/linux/input.h | 1 +
> 2 files changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index a1e609a..2f80fee 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -425,7 +425,7 @@ void input_event(struct input_dev *dev,
> {
> unsigned long flags;
>
> - if (is_event_supported(type, dev->evbit, EV_MAX)) {
> + if (!dev->mute && is_event_supported(type, dev->evbit, EV_MAX)) {
>
> spin_lock_irqsave(&dev->event_lock, flags);
> input_handle_event(dev, type, code, value);
> @@ -1384,10 +1384,38 @@ static ssize_t input_dev_show_properties(struct device *dev,
> <snip>
One big issue I see here is that you start dropping all events at a random
point in time.
You may end up within a gesture or just while a button is down and remain
so until that same button gets pressed again on unmute.
On your touchscreen, how do things behave if you trigger the muting while
you are dragging or doing some gesture (and unmute when noone touches
the touchscreen)?
If applied to a keyboard, what happens when you mute while keys are pressed
and unmute when they have long been released?
If you could send a "reset" event to input listeners when muting you could
work around most issues as any application making use of events would know
that after this "reset" event things should not depend on any past state.
Possibly a better way to achieve your aim is to just unbind and re-bind
the device from device driver, causing software hotplug.
That way you are sure no application will perform incorrect guesses while
device is "muted".
Bruno
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] input: Add soft kill switch for input devices
2015-01-06 21:17 ` Bruno Prémont
@ 2015-01-07 6:40 ` Tristan Lelong
0 siblings, 0 replies; 3+ messages in thread
From: Tristan Lelong @ 2015-01-07 6:40 UTC (permalink / raw)
To: Bruno Prémont; +Cc: linux-input, dmitry.torokhov, linux-kernel
On Tue, Jan 06, 2015 at 10:17:32PM +0100, Bruno Prémont wrote:
>
> One big issue I see here is that you start dropping all events at a random
> point in time.
> You may end up within a gesture or just while a button is down and remain
> so until that same button gets pressed again on unmute.
>
> On your touchscreen, how do things behave if you trigger the muting while
> you are dragging or doing some gesture (and unmute when noone touches
> the touchscreen)?
That is right, I thought of it for pointing devices, and it seemed that it should not be
too much of a problem, even thought it would be better to handle it properly.
>
> If applied to a keyboard, what happens when you mute while keys are pressed
> and unmute when they have long been released?
This case is actually a bigger problem and I didn't think of it.
>
>
> If you could send a "reset" event to input listeners when muting you could
> work around most issues as any application making use of events would know
> that after this "reset" event things should not depend on any past state.
I could definitely do something like this and make sure all the events are handled properly.
>
>
> Possibly a better way to achieve your aim is to just unbind and re-bind
> the device from device driver, causing software hotplug.
> That way you are sure no application will perform incorrect guesses while
> device is "muted".
This is another good solution that would work in my case.
If somebody think this patch can be of any interest, I'll be happy to
submit a v2 with correct handling of current events at the time of mutting.
Best regards
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-01-07 6:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-04 6:24 [PATCH] input: Add soft kill switch for input devices Tristan Lelong
2015-01-06 21:17 ` Bruno Prémont
2015-01-07 6:40 ` Tristan Lelong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).