[weston,v2] input: Use slightly less obscure logic in evdev_notify_keyboard_focus()

Submitted by Derek Foreman on Nov. 19, 2014, 5:04 p.m.

Details

Message ID 1416416652-372-1-git-send-email-derekf@osg.samsung.com
State Accepted
Commit d621df2dee522d9768a8aff1dd200f3595e29c65
Headers show

Not browsing as part of any series.

Commit Message

Derek Foreman Nov. 19, 2014, 5:04 p.m.
While the test is actually correct (for non-negative numbers), it's not
at all clear and seems to be an accidental order of operations mistake.

Also, add an assert() to make sure this number is never negative.

Closes bug 86346 - https://bugs.freedeskto.org/show_bug.cgi?id=86346

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
---

This version just moves the assert directly after the decrement...

 src/input.c           | 1 +
 src/libinput-device.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/src/input.c b/src/input.c
index 5f19875..cd5e10b 100644
--- a/src/input.c
+++ b/src/input.c
@@ -2203,6 +2203,7 @@  WL_EXPORT void
 weston_seat_release_keyboard(struct weston_seat *seat)
 {
 	seat->keyboard_device_count--;
+	assert(seat->keyboard_device_count >= 0);
 	if (seat->keyboard_device_count == 0) {
 		weston_keyboard_set_focus(seat->keyboard, NULL);
 		weston_keyboard_cancel_grab(seat->keyboard);
diff --git a/src/libinput-device.c b/src/libinput-device.c
index 0e3f46d..8a48905 100644
--- a/src/libinput-device.c
+++ b/src/libinput-device.c
@@ -470,7 +470,7 @@  evdev_notify_keyboard_focus(struct weston_seat *seat,
 {
 	struct wl_array keys;
 
-	if (!seat->keyboard_device_count > 0)
+	if (seat->keyboard_device_count == 0)
 		return;
 
 	wl_array_init(&keys);

Comments

On Wed, 19 Nov 2014 11:04:12 -0600
Derek Foreman <derekf@osg.samsung.com> wrote:

> While the test is actually correct (for non-negative numbers), it's not
> at all clear and seems to be an accidental order of operations mistake.
> 
> Also, add an assert() to make sure this number is never negative.
> 
> Closes bug 86346 - https://bugs.freedeskto.org/show_bug.cgi?id=86346
> 
> Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
> ---
> 
> This version just moves the assert directly after the decrement...
> 
>  src/input.c           | 1 +
>  src/libinput-device.c | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/input.c b/src/input.c
> index 5f19875..cd5e10b 100644
> --- a/src/input.c
> +++ b/src/input.c
> @@ -2203,6 +2203,7 @@ WL_EXPORT void
>  weston_seat_release_keyboard(struct weston_seat *seat)
>  {
>  	seat->keyboard_device_count--;
> +	assert(seat->keyboard_device_count >= 0);
>  	if (seat->keyboard_device_count == 0) {
>  		weston_keyboard_set_focus(seat->keyboard, NULL);
>  		weston_keyboard_cancel_grab(seat->keyboard);
> diff --git a/src/libinput-device.c b/src/libinput-device.c
> index 0e3f46d..8a48905 100644
> --- a/src/libinput-device.c
> +++ b/src/libinput-device.c
> @@ -470,7 +470,7 @@ evdev_notify_keyboard_focus(struct weston_seat *seat,
>  {
>  	struct wl_array keys;
>  
> -	if (!seat->keyboard_device_count > 0)
> +	if (seat->keyboard_device_count == 0)
>  		return;
>  
>  	wl_array_init(&keys);

Pushed with Marek's R-b.

Thanks,
pq