forked from enlightenment/efl
evas: add example for multiseat events
Also useful to make some tests / debugging.
This commit is contained in:
parent
639e0eeaf5
commit
887be4d4e5
|
@ -54,6 +54,7 @@
|
||||||
/evas_map_utils
|
/evas_map_utils
|
||||||
/evas_map_utils_eo
|
/evas_map_utils_eo
|
||||||
/evas_multi_touch
|
/evas_multi_touch
|
||||||
|
/evas_multiseat_events
|
||||||
/evas_object_manipulation
|
/evas_object_manipulation
|
||||||
/evas_object_manipulation-eo
|
/evas_object_manipulation-eo
|
||||||
/evas_smart_interface
|
/evas_smart_interface
|
||||||
|
|
|
@ -119,6 +119,11 @@ evas_events_SOURCES = evas-events.c
|
||||||
evas_events_LDADD = $(ECORE_EVAS_COMMON_LDADD)
|
evas_events_LDADD = $(ECORE_EVAS_COMMON_LDADD)
|
||||||
evas_events_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
|
evas_events_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
|
||||||
|
|
||||||
|
EXTRA_PROGRAMS += evas_multiseat_events
|
||||||
|
evas_multiseat_events_SOURCES = evas-multiseat-events.c
|
||||||
|
evas_multiseat_events_LDADD = $(ECORE_EVAS_COMMON_LDADD)
|
||||||
|
evas_multiseat_events_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
|
||||||
|
|
||||||
EXTRA_PROGRAMS += evas_object_manipulation
|
EXTRA_PROGRAMS += evas_object_manipulation
|
||||||
evas_object_manipulation_SOURCES = evas-object-manipulation.c
|
evas_object_manipulation_SOURCES = evas-object-manipulation.c
|
||||||
evas_object_manipulation_LDADD = $(ECORE_EVAS_COMMON_LDADD)
|
evas_object_manipulation_LDADD = $(ECORE_EVAS_COMMON_LDADD)
|
||||||
|
|
|
@ -0,0 +1,300 @@
|
||||||
|
/**
|
||||||
|
* Evas example illustrating how to handle events with multiseat information:
|
||||||
|
* * mouse events
|
||||||
|
* * keyboard events
|
||||||
|
* * focus events
|
||||||
|
*
|
||||||
|
* You'll need at least one engine built for it (excluding the buffer
|
||||||
|
* one) and the png image loader also built. See stdout/stderr for
|
||||||
|
* output.
|
||||||
|
*
|
||||||
|
* @verbatim
|
||||||
|
* gcc -o evas_multiseat_events evas-multiseat-events.c `pkg-config --libs --cflags evas ecore ecore-evas`
|
||||||
|
* @endverbatim
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <Ecore.h>
|
||||||
|
#include <Ecore_Evas.h>
|
||||||
|
#include <Efl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define WIDTH (400)
|
||||||
|
#define HEIGHT (200)
|
||||||
|
|
||||||
|
static void
|
||||||
|
_canvas_focus_in_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||||
|
{
|
||||||
|
Efl_Input_Device *seat;
|
||||||
|
Efl_Input_Focus *ev;
|
||||||
|
Evas_Object *focused;
|
||||||
|
|
||||||
|
ev = event->info;
|
||||||
|
seat = efl_input_device_get(ev);
|
||||||
|
focused = efl_input_focus_object_get(ev);
|
||||||
|
|
||||||
|
fprintf(stdout, "Object %s was focused by seat %s\n",
|
||||||
|
evas_object_name_get(focused),
|
||||||
|
efl_input_device_name_get(seat));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_hold_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||||
|
{
|
||||||
|
Efl_Input_Device *seat;
|
||||||
|
Efl_Input_Hold *ev;
|
||||||
|
|
||||||
|
ev = event->info;
|
||||||
|
seat = efl_input_device_seat_get(efl_input_device_get(ev));
|
||||||
|
|
||||||
|
fprintf(stdout, "Hold %s at object %s from seat %s\n",
|
||||||
|
efl_input_hold_get(ev) ? "on" : "off",
|
||||||
|
evas_object_name_get(event->object),
|
||||||
|
efl_input_device_name_get(seat));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_focus_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||||
|
{
|
||||||
|
Efl_Input_Device *seat;
|
||||||
|
Efl_Input_Focus *ev;
|
||||||
|
|
||||||
|
ev = event->info;
|
||||||
|
seat = efl_input_device_get(ev);
|
||||||
|
|
||||||
|
fprintf(stdout, "Focus %s at object %s from seat %s\n",
|
||||||
|
event->desc == EFL_EVENT_FOCUS_IN ? "in" : "out",
|
||||||
|
evas_object_name_get(event->object),
|
||||||
|
efl_input_device_name_get(seat));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_pointer_in_out_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||||
|
{
|
||||||
|
Efl_Input_Pointer *ev;
|
||||||
|
Efl_Input_Device *seat;
|
||||||
|
|
||||||
|
ev = event->info;
|
||||||
|
seat = efl_input_device_seat_get(efl_input_device_get(ev));
|
||||||
|
|
||||||
|
fprintf(stdout, "Pointer %s at object %s from seat %s\n",
|
||||||
|
event->desc == EFL_EVENT_POINTER_IN ? "in" : "out",
|
||||||
|
evas_object_name_get(event->object),
|
||||||
|
efl_input_device_name_get(seat));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_pointer_down_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||||
|
{
|
||||||
|
Efl_Input_Pointer *ev;
|
||||||
|
Efl_Input_Device *seat;
|
||||||
|
Efl_Pointer_Flags pointer_flags;
|
||||||
|
char buf[256];
|
||||||
|
|
||||||
|
ev = event->info;
|
||||||
|
seat = efl_input_device_seat_get(efl_input_device_get(ev));
|
||||||
|
pointer_flags = efl_input_pointer_button_flags_get(ev);
|
||||||
|
|
||||||
|
if (pointer_flags & EFL_POINTER_FLAGS_TRIPLE_CLICK)
|
||||||
|
snprintf(buf, sizeof(buf), "Triple click with button %i",
|
||||||
|
efl_input_pointer_button_get(ev));
|
||||||
|
else if (pointer_flags & EFL_POINTER_FLAGS_DOUBLE_CLICK)
|
||||||
|
snprintf(buf, sizeof(buf), "Double click with button %i",
|
||||||
|
efl_input_pointer_button_get(ev));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(buf, sizeof(buf), "Pointer button %i down",
|
||||||
|
efl_input_pointer_button_get(ev));
|
||||||
|
efl_canvas_object_seat_focus_add(event->object, seat);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stdout, "%s at object %s from seat %s\n", buf,
|
||||||
|
evas_object_name_get(event->object),
|
||||||
|
efl_input_device_name_get(seat));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_pointer_up_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||||
|
{
|
||||||
|
Efl_Input_Pointer *ev;
|
||||||
|
Efl_Input_Device *seat;
|
||||||
|
|
||||||
|
ev = event->info;
|
||||||
|
seat = efl_input_device_seat_get(efl_input_device_get(ev));
|
||||||
|
|
||||||
|
fprintf(stdout, "Pointer button %i up at object %s from seat %s\n",
|
||||||
|
efl_input_pointer_button_get(ev),
|
||||||
|
evas_object_name_get(event->object),
|
||||||
|
efl_input_device_name_get(seat));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_pointer_move_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||||
|
{
|
||||||
|
Efl_Input_Pointer *ev;
|
||||||
|
Efl_Input_Device *seat;
|
||||||
|
|
||||||
|
ev = event->info;
|
||||||
|
seat = efl_input_device_seat_get(efl_input_device_get(ev));
|
||||||
|
|
||||||
|
fprintf(stdout, "Pointer moved to %1.f,%1.f at object %s from seat %s\n",
|
||||||
|
efl_input_pointer_value_get(ev, EFL_INPUT_VALUE_X),
|
||||||
|
efl_input_pointer_value_get(ev, EFL_INPUT_VALUE_Y),
|
||||||
|
evas_object_name_get(event->object),
|
||||||
|
efl_input_device_name_get(seat));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_pointer_wheel_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||||
|
{
|
||||||
|
Efl_Input_Pointer *ev;
|
||||||
|
Efl_Input_Device *seat;
|
||||||
|
|
||||||
|
ev = event->info;
|
||||||
|
seat = efl_input_device_seat_get(efl_input_device_get(ev));
|
||||||
|
|
||||||
|
fprintf(stdout, "Wheel: '%i,%i' on object %s from seat %s\n",
|
||||||
|
efl_input_pointer_wheel_direction_get(ev),
|
||||||
|
efl_input_pointer_wheel_delta_get(ev),
|
||||||
|
evas_object_name_get(event->object),
|
||||||
|
efl_input_device_name_get(seat));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_key_down_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||||
|
{
|
||||||
|
const Evas_Modifier *mods;
|
||||||
|
Efl_Input_Device *seat;
|
||||||
|
Efl_Input_Key *ev;
|
||||||
|
|
||||||
|
ev = event->info;
|
||||||
|
mods = evas_key_modifier_get(evas_object_evas_get(event->object));
|
||||||
|
seat = efl_input_device_seat_get(efl_input_device_get(ev));
|
||||||
|
|
||||||
|
fprintf(stdout, "Key down: '%s' on object %s from seat %s\n",
|
||||||
|
efl_input_key_name_get(ev),
|
||||||
|
evas_object_name_get(event->object),
|
||||||
|
efl_input_device_name_get(seat));
|
||||||
|
|
||||||
|
// FIXME use evas_seat_key_modifier_is_set() after PR is merged
|
||||||
|
(void) mods;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_key_up_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||||
|
{
|
||||||
|
Efl_Input_Key *ev;
|
||||||
|
Efl_Input_Device *seat;
|
||||||
|
|
||||||
|
ev = event->info;
|
||||||
|
seat = efl_input_device_seat_get(efl_input_device_get(ev));
|
||||||
|
|
||||||
|
fprintf(stdout, "Key up: '%s' on object %s from seat %s\n",
|
||||||
|
efl_input_key_name_get(ev),
|
||||||
|
evas_object_name_get(event->object),
|
||||||
|
efl_input_device_name_get(seat));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_dev_added_or_removed(void *data EINA_UNUSED, const Efl_Event *event)
|
||||||
|
{
|
||||||
|
Efl_Input_Device *dev = event->info;
|
||||||
|
|
||||||
|
if (efl_input_device_type_get(dev) != EFL_INPUT_DEVICE_CLASS_SEAT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fprintf(stdout, "The seat '%s' - description: '%s' was '%s'\n",
|
||||||
|
efl_input_device_name_get(dev),
|
||||||
|
efl_input_device_description_get(dev),
|
||||||
|
event->desc == EFL_CANVAS_EVENT_DEVICE_ADDED ? "added" : "removed");
|
||||||
|
}
|
||||||
|
|
||||||
|
EFL_CALLBACKS_ARRAY_DEFINE(canvas_callbacks,
|
||||||
|
{ EFL_CANVAS_EVENT_OBJECT_FOCUS_IN,
|
||||||
|
_canvas_focus_in_cb },
|
||||||
|
{ EFL_CANVAS_EVENT_DEVICE_ADDED,
|
||||||
|
_dev_added_or_removed },
|
||||||
|
{ EFL_CANVAS_EVENT_DEVICE_REMOVED,
|
||||||
|
_dev_added_or_removed });
|
||||||
|
|
||||||
|
EFL_CALLBACKS_ARRAY_DEFINE(callbacks,
|
||||||
|
{ EFL_EVENT_FOCUS_IN, _focus_cb },
|
||||||
|
{ EFL_EVENT_FOCUS_OUT, _focus_cb },
|
||||||
|
{ EFL_EVENT_KEY_DOWN, _key_down_cb },
|
||||||
|
{ EFL_EVENT_KEY_UP, _key_up_cb },
|
||||||
|
{ EFL_EVENT_HOLD, _hold_cb },
|
||||||
|
{ EFL_EVENT_POINTER_IN, _pointer_in_out_cb },
|
||||||
|
{ EFL_EVENT_POINTER_OUT, _pointer_in_out_cb },
|
||||||
|
{ EFL_EVENT_POINTER_DOWN, _pointer_down_cb },
|
||||||
|
{ EFL_EVENT_POINTER_UP, _pointer_up_cb },
|
||||||
|
{ EFL_EVENT_POINTER_MOVE, _pointer_move_cb },
|
||||||
|
{ EFL_EVENT_POINTER_WHEEL, _pointer_wheel_cb });
|
||||||
|
|
||||||
|
int
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
|
Evas_Object *bg, *red_rect, *blue_rect;
|
||||||
|
const Eina_List *devices, *l;
|
||||||
|
Efl_Input_Device *dev;
|
||||||
|
Ecore_Evas *ee;
|
||||||
|
Evas *canvas;
|
||||||
|
|
||||||
|
if (!ecore_evas_init())
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
|
ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
|
||||||
|
if (!ee)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
canvas = ecore_evas_get(ee);
|
||||||
|
efl_event_callback_array_add(canvas, canvas_callbacks(), NULL);
|
||||||
|
|
||||||
|
bg = evas_object_rectangle_add(canvas);
|
||||||
|
evas_object_name_set(bg, "background");
|
||||||
|
evas_object_color_set(bg, 255, 255, 255, 255);
|
||||||
|
evas_object_move(bg, 0, 0);
|
||||||
|
evas_object_resize(bg, WIDTH, HEIGHT);
|
||||||
|
evas_object_show(bg);
|
||||||
|
|
||||||
|
red_rect = evas_object_rectangle_add(canvas);
|
||||||
|
evas_object_name_set(red_rect, "red rect");
|
||||||
|
evas_object_color_set(red_rect, 255, 0, 0, 255);
|
||||||
|
evas_object_move(red_rect, WIDTH/4, HEIGHT/4);
|
||||||
|
evas_object_resize(red_rect, WIDTH/4 - 10, HEIGHT/2);
|
||||||
|
evas_object_show(red_rect);
|
||||||
|
efl_event_callback_array_add(red_rect, callbacks(), NULL);
|
||||||
|
|
||||||
|
blue_rect = evas_object_rectangle_add(canvas);
|
||||||
|
evas_object_name_set(blue_rect, "blue rect");
|
||||||
|
evas_object_color_set(blue_rect, 0, 0, 255, 255);
|
||||||
|
evas_object_move(blue_rect, WIDTH/2 + 10, HEIGHT/4);
|
||||||
|
evas_object_resize(blue_rect, WIDTH/4 - 10, HEIGHT/2);
|
||||||
|
evas_object_show(blue_rect);
|
||||||
|
efl_event_callback_array_add(blue_rect, callbacks(), NULL);
|
||||||
|
|
||||||
|
devices = evas_device_list(canvas, NULL);
|
||||||
|
EINA_LIST_FOREACH(devices, l, dev)
|
||||||
|
{
|
||||||
|
if (efl_input_device_type_get(dev) == EFL_INPUT_DEVICE_CLASS_SEAT)
|
||||||
|
fprintf(stdout, "The seat '%s' - description: '%s' was 'added'\n",
|
||||||
|
efl_input_device_name_get(dev),
|
||||||
|
efl_input_device_description_get(dev));
|
||||||
|
}
|
||||||
|
|
||||||
|
ecore_evas_show(ee);
|
||||||
|
ecore_main_loop_begin();
|
||||||
|
|
||||||
|
ecore_evas_free(ee);
|
||||||
|
ecore_evas_shutdown();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
error:
|
||||||
|
fprintf(stderr, "At least one evas engine built and linked up to ecore evas "
|
||||||
|
"is required for this example to run properly.\n");
|
||||||
|
ecore_evas_shutdown();
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
Loading…
Reference in New Issue