Skip to content

Commit

Permalink
Add GType registration for SugarEventController and SugarSwipeControl…
Browse files Browse the repository at this point in the history
…ler states
  • Loading branch information
MostlyKIGuess committed Jan 18, 2025
1 parent d0bfc80 commit 7137cee
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/sugar3/event-controller/sugar-event-controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "sugar-event-controller.h"
#include "sugar-enum-types.h"
#include <glib-object.h>

typedef struct _SugarControllerItem SugarControllerItem;
typedef struct _SugarControllerWidgetData SugarControllerWidgetData;
Expand Down Expand Up @@ -52,6 +53,24 @@ struct _SugarControllerWidgetData
SugarEventController *current_exclusive;
};

GType sugar_event_controller_state_get_type(void) {
static GType etype = 0;
static const GEnumValue values[] = {
{SUGAR_EVENT_CONTROLLER_STATE_NONE, "SUGAR_EVENT_CONTROLLER_STATE_NONE", "none"},
{SUGAR_EVENT_CONTROLLER_STATE_COLLECTING, "SUGAR_EVENT_CONTROLLER_STATE_COLLECTING", "collecting"},
{SUGAR_EVENT_CONTROLLER_STATE_RECOGNIZED, "SUGAR_EVENT_CONTROLLER_STATE_RECOGNIZED", "recognized"},
{SUGAR_EVENT_CONTROLLER_STATE_NOT_RECOGNIZED, "SUGAR_EVENT_CONTROLLER_STATE_NOT_RECOGNIZED", "not-recognized"},
{0, NULL, NULL}
};

if (etype == 0) {
etype = g_enum_register_static("SugarEventControllerState", values);
}

return etype;
}


G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (SugarEventController,
sugar_event_controller,
G_TYPE_OBJECT)
Expand Down
2 changes: 2 additions & 0 deletions src/sugar3/event-controller/sugar-event-controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ G_BEGIN_DECLS
#define SUGAR_IS_EVENT_CONTROLLER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), SUGAR_TYPE_EVENT_CONTROLLER))
#define SUGAR_IS_EVENT_CONTROLLER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), SUGAR_TYPE_EVENT_CONTROLLER))
#define SUGAR_EVENT_CONTROLLER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), SUGAR_TYPE_EVENT_CONTROLLER, SugarEventControllerClass))
#define SUGAR_TYPE_EVENT_CONTROLLER_STATE (sugar_event_controller_state_get_type())

typedef struct _SugarEventController SugarEventController;
typedef struct _SugarEventControllerClass SugarEventControllerClass;
Expand Down Expand Up @@ -82,6 +83,7 @@ struct _SugarEventControllerPrivate
};

GType sugar_event_controller_get_type (void) G_GNUC_CONST;
GType sugar_event_controller_state_get_type(void) G_GNUC_CONST;
gboolean sugar_event_controller_handle_event (SugarEventController *controller,
GdkEvent *event);
gboolean sugar_event_controller_attach (SugarEventController *controller,
Expand Down
36 changes: 36 additions & 0 deletions src/sugar3/event-controller/sugar-swipe-controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "sugar-swipe-controller.h"
#include "sugar-enum-types.h"
#include <glib-object.h>


#define CHECK_TIME 100
#define SWIPE_PX_THRESHOLD 80
Expand All @@ -46,6 +48,40 @@ struct _SugarEventData

static guint signals[LAST_SIGNAL] = { 0 };

GType sugar_swipe_direction_get_type(void) {
static GType etype = 0;
static const GEnumValue values[] = {
{SUGAR_SWIPE_DIRECTION_LEFT, "SUGAR_SWIPE_DIRECTION_LEFT", "left"},
{SUGAR_SWIPE_DIRECTION_RIGHT, "SUGAR_SWIPE_DIRECTION_RIGHT", "right"},
{SUGAR_SWIPE_DIRECTION_UP, "SUGAR_SWIPE_DIRECTION_UP", "up"},
{SUGAR_SWIPE_DIRECTION_DOWN, "SUGAR_SWIPE_DIRECTION_DOWN", "down"},
{0, NULL, NULL}
};

if (etype == 0) {
etype = g_enum_register_static("SugarSwipeDirection", values);
}

return etype;
}

GType sugar_swipe_direction_flags_get_type(void) {
static GType etype = 0;
static const GFlagsValue values[] = {
{SUGAR_SWIPE_DIRECTION_FLAG_LEFT, "SUGAR_SWIPE_DIRECTION_FLAG_LEFT", "left"},
{SUGAR_SWIPE_DIRECTION_FLAG_RIGHT, "SUGAR_SWIPE_DIRECTION_FLAG_RIGHT", "right"},
{SUGAR_SWIPE_DIRECTION_FLAG_UP, "SUGAR_SWIPE_DIRECTION_FLAG_UP", "up"},
{SUGAR_SWIPE_DIRECTION_FLAG_DOWN, "SUGAR_SWIPE_DIRECTION_FLAG_DOWN", "down"},
{0, NULL, NULL}
};

if (etype == 0) {
etype = g_flags_register_static("SugarSwipeDirectionFlags", values);
}

return etype;
}

G_DEFINE_TYPE_WITH_PRIVATE (SugarSwipeController,
sugar_swipe_controller,
SUGAR_TYPE_EVENT_CONTROLLER)
Expand Down
5 changes: 5 additions & 0 deletions src/sugar3/event-controller/sugar-swipe-controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ G_BEGIN_DECLS
#define SUGAR_IS_SWIPE_CONTROLLER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), SUGAR_TYPE_SWIPE_CONTROLLER))
#define SUGAR_IS_SWIPE_CONTROLLER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), SUGAR_TYPE_SWIPE_CONTROLLER))
#define SUGAR_SWIPE_CONTROLLER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), SUGAR_TYPE_SWIPE_CONTROLLER, SugarSwipeControllerClass))
#define SUGAR_TYPE_SWIPE_DIRECTION (sugar_swipe_direction_get_type())
#define SUGAR_TYPE_SWIPE_DIRECTION_FLAGS (sugar_swipe_direction_flags_get_type())


typedef struct _SugarSwipeController SugarSwipeController;
typedef struct _SugarSwipeControllerClass SugarSwipeControllerClass;
Expand Down Expand Up @@ -81,6 +84,8 @@ struct _SugarSwipeControllerPrivate
};

GType sugar_swipe_controller_get_type (void) G_GNUC_CONST;
GType sugar_swipe_direction_get_type(void) G_GNUC_CONST;
GType sugar_swipe_direction_flags_get_type(void) G_GNUC_CONST;
SugarEventController * sugar_swipe_controller_new (SugarSwipeDirectionFlags directions);

G_END_DECLS
Expand Down

0 comments on commit 7137cee

Please sign in to comment.