Merge lp:~jpakkane/libgrip/type_detection_refactoring into lp:libgrip

Proposed by Jussi Pakkanen
Status: Merged
Merged at revision: 55
Proposed branch: lp:~jpakkane/libgrip/type_detection_refactoring
Merge into: lp:libgrip
Diff against target: 86 lines (+31/-17)
1 file modified
src/gripgesturemanager.c (+31/-17)
To merge this branch: bzr merge lp:~jpakkane/libgrip/type_detection_refactoring
Reviewer Review Type Date Requested Status
Chase Douglas (community) Approve
Stephen M. Webb (community) Approve
Review via email: mp+70719@code.launchpad.net

Description of the change

There are two different locations where input attributes are converted to types. This patch consolidates them into a single function.

It is currently static but we should expose this function in API. Since gesture subscription is done with input types, for symmetry they should be easily and directly available. In fact it is worth asking if the direct/independent attributes should be exposed to libgrip users at all. I don't think that's something they really care about. Should libgrip ever get other backends, they might even not provide those attributes.

Depending on feedback I can add the API exposition here or create a new branch.

To post a comment you must log in.
Revision history for this message
Stephen M. Webb (bregma) wrote :

I have no problem with this patch per se. I would hold off on making the function public until we've had a review of the use stories for the API itself.

review: Approve
Revision history for this message
Chase Douglas (chasedouglas) wrote :

Looks good to me too.

I can't think of any reason not to expose the API publicly, so I'm +1 on that. However, I'll defer judgement to Stephen. To give a second take, in utouch-qml I only expose the type of device in the same sense as grip_get_device_type, so it would mirror what is done there.

All that said, we're up against the feature freeze deadline and this is just a convenience addition. I think we should leave it aside for now if we aren't absolutely sure about it rather than rush it in.

review: Approve
Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

The main use story can be found in our touch patch for Evince. It goes through several hoops (setting up different callback functions that call other things etc) which essentially reduces to one if statement in the main callback function. That if just negates the drag amounts if the gesture came from a touchpad. Having this function would make all the extra stuff just go away.

But I'll merge this now and start a new branch for exposing.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/gripgesturemanager.c'
--- src/gripgesturemanager.c 2011-08-04 01:04:47 +0000
+++ src/gripgesturemanager.c 2011-08-08 11:11:21 +0000
@@ -419,6 +419,22 @@
419 return input_device;419 return input_device;
420}420}
421421
422static
423GripDeviceType
424grip_get_device_type (GripInputDevice *input_device) {
425 gboolean is_direct = grip_input_device_is_direct (input_device);
426 gboolean is_independent = grip_input_device_is_independent (input_device);
427 if (is_direct && !is_independent)
428 return GRIP_DEVICE_TOUCHSCREEN;
429 if (!is_direct && !is_independent)
430 return GRIP_DEVICE_TOUCHPAD;
431 if (!is_direct && is_independent)
432 return GRIP_DEVICE_INDEPENDENT;
433
434 g_critical("Unknown touch device type.");
435 return GRIP_DEVICE_TOUCHSCREEN;
436}
437
422/*438/*
423 * registration_for_input_device:439 * registration_for_input_device:
424 * @registrations: A collection of #GripGestureRegistration440 * @registrations: A collection of #GripGestureRegistration
@@ -433,18 +449,16 @@
433registration_for_input_device (struct Registrations *registrations,449registration_for_input_device (struct Registrations *registrations,
434 GripInputDevice *input_device)450 GripInputDevice *input_device)
435{451{
436 gboolean is_direct = grip_input_device_is_direct (input_device);452 GripDeviceType device_type = grip_get_device_type(input_device);
437 gboolean is_independent = grip_input_device_is_independent (input_device);453 if (device_type == GRIP_DEVICE_TOUCHSCREEN)
438
439 if (is_direct && !is_independent)
440 {454 {
441 return registrations->touchscreen;455 return registrations->touchscreen;
442 }456 }
443 else if (!is_direct && !is_independent)457 else if (GRIP_DEVICE_TOUCHPAD)
444 {458 {
445 return registrations->touchpad;459 return registrations->touchpad;
446 }460 }
447 else if (!is_direct && is_independent)461 else if (GRIP_DEVICE_INDEPENDENT)
448 {462 {
449 return registrations->independent;463 return registrations->independent;
450 }464 }
@@ -1010,6 +1024,7 @@
1010 return g_object_new (GRIP_TYPE_GESTURE_MANAGER, NULL);1024 return g_object_new (GRIP_TYPE_GESTURE_MANAGER, NULL);
1011}1025}
10121026
1027
1013static void1028static void
1014grip_devices_for_type (GripDeviceType type, GArray *selection,1029grip_devices_for_type (GripDeviceType type, GArray *selection,
1015 GripDevices *devices)1030 GripDevices *devices)
@@ -1020,18 +1035,17 @@
1020 {1035 {
1021 GripInputDevice *input_device = g_ptr_array_index (devices, i);1036 GripInputDevice *input_device = g_ptr_array_index (devices, i);
1022 GeisInputDeviceId id = grip_input_device_get_id (input_device);1037 GeisInputDeviceId id = grip_input_device_get_id (input_device);
1023 gboolean is_direct = grip_input_device_is_direct (input_device);1038 GripDeviceType device_type= grip_get_device_type(input_device);
1024 gboolean is_independent = grip_input_device_is_independent (input_device);
10251039
1026 if (type & GRIP_DEVICE_TOUCHSCREEN && is_direct && !is_independent)1040 if ((type & GRIP_DEVICE_TOUCHSCREEN) && device_type == GRIP_DEVICE_TOUCHSCREEN)
1027 {1041 {
1028 g_array_append_val (selection, id);1042 g_array_append_val (selection, id);
1029 }1043 }
1030 if (type & GRIP_DEVICE_TOUCHPAD && !is_direct && !is_independent)1044 if ((type & GRIP_DEVICE_TOUCHPAD) && device_type == GRIP_DEVICE_TOUCHPAD)
1031 {1045 {
1032 g_array_append_val (selection, id);1046 g_array_append_val (selection, id);
1033 }1047 }
1034 if (type & GRIP_DEVICE_INDEPENDENT && !is_direct && is_independent)1048 if ((type & GRIP_DEVICE_INDEPENDENT) && device_type == GRIP_DEVICE_INDEPENDENT)
1035 {1049 {
1036 g_array_append_val (selection, id);1050 g_array_append_val (selection, id);
1037 }1051 }

Subscribers

People subscribed via source and target branches