use ARRAY_FOR_EACH when traverse array

Signed-off-by: weizhixiang <weizhixiang@uniontech.com>
This commit is contained in:
weizhixiang 2021-05-19 21:09:30 +09:00 committed by Peter Hutterer
parent 0cb570addd
commit cce5921015
2 changed files with 14 additions and 13 deletions

View file

@ -1036,10 +1036,10 @@ static void
handle_event_device_notify(struct libinput_event *ev)
{
struct libinput_device *dev = libinput_event_get_device(ev);
struct libinput_device **device;
struct libinput *li;
struct window *w;
const char *type;
size_t i;
li = libinput_event_get_context(ev);
w = libinput_get_user_data(li);
@ -1060,17 +1060,17 @@ handle_event_device_notify(struct libinput_event *ev)
type);
if (libinput_event_get_type(ev) == LIBINPUT_EVENT_DEVICE_ADDED) {
for (i = 0; i < ARRAY_LENGTH(w->devices); i++) {
if (w->devices[i] == NULL) {
w->devices[i] = libinput_device_ref(dev);
ARRAY_FOR_EACH(w->devices, device) {
if (*device == NULL) {
*device = libinput_device_ref(dev);
break;
}
}
} else {
for (i = 0; i < ARRAY_LENGTH(w->devices); i++) {
if (w->devices[i] == dev) {
libinput_device_unref(w->devices[i]);
w->devices[i] = NULL;
ARRAY_FOR_EACH(w->devices, device) {
if (*device == dev) {
libinput_device_unref(*device);
*device = NULL;
break;
}
}

View file

@ -306,17 +306,18 @@ handle_tablet_button_event(struct context *ctx, struct libinput_event *ev)
{
struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev);
unsigned int button = libinput_event_tablet_tool_get_button(t);
unsigned int *btn;
enum libinput_button_state state = libinput_event_tablet_tool_get_button_state(t);
for (size_t i = 0; i < ARRAY_LENGTH(ctx->buttons_down); i++) {
ARRAY_FOR_EACH(ctx->buttons_down, btn) {
if (state == LIBINPUT_BUTTON_STATE_PRESSED) {
if (ctx->buttons_down[i] == 0) {
ctx->buttons_down[i] = button;
if (*btn == 0) {
*btn = button;
break;
}
} else {
if (ctx->buttons_down[i] == button) {
ctx->buttons_down[i] = 0;
if (*btn == button) {
*btn = 0;
break;
}
}