/* controller-manager.c generated by valac 0.56.19, the Vala compiler
 * generated from controller-manager.vala, do not modify */

#include "protonplus_core.h"
#include <glib.h>
#include <gtk/gtk.h>
#include <gee.h>
#include <glib-object.h>
#include <float.h>
#include <math.h>
#include <SDL3/SDL_gamepad.h>
#include <gdk/gdk.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_init.h>
#include <SDL3/SDL_error.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <SDL3/SDL_joystick.h>
#include <SDL3/SDL_stdinc.h>
#include <adwaita.h>
#include <SDL3/SDL_events.h>
#include <graphene-gobject.h>

#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_SCROLL_SPEED 12.0
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_INITIAL_REPEAT_DELAY ((guint) 350)
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_REPEAT_INTERVAL ((guint) 75)
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_WINDOW_INACTIVE_DEBOUNCE_MS ((guint) 50)
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GAMEPAD_STATE (proton_plus_utils_controller_manager_gamepad_state_get_type ())
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GAMEPAD_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GAMEPAD_STATE, ProtonPlusUtilsControllerManagerGamepadState))
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GAMEPAD_STATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GAMEPAD_STATE, ProtonPlusUtilsControllerManagerGamepadStateClass))
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_IS_GAMEPAD_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GAMEPAD_STATE))
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_IS_GAMEPAD_STATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GAMEPAD_STATE))
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GAMEPAD_STATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GAMEPAD_STATE, ProtonPlusUtilsControllerManagerGamepadStateClass))

typedef struct _ProtonPlusUtilsControllerManagerGamepadState ProtonPlusUtilsControllerManagerGamepadState;
typedef struct _ProtonPlusUtilsControllerManagerGamepadStateClass ProtonPlusUtilsControllerManagerGamepadStateClass;

#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_SURFACE (proton_plus_utils_controller_manager_gtk_surface_get_type ())
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GTK_SURFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_SURFACE, ProtonPlusUtilsControllerManagerGtkSurface))
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GTK_SURFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_SURFACE, ProtonPlusUtilsControllerManagerGtkSurfaceClass))
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_IS_GTK_SURFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_SURFACE))
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_IS_GTK_SURFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_SURFACE))
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GTK_SURFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_SURFACE, ProtonPlusUtilsControllerManagerGtkSurfaceClass))

typedef struct _ProtonPlusUtilsControllerManagerGtkSurface ProtonPlusUtilsControllerManagerGtkSurface;
typedef struct _ProtonPlusUtilsControllerManagerGtkSurfaceClass ProtonPlusUtilsControllerManagerGtkSurfaceClass;
enum  {
	PROTON_PLUS_UTILS_CONTROLLER_MANAGER_0_PROPERTY,
	PROTON_PLUS_UTILS_CONTROLLER_MANAGER_PRESENTATION_STATE_PROPERTY,
	PROTON_PLUS_UTILS_CONTROLLER_MANAGER_NUM_PROPERTIES
};
static GParamSpec* proton_plus_utils_controller_manager_properties[PROTON_PLUS_UTILS_CONTROLLER_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block74Data Block74Data;
typedef struct _Block75Data Block75Data;
typedef struct _ProtonPlusUtilsControllerManagerGtkSurfacePrivate ProtonPlusUtilsControllerManagerGtkSurfacePrivate;
typedef struct _Block76Data Block76Data;
typedef struct _Block77Data Block77Data;
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
typedef struct _ProtonPlusUtilsControllerManagerGamepadStatePrivate ProtonPlusUtilsControllerManagerGamepadStatePrivate;
#define _gtk_bitset_unref0(var) ((var == NULL) ? NULL : (var = (gtk_bitset_unref (var), NULL)))
typedef struct _Block78Data Block78Data;

#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_FOCUS_SCROLL_REQUEST (proton_plus_utils_controller_manager_gtk_focus_scroll_request_get_type ())
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GTK_FOCUS_SCROLL_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_FOCUS_SCROLL_REQUEST, ProtonPlusUtilsControllerManagerGtkFocusScrollRequest))
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GTK_FOCUS_SCROLL_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_FOCUS_SCROLL_REQUEST, ProtonPlusUtilsControllerManagerGtkFocusScrollRequestClass))
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_IS_GTK_FOCUS_SCROLL_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_FOCUS_SCROLL_REQUEST))
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_IS_GTK_FOCUS_SCROLL_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_FOCUS_SCROLL_REQUEST))
#define PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GTK_FOCUS_SCROLL_REQUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_FOCUS_SCROLL_REQUEST, ProtonPlusUtilsControllerManagerGtkFocusScrollRequestClass))

typedef struct _ProtonPlusUtilsControllerManagerGtkFocusScrollRequest ProtonPlusUtilsControllerManagerGtkFocusScrollRequest;
typedef struct _ProtonPlusUtilsControllerManagerGtkFocusScrollRequestClass ProtonPlusUtilsControllerManagerGtkFocusScrollRequestClass;
typedef struct _Block79Data Block79Data;
typedef struct _ProtonPlusUtilsControllerManagerGtkFocusScrollRequestPrivate ProtonPlusUtilsControllerManagerGtkFocusScrollRequestPrivate;
enum  {
	PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GAMEPAD_STATE_0_PROPERTY,
	PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GAMEPAD_STATE_NUM_PROPERTIES
};
static GParamSpec* proton_plus_utils_controller_manager_gamepad_state_properties[PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GAMEPAD_STATE_NUM_PROPERTIES];
enum  {
	PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GTK_SURFACE_0_PROPERTY,
	PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GTK_SURFACE_NUM_PROPERTIES
};
static GParamSpec* proton_plus_utils_controller_manager_gtk_surface_properties[PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GTK_SURFACE_NUM_PROPERTIES];
enum  {
	PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GTK_FOCUS_SCROLL_REQUEST_0_PROPERTY,
	PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GTK_FOCUS_SCROLL_REQUEST_NUM_PROPERTIES
};
static GParamSpec* proton_plus_utils_controller_manager_gtk_focus_scroll_request_properties[PROTON_PLUS_UTILS_CONTROLLER_MANAGER_GTK_FOCUS_SCROLL_REQUEST_NUM_PROPERTIES];
enum  {
	PROTON_PLUS_UTILS_CONTROLLER_MANAGER_PRESENTATION_CHANGED_SIGNAL,
	PROTON_PLUS_UTILS_CONTROLLER_MANAGER_NUM_SIGNALS
};
static guint proton_plus_utils_controller_manager_signals[PROTON_PLUS_UTILS_CONTROLLER_MANAGER_NUM_SIGNALS] = {0};

struct _ProtonPlusUtilsControllerManagerPrivate {
	ProtonPlusWidgetsWindow* window;
	guint timeout_id;
	guint repeat_timeout_id;
	gboolean sdl_initialized;
	gboolean controller_active;
	GtkWidget* highlighted;
	GtkEventControllerMotion* motion;
	GtkGestureClick* press;
	GtkEventControllerKey* keys;
	gboolean input_controllers_attached;
	gulong window_active_handler;
	gulong window_focus_handler;
	gulong confirm_button_changed_handler;
	gulong haptics_enabled_changed_handler;
	gulong highlight_visible_handler;
	gulong highlight_unmap_handler;
	gulong highlight_destroy_handler;
	guint focus_idle_id;
	guint window_inactive_timeout_id;
	GeeArrayList* gamepads;
	GeeArrayList* registered_surfaces;
	ProtonPlusUtilsControllerManagerGtkSurface* window_surface;
	ProtonPlusUtilsControllerSurfacePolicy* surface_policy;
	ProtonPlusUtilsControllerInputPolicy* input_policy;
	ProtonPlusUtilsControllerNavigationPolicy* navigation_policy;
	ProtonPlusUtilsSdlControllerHapticSink* haptic_sink;
	ProtonPlusUtilsControllerHapticFeedback* haptic_feedback;
	guint64 surface_generation;
	guint navigation_focus_source_id;
	guint scroll_focus_source_id;
	GtkRange* presentation_range;
	gulong presentation_range_orientation_handler;
	ProtonPlusUtilsControllerPresentationState* _presentation_state;
};

struct _Block74Data {
	int _ref_count_;
	ProtonPlusUtilsControllerManager* self;
	ProtonPlusWidgetsWindow* window;
};

struct _Block75Data {
	int _ref_count_;
	ProtonPlusUtilsControllerManager* self;
	AdwDialog* dialog;
};

struct _ProtonPlusUtilsControllerManagerGtkSurface {
	ProtonPlusUtilsControllerSurface parent_instance;
	ProtonPlusUtilsControllerManagerGtkSurfacePrivate * priv;
	GtkWidget* widget;
	GtkWidget* opener;
	GtkWidget* initial_focus;
	gulong state_handler;
	gulong destroy_handler;
};

struct _ProtonPlusUtilsControllerManagerGtkSurfaceClass {
	ProtonPlusUtilsControllerSurfaceClass parent_class;
};

struct _Block76Data {
	int _ref_count_;
	ProtonPlusUtilsControllerManager* self;
	ProtonPlusUtilsControllerManagerGtkSurface* surface;
	GtkPopover* popover;
};

struct _Block77Data {
	int _ref_count_;
	ProtonPlusUtilsControllerManager* self;
	ProtonPlusUtilsControllerManagerGtkSurface* surface;
};

struct _ProtonPlusUtilsControllerManagerGamepadState {
	GObject parent_instance;
	ProtonPlusUtilsControllerManagerGamepadStatePrivate * priv;
	SDL_JoystickID id;
	SDL_Gamepad* gamepad;
};

struct _ProtonPlusUtilsControllerManagerGamepadStateClass {
	GObjectClass parent_class;
};

struct _Block78Data {
	int _ref_count_;
	ProtonPlusUtilsControllerManager* self;
	ProtonPlusUtilsControllerFocusRestoreRequest* request;
	gint attempt;
	gboolean prefer_initial;
};

struct _Block79Data {
	int _ref_count_;
	ProtonPlusUtilsControllerManager* self;
	ProtonPlusUtilsControllerManagerGtkFocusScrollRequest* request;
};

struct _ProtonPlusUtilsControllerManagerGtkFocusScrollRequest {
	GObject parent_instance;
	ProtonPlusUtilsControllerManagerGtkFocusScrollRequestPrivate * priv;
	GtkWidget* widget;
	GtkWidget* page_root;
	gchar* page_id;
	guint64 surface_generation;
};

struct _ProtonPlusUtilsControllerManagerGtkFocusScrollRequestClass {
	GObjectClass parent_class;
};

static gint ProtonPlusUtilsControllerManager_private_offset;
static gpointer proton_plus_utils_controller_manager_parent_class = NULL;
static gpointer proton_plus_utils_controller_manager_gamepad_state_parent_class = NULL;
static gpointer proton_plus_utils_controller_manager_gtk_surface_parent_class = NULL;
static gpointer proton_plus_utils_controller_manager_gtk_focus_scroll_request_parent_class = NULL;

static GType proton_plus_utils_controller_manager_gamepad_state_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static GType proton_plus_utils_controller_manager_gtk_surface_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static Block74Data* block74_data_ref (Block74Data* _data74_);
static void block74_data_unref (void * _userdata_);
static void proton_plus_utils_controller_manager_set_presentation_state (ProtonPlusUtilsControllerManager* self,
                                                                  ProtonPlusUtilsControllerPresentationState* value);
static ProtonPlusUtilsControllerManagerGtkSurface* proton_plus_utils_controller_manager_gtk_surface_new (ProtonPlusUtilsControllerSurfaceKind kind,
                                                                                                  GtkWidget* widget,
                                                                                                  GtkWidget* opener,
                                                                                                  GtkWidget* initial_focus);
static ProtonPlusUtilsControllerManagerGtkSurface* proton_plus_utils_controller_manager_gtk_surface_construct (GType object_type,
                                                                                                        ProtonPlusUtilsControllerSurfaceKind kind,
                                                                                                        GtkWidget* widget,
                                                                                                        GtkWidget* opener,
                                                                                                        GtkWidget* initial_focus);
static void __lambda37_ (ProtonPlusUtilsControllerManager* self,
                  gdouble x,
                  gdouble y);
static void ___lambda37__gtk_event_controller_motion_enter (GtkEventControllerMotion* _sender,
                                                     gdouble x,
                                                     gdouble y,
                                                     gpointer self);
static void __lambda38_ (ProtonPlusUtilsControllerManager* self,
                  gdouble x,
                  gdouble y);
static void proton_plus_utils_controller_manager_yield_to_non_controller_input (ProtonPlusUtilsControllerManager* self);
static void ___lambda38__gtk_event_controller_motion_motion (GtkEventControllerMotion* _sender,
                                                      gdouble x,
                                                      gdouble y,
                                                      gpointer self);
static void __lambda367_ (ProtonPlusUtilsControllerManager* self,
                   gint n_press,
                   gdouble x,
                   gdouble y);
static void ___lambda367__gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                              gint n_press,
                                              gdouble x,
                                              gdouble y,
                                              gpointer self);
static gboolean __lambda368_ (ProtonPlusUtilsControllerManager* self,
                       guint keyval,
                       guint keycode,
                       GdkModifierType state);
static gboolean proton_plus_utils_controller_manager_is_controller_echo_key (ProtonPlusUtilsControllerManager* self,
                                                                      guint keyval);
static gboolean ___lambda368__gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                             guint keyval,
                                                             guint keycode,
                                                             GdkModifierType state,
                                                             gpointer self);
static void __lambda369_ (Block74Data* _data74_);
static void proton_plus_utils_controller_manager_cancel_window_inactive_check (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_schedule_window_inactive_check (ProtonPlusUtilsControllerManager* self);
static void ___lambda369__g_object_notify (GObject* _sender,
                                    GParamSpec* pspec,
                                    gpointer self);
static void __lambda371_ (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_sync_highlight (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_refresh_presentation (ProtonPlusUtilsControllerManager* self);
static void ___lambda371__g_object_notify (GObject* _sender,
                                    GParamSpec* pspec,
                                    gpointer self);
static void _proton_plus_utils_controller_manager_refresh_presentation_g_settings_changed (GSettings* _sender,
                                                                                    const gchar* key,
                                                                                    gpointer self);
static void ___lambda372_ (ProtonPlusUtilsControllerManager* self);
static void ____lambda372__g_settings_changed (GSettings* _sender,
                                        const gchar* key,
                                        gpointer self);
static void proton_plus_utils_controller_manager_open_gamepad (ProtonPlusUtilsControllerManager* self,
                                                        SDL_JoystickID id);
static gboolean proton_plus_utils_controller_manager_poll (ProtonPlusUtilsControllerManager* self);
static gboolean _proton_plus_utils_controller_manager_poll_gsource_func (gpointer self);
static void proton_plus_utils_controller_manager_stop_navigation_repeat (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_cancel_navigation_focus_restore (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_cancel_scroll_to_focus (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_close_gamepads (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_disconnect_surface (ProtonPlusUtilsControllerManager* self,
                                                              ProtonPlusUtilsControllerManagerGtkSurface* surface);
static void proton_plus_utils_controller_manager_deactivate_controller_mode (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_disconnect_presentation_range (ProtonPlusUtilsControllerManager* self);
static Block75Data* block75_data_ref (Block75Data* _data75_);
static void block75_data_unref (void * _userdata_);
static ProtonPlusUtilsControllerManagerGtkSurface* proton_plus_utils_controller_manager_find_registered_surface (ProtonPlusUtilsControllerManager* self,
                                                                                                          GtkWidget* widget);
static void ___lambda53_ (Block75Data* _data75_);
static void proton_plus_utils_controller_manager_unregister_dialog (ProtonPlusUtilsControllerManager* self,
                                                             AdwDialog* dialog);
static void ____lambda53__adw_dialog_closed (AdwDialog* _sender,
                                      gpointer self);
static void proton_plus_utils_controller_manager_surface_changed (ProtonPlusUtilsControllerManager* self,
                                                           ProtonPlusUtilsControllerManagerGtkSurface* surface);
static void proton_plus_utils_controller_manager_remove_surface (ProtonPlusUtilsControllerManager* self,
                                                          ProtonPlusUtilsControllerManagerGtkSurface* surface);
static Block76Data* block76_data_ref (Block76Data* _data76_);
static void block76_data_unref (void * _userdata_);
static void ___lambda43_ (Block76Data* _data76_);
static void proton_plus_utils_controller_manager_present_popover (ProtonPlusUtilsControllerManager* self,
                                                           ProtonPlusUtilsControllerManagerGtkSurface* surface);
static void ____lambda43__g_object_notify (GObject* _sender,
                                    GParamSpec* pspec,
                                    gpointer self);
static void ___lambda50_ (Block76Data* _data76_);
static void proton_plus_utils_controller_manager_unregister_popover (ProtonPlusUtilsControllerManager* self,
                                                              ProtonPlusUtilsControllerManagerGtkSurface* surface);
static void ____lambda50__gtk_widget_destroy (GtkWidget* _sender,
                                       gpointer self);
static void proton_plus_utils_controller_manager_schedule_initial_focus (ProtonPlusUtilsControllerManager* self,
                                                                  ProtonPlusUtilsControllerManagerGtkSurface* surface);
static gboolean proton_plus_utils_controller_manager_is_valid_focus_target (ProtonPlusUtilsControllerManager* self,
                                                                     GtkWidget* widget);
static void proton_plus_utils_controller_manager_cancel_repeat_timer (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_invalidate_navigation_deferred (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_clear_highlight (ProtonPlusUtilsControllerManager* self);
static gboolean proton_plus_utils_controller_manager_is_inside_surface (ProtonPlusUtilsControllerManager* self,
                                                                 GtkWidget* widget,
                                                                 ProtonPlusUtilsControllerManagerGtkSurface* surface);
static void proton_plus_utils_controller_manager_schedule_active_surface_focus (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_schedule_scroll_to_focus (ProtonPlusUtilsControllerManager* self);
static Block77Data* block77_data_ref (Block77Data* _data77_);
static void block77_data_unref (void * _userdata_);
static gboolean __lambda47_ (Block77Data* _data77_);
static ProtonPlusUtilsControllerManagerGtkSurface* proton_plus_utils_controller_manager_get_active_surface (ProtonPlusUtilsControllerManager* self);
static GtkWidget* proton_plus_utils_controller_manager_get_focused_widget (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_controller_focus_changed (ProtonPlusUtilsControllerManager* self);
static gboolean ___lambda47__gsource_func (gpointer self);
static void proton_plus_utils_controller_manager_focus_active_surface (ProtonPlusUtilsControllerManager* self);
static gboolean* _bool_dup (gboolean* self);
static gboolean _bool_equal (const gboolean * s1,
                      const gboolean * s2);
static gboolean __lambda49_ (ProtonPlusUtilsControllerManager* self);
static gboolean ___lambda49__gsource_func (gpointer self);
static gboolean proton_plus_utils_controller_manager_widget_is_descendant_of (ProtonPlusUtilsControllerManager* self,
                                                                       GtkWidget* widget,
                                                                       GtkWidget* ancestor);
static void proton_plus_utils_controller_manager_close_gamepad (ProtonPlusUtilsControllerManager* self,
                                                         SDL_JoystickID id);
static void proton_plus_utils_controller_manager_handle_button_down (ProtonPlusUtilsControllerManager* self,
                                                              SDL_JoystickID id,
                                                              SDL_GamepadButton button);
static void proton_plus_utils_controller_manager_handle_button_up (ProtonPlusUtilsControllerManager* self,
                                                            SDL_JoystickID id,
                                                            SDL_GamepadButton button);
static void proton_plus_utils_controller_manager_handle_axis (ProtonPlusUtilsControllerManager* self,
                                                       SDL_JoystickID id,
                                                       SDL_GamepadAxis axis,
                                                       gint16 raw);
static void proton_plus_utils_controller_manager_reset_input_state (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_scroll (ProtonPlusUtilsControllerManager* self,
                                                  gdouble delta);
static ProtonPlusUtilsControllerManagerGamepadState* proton_plus_utils_controller_manager_find_gamepad (ProtonPlusUtilsControllerManager* self,
                                                                                                 SDL_JoystickID id);
static ProtonPlusUtilsControllerManagerGamepadState* proton_plus_utils_controller_manager_gamepad_state_new (SDL_JoystickID id,
                                                                                                      SDL_Gamepad* gamepad);
static ProtonPlusUtilsControllerManagerGamepadState* proton_plus_utils_controller_manager_gamepad_state_construct (GType object_type,
                                                                                                            SDL_JoystickID id,
                                                                                                            SDL_Gamepad* gamepad);
static gint64 proton_plus_utils_controller_manager_controller_id (ProtonPlusUtilsControllerManager* self,
                                                           SDL_JoystickID id);
static ProtonPlusUtilsControllerManagerGamepadState* proton_plus_utils_controller_manager_find_gamepad_by_controller_id (ProtonPlusUtilsControllerManager* self,
                                                                                                                  gint64 id);
static void proton_plus_utils_controller_manager_activate_controller_mode (ProtonPlusUtilsControllerManager* self);
static gboolean __lambda370_ (ProtonPlusUtilsControllerManager* self);
static gboolean ___lambda370__gsource_func (gpointer self);
static void proton_plus_utils_controller_manager_update_highlight (ProtonPlusUtilsControllerManager* self,
                                                            GtkWidget* widget);
static gboolean proton_plus_utils_controller_manager_is_valid_highlight (ProtonPlusUtilsControllerManager* self,
                                                                  GtkWidget* widget);
static gboolean proton_plus_utils_controller_manager_uses_native_focus_highlight (ProtonPlusUtilsControllerManager* self,
                                                                           GtkWidget* widget);
static void __lambda44_ (ProtonPlusUtilsControllerManager* self);
static void ___lambda44__g_object_notify (GObject* _sender,
                                   GParamSpec* pspec,
                                   gpointer self);
static void __lambda45_ (ProtonPlusUtilsControllerManager* self);
static void ___lambda45__gtk_widget_unmap (GtkWidget* _sender,
                                    gpointer self);
static void __lambda46_ (ProtonPlusUtilsControllerManager* self);
static void ___lambda46__gtk_widget_destroy (GtkWidget* _sender,
                                      gpointer self);
static ProtonPlusUtilsControllerHintControlKind proton_plus_utils_controller_manager_classify_hint_control (ProtonPlusUtilsControllerManager* self,
                                                                                                     GtkWidget* focused,
                                                                                                     ProtonPlusUtilsControllerManagerGtkSurface* surface);
static GtkPopover* proton_plus_utils_controller_manager_find_focused_popover (ProtonPlusUtilsControllerManager* self);
static ProtonPlusUtilsControllerNavigationHost* proton_plus_utils_controller_manager_get_active_navigation_host (ProtonPlusUtilsControllerManager* self);
static GtkWidget* proton_plus_utils_controller_manager_get_direction_input_root (ProtonPlusUtilsControllerManager* self,
                                                                          GtkWidget* focused,
                                                                          ProtonPlusUtilsControllerManagerGtkSurface* surface);
static void proton_plus_utils_controller_manager_sync_presentation_range (ProtonPlusUtilsControllerManager* self,
                                                                   GtkRange* range);
static GtkWidget* proton_plus_utils_controller_manager_find_controller_activation_target (ProtonPlusUtilsControllerManager* self,
                                                                                   GtkWidget* focused,
                                                                                   GtkWidget* root);
static void _proton_plus_utils_controller_manager_refresh_presentation_g_object_notify (GObject* _sender,
                                                                                 GParamSpec* pspec,
                                                                                 gpointer self);
static ProtonPlusUtilsControllerNavigationDirection proton_plus_utils_controller_manager_direction_for_dpad (ProtonPlusUtilsControllerManager* self,
                                                                                                      SDL_GamepadButton button);
static void proton_plus_utils_controller_manager_handle_controller_direction (ProtonPlusUtilsControllerManager* self,
                                                                       gint64 device_id,
                                                                       ProtonPlusUtilsControllerNavigationDirection direction);
static void proton_plus_utils_controller_manager_restart_repeat_timer (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_handle_face_button (ProtonPlusUtilsControllerManager* self,
                                                              gint64 device_id,
                                                              SDL_GamepadButton button);
static void proton_plus_utils_controller_manager_handle_page_shortcut (ProtonPlusUtilsControllerManager* self,
                                                                gint64 device_id,
                                                                gboolean search);
static gboolean proton_plus_utils_controller_manager_has_active_modal_surface (ProtonPlusUtilsControllerManager* self);
static gboolean proton_plus_utils_controller_manager_switch_tab (ProtonPlusUtilsControllerManager* self,
                                                          gint delta);
static gboolean proton_plus_utils_controller_manager_activate_focused (ProtonPlusUtilsControllerManager* self,
                                                                ProtonPlusUtilsControllerActivationDecision* decision);
static gboolean proton_plus_utils_controller_manager_perform_navigate_back (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_save_current_page_focus (ProtonPlusUtilsControllerManager* self);
static gboolean __lambda373_ (ProtonPlusUtilsControllerManager* self);
static gboolean proton_plus_utils_controller_manager_can_repeat_navigation (ProtonPlusUtilsControllerManager* self);
static gboolean __lambda374_ (ProtonPlusUtilsControllerManager* self);
static gboolean ___lambda374__gsource_func (gpointer self);
static gboolean ___lambda373__gsource_func (gpointer self);
static GtkWidget* proton_plus_utils_controller_manager_resolve_effective_standard_control (ProtonPlusUtilsControllerManager* self,
                                                                                    GtkWidget* focused,
                                                                                    GtkWidget* root);
static ProtonPlusUtilsControllerControlKind proton_plus_utils_controller_manager_get_control_kind (ProtonPlusUtilsControllerManager* self,
                                                                                            GtkRange* range);
static ProtonPlusUtilsControllerDirectionalFocus* proton_plus_utils_controller_manager_find_directional_focus_ancestor (ProtonPlusUtilsControllerManager* self,
                                                                                                                 GtkWidget* focused,
                                                                                                                 GtkWidget* root);
static gboolean proton_plus_utils_controller_manager_adjust_range (ProtonPlusUtilsControllerManager* self,
                                                            GtkRange* range,
                                                            ProtonPlusUtilsControllerDirectionAction action);
static gboolean proton_plus_utils_controller_manager_move_focus (ProtonPlusUtilsControllerManager* self,
                                                          GtkWidget* root,
                                                          ProtonPlusUtilsControllerNavigationDirection direction);
static GtkWidget* proton_plus_utils_controller_manager_get_input_root (ProtonPlusUtilsControllerManager* self);
static void proton_plus_utils_controller_manager_focus_text_input (ProtonPlusUtilsControllerManager* self,
                                                            GtkWidget* target);
static void proton_plus_utils_controller_manager_get_active_page_context (ProtonPlusUtilsControllerManager* self,
                                                                   gchar** page_id,
                                                                   GtkWidget** page_root);
static GtkListView* proton_plus_utils_controller_manager_find_list_view_ancestor (ProtonPlusUtilsControllerManager* self,
                                                                           GtkWidget* focused,
                                                                           GtkWidget* root);
static ProtonPlusUtilsControllerActivationHandler* proton_plus_utils_controller_manager_find_controller_activation_handler (ProtonPlusUtilsControllerManager* self,
                                                                                                                     GtkWidget* focused,
                                                                                                                     GtkWidget* root);
static void proton_plus_utils_controller_manager_schedule_page_focus_restore (ProtonPlusUtilsControllerManager* self,
                                                                       gboolean prefer_initial);
static void proton_plus_utils_controller_manager_scroll_adjustment (ProtonPlusUtilsControllerManager* self,
                                                             GtkAdjustment* adjustment,
                                                             gdouble delta);
static GtkScrolledWindow* proton_plus_utils_controller_manager_find_scrolled_descendant (ProtonPlusUtilsControllerManager* self,
                                                                                  GtkWidget* root);
static gboolean proton_plus_utils_controller_manager_dismiss_active_surface (ProtonPlusUtilsControllerManager* self);
static gboolean proton_plus_utils_controller_manager_is_valid_page_focus_target (ProtonPlusUtilsControllerManager* self,
                                                                          GtkWidget* widget,
                                                                          GtkWidget* page_root);
static void proton_plus_utils_controller_manager_schedule_page_focus_restore_attempt (ProtonPlusUtilsControllerManager* self,
                                                                               ProtonPlusUtilsControllerFocusRestoreRequest* request,
                                                                               gint attempt,
                                                                               gboolean prefer_initial);
static Block78Data* block78_data_ref (Block78Data* _data78_);
static void block78_data_unref (void * _userdata_);
static gboolean __lambda375_ (Block78Data* _data78_);
static gboolean ___lambda375__gsource_func (gpointer self);
static GType proton_plus_utils_controller_manager_gtk_focus_scroll_request_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static Block79Data* block79_data_ref (Block79Data* _data79_);
static void block79_data_unref (void * _userdata_);
static ProtonPlusUtilsControllerManagerGtkFocusScrollRequest* proton_plus_utils_controller_manager_gtk_focus_scroll_request_new (GtkWidget* widget,
                                                                                                                          GtkWidget* page_root,
                                                                                                                          const gchar* page_id,
                                                                                                                          guint64 surface_generation);
static ProtonPlusUtilsControllerManagerGtkFocusScrollRequest* proton_plus_utils_controller_manager_gtk_focus_scroll_request_construct (GType object_type,
                                                                                                                                GtkWidget* widget,
                                                                                                                                GtkWidget* page_root,
                                                                                                                                const gchar* page_id,
                                                                                                                                guint64 surface_generation);
static gboolean __lambda48_ (Block79Data* _data79_);
static void proton_plus_utils_controller_manager_reveal_focused_widget (ProtonPlusUtilsControllerManager* self,
                                                                 ProtonPlusUtilsControllerManagerGtkFocusScrollRequest* request);
static gboolean ___lambda48__gsource_func (gpointer self);
static GtkScrolledWindow* proton_plus_utils_controller_manager_find_nearest_scrolled_ancestor (ProtonPlusUtilsControllerManager* self,
                                                                                        GtkWidget* widget,
                                                                                        GtkWidget* page_root);
static GtkWidget* proton_plus_utils_controller_manager_get_scrolled_content (ProtonPlusUtilsControllerManager* self,
                                                                      GtkScrolledWindow* scrolled);
static void proton_plus_utils_controller_manager_reveal_adjustment (ProtonPlusUtilsControllerManager* self,
                                                             GtkAdjustment* adjustment,
                                                             gdouble start,
                                                             gdouble end);
static void proton_plus_utils_controller_manager_gamepad_state_finalize (GObject * obj);
static GType proton_plus_utils_controller_manager_gamepad_state_get_type_once (void);
static void proton_plus_utils_controller_manager_gtk_surface_finalize (GObject * obj);
static GType proton_plus_utils_controller_manager_gtk_surface_get_type_once (void);
static void proton_plus_utils_controller_manager_gtk_focus_scroll_request_finalize (GObject * obj);
static GType proton_plus_utils_controller_manager_gtk_focus_scroll_request_get_type_once (void);
static void proton_plus_utils_controller_manager_finalize (GObject * obj);
static GType proton_plus_utils_controller_manager_get_type_once (void);
static void _vala_proton_plus_utils_controller_manager_get_property (GObject * object,
                                                              guint property_id,
                                                              GValue * value,
                                                              GParamSpec * pspec);
static void _vala_proton_plus_utils_controller_manager_set_property (GObject * object,
                                                              guint property_id,
                                                              const GValue * value,
                                                              GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
proton_plus_utils_controller_manager_get_instance_private (ProtonPlusUtilsControllerManager* self)
{
	return G_STRUCT_MEMBER_P (self, ProtonPlusUtilsControllerManager_private_offset);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static Block74Data*
block74_data_ref (Block74Data* _data74_)
{
	g_atomic_int_inc (&_data74_->_ref_count_);
	return _data74_;
}

static void
block74_data_unref (void * _userdata_)
{
	Block74Data* _data74_;
	_data74_ = (Block74Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data74_->_ref_count_)) {
		ProtonPlusUtilsControllerManager* self;
		self = _data74_->self;
		_g_object_unref0 (_data74_->window);
		_g_object_unref0 (self);
		g_slice_free (Block74Data, _data74_);
	}
}

static void
__lambda37_ (ProtonPlusUtilsControllerManager* self,
             gdouble x,
             gdouble y)
{
	ProtonPlusUtilsControllerInputPolicy* _tmp0_;
	_tmp0_ = self->priv->input_policy;
	proton_plus_utils_controller_input_policy_note_pointer_position (_tmp0_, x, y);
}

static void
___lambda37__gtk_event_controller_motion_enter (GtkEventControllerMotion* _sender,
                                                gdouble x,
                                                gdouble y,
                                                gpointer self)
{
	__lambda37_ ((ProtonPlusUtilsControllerManager*) self, x, y);
}

static void
__lambda38_ (ProtonPlusUtilsControllerManager* self,
             gdouble x,
             gdouble y)
{
	ProtonPlusUtilsControllerInputPolicy* _tmp0_;
	_tmp0_ = self->priv->input_policy;
	if (proton_plus_utils_controller_input_policy_should_accept_pointer_motion_handoff (_tmp0_, x, y, g_get_monotonic_time ())) {
		proton_plus_utils_controller_manager_yield_to_non_controller_input (self);
	}
}

static void
___lambda38__gtk_event_controller_motion_motion (GtkEventControllerMotion* _sender,
                                                 gdouble x,
                                                 gdouble y,
                                                 gpointer self)
{
	__lambda38_ ((ProtonPlusUtilsControllerManager*) self, x, y);
}

static void
__lambda367_ (ProtonPlusUtilsControllerManager* self,
              gint n_press,
              gdouble x,
              gdouble y)
{
	proton_plus_utils_controller_manager_yield_to_non_controller_input (self);
}

static void
___lambda367__gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                         gint n_press,
                                         gdouble x,
                                         gdouble y,
                                         gpointer self)
{
	__lambda367_ ((ProtonPlusUtilsControllerManager*) self, n_press, x, y);
}

static gboolean
__lambda368_ (ProtonPlusUtilsControllerManager* self,
              guint keyval,
              guint keycode,
              GdkModifierType state)
{
	ProtonPlusUtilsControllerInputPolicy* _tmp0_;
	gboolean result;
	_tmp0_ = self->priv->input_policy;
	if (!proton_plus_utils_controller_input_policy_should_accept_keyboard_handoff (_tmp0_, proton_plus_utils_controller_manager_is_controller_echo_key (self, keyval), g_get_monotonic_time ())) {
		result = TRUE;
		return result;
	}
	proton_plus_utils_controller_manager_yield_to_non_controller_input (self);
	result = FALSE;
	return result;
}

static gboolean
___lambda368__gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                    guint keyval,
                                                    guint keycode,
                                                    GdkModifierType state,
                                                    gpointer self)
{
	gboolean result;
	result = __lambda368_ ((ProtonPlusUtilsControllerManager*) self, keyval, keycode, state);
	return result;
}

static void
__lambda369_ (Block74Data* _data74_)
{
	ProtonPlusUtilsControllerManager* self;
	ProtonPlusUtilsControllerHapticFeedback* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	self = _data74_->self;
	_tmp0_ = self->priv->haptic_feedback;
	g_object_get ((GtkWindow*) _data74_->window, "is-active", &_tmp1_, NULL);
	_tmp2_ = _tmp1_;
	proton_plus_utils_controller_haptic_feedback_set_input_active (_tmp0_, _tmp2_);
	g_object_get ((GtkWindow*) _data74_->window, "is-active", &_tmp3_, NULL);
	_tmp4_ = _tmp3_;
	if (_tmp4_) {
		proton_plus_utils_controller_manager_cancel_window_inactive_check (self);
	} else {
		proton_plus_utils_controller_manager_schedule_window_inactive_check (self);
	}
}

static void
___lambda369__g_object_notify (GObject* _sender,
                               GParamSpec* pspec,
                               gpointer self)
{
	__lambda369_ (self);
}

static void
__lambda371_ (ProtonPlusUtilsControllerManager* self)
{
	proton_plus_utils_controller_manager_sync_highlight (self);
	proton_plus_utils_controller_manager_refresh_presentation (self);
}

static void
___lambda371__g_object_notify (GObject* _sender,
                               GParamSpec* pspec,
                               gpointer self)
{
	__lambda371_ ((ProtonPlusUtilsControllerManager*) self);
}

ProtonPlusUtilsControllerManager*
proton_plus_utils_controller_manager_construct (GType object_type,
                                                ProtonPlusWidgetsWindow* window)
{
	ProtonPlusUtilsControllerManager * self = NULL;
	Block74Data* _data74_;
	ProtonPlusWidgetsWindow* _tmp0_;
	ProtonPlusWidgetsWindow* _tmp1_;
	ProtonPlusUtilsSdlControllerHapticSink* _tmp2_;
	ProtonPlusUtilsControllerHapticFeedback* _tmp3_;
	ProtonPlusUtilsControllerFaceButtonLabelFacts* face_labels = NULL;
	ProtonPlusUtilsControllerFaceButtonLabelFacts* _tmp4_;
	ProtonPlusUtilsControllerHintKind* _tmp5_;
	ProtonPlusUtilsControllerHintKind* _tmp6_;
	gint _tmp6__length1;
	ProtonPlusUtilsControllerPromptButtonLabels* _tmp7_;
	ProtonPlusUtilsControllerPromptButtonLabels* _tmp8_;
	ProtonPlusUtilsControllerPresentationState* _tmp9_;
	ProtonPlusUtilsControllerPresentationState* _tmp10_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp11_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp12_;
	ProtonPlusUtilsControllerSurfacePolicy* _tmp13_;
	GtkEventControllerMotion* _tmp14_;
	GtkEventControllerMotion* _tmp15_;
	GtkEventControllerMotion* _tmp16_;
	GtkGestureClick* _tmp17_;
	GtkGestureClick* _tmp18_;
	GtkGestureClick* _tmp19_;
	GtkGestureClick* _tmp20_;
	GtkEventControllerKey* _tmp21_;
	GtkEventControllerKey* _tmp22_;
	GtkEventControllerKey* _tmp23_;
	gulong _tmp24_;
	gulong _tmp25_;
	g_return_val_if_fail (window != NULL, NULL);
	_data74_ = g_slice_new0 (Block74Data);
	_data74_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (window);
	_g_object_unref0 (_data74_->window);
	_data74_->window = _tmp0_;
	self = (ProtonPlusUtilsControllerManager*) g_object_new (object_type, NULL);
	_data74_->self = g_object_ref (self);
	_tmp1_ = _g_object_ref0 (_data74_->window);
	_g_object_unref0 (self->priv->window);
	self->priv->window = _tmp1_;
	_tmp2_ = self->priv->haptic_sink;
	_tmp3_ = proton_plus_utils_controller_haptic_feedback_new ((ProtonPlusUtilsControllerHapticSink*) _tmp2_, NULL);
	_g_object_unref0 (self->priv->haptic_feedback);
	self->priv->haptic_feedback = _tmp3_;
	_tmp4_ = proton_plus_utils_controller_physical_label_resolver_from_sdl (SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN, SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN, SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN, SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN);
	face_labels = _tmp4_;
	_tmp5_ = g_new0 (ProtonPlusUtilsControllerHintKind, 0);
	_tmp6_ = _tmp5_;
	_tmp6__length1 = 0;
	_tmp7_ = proton_plus_utils_controller_physical_label_resolver_map_prompts (face_labels, PROTON_PLUS_UTILS_CONTROLLER_CONFIRM_BUTTON_SOUTH);
	_tmp8_ = _tmp7_;
	_tmp9_ = proton_plus_utils_controller_presentation_state_new (FALSE, _tmp6_, 0, face_labels, _tmp8_);
	_tmp10_ = _tmp9_;
	proton_plus_utils_controller_manager_set_presentation_state (self, _tmp10_);
	_g_object_unref0 (_tmp10_);
	_g_object_unref0 (_tmp8_);
	_tmp6_ = (g_free (_tmp6_), NULL);
	_tmp11_ = proton_plus_utils_controller_manager_gtk_surface_new (PROTON_PLUS_UTILS_CONTROLLER_SURFACE_KIND_WINDOW, (GtkWidget*) _data74_->window, NULL, NULL);
	_g_object_unref0 (self->priv->window_surface);
	self->priv->window_surface = _tmp11_;
	_tmp12_ = self->priv->window_surface;
	_tmp13_ = proton_plus_utils_controller_surface_policy_new ((ProtonPlusUtilsControllerSurface*) _tmp12_);
	_g_object_unref0 (self->priv->surface_policy);
	self->priv->surface_policy = _tmp13_;
	_tmp14_ = (GtkEventControllerMotion*) gtk_event_controller_motion_new ();
	_g_object_unref0 (self->priv->motion);
	self->priv->motion = _tmp14_;
	_tmp15_ = self->priv->motion;
	g_signal_connect_object (_tmp15_, "enter", (GCallback) ___lambda37__gtk_event_controller_motion_enter, self, 0);
	_tmp16_ = self->priv->motion;
	g_signal_connect_object (_tmp16_, "motion", (GCallback) ___lambda38__gtk_event_controller_motion_motion, self, 0);
	_tmp17_ = (GtkGestureClick*) gtk_gesture_click_new ();
	_g_object_unref0 (self->priv->press);
	self->priv->press = _tmp17_;
	_tmp18_ = self->priv->press;
	gtk_gesture_single_set_button ((GtkGestureSingle*) _tmp18_, (guint) 0);
	_tmp19_ = self->priv->press;
	gtk_event_controller_set_propagation_phase ((GtkEventController*) _tmp19_, GTK_PHASE_CAPTURE);
	_tmp20_ = self->priv->press;
	g_signal_connect_object (_tmp20_, "pressed", (GCallback) ___lambda367__gtk_gesture_click_pressed, self, 0);
	_tmp21_ = (GtkEventControllerKey*) gtk_event_controller_key_new ();
	_g_object_unref0 (self->priv->keys);
	self->priv->keys = _tmp21_;
	_tmp22_ = self->priv->keys;
	gtk_event_controller_set_propagation_phase ((GtkEventController*) _tmp22_, GTK_PHASE_CAPTURE);
	_tmp23_ = self->priv->keys;
	g_signal_connect_object (_tmp23_, "key-pressed", (GCallback) ___lambda368__gtk_event_controller_key_key_pressed, self, 0);
	_tmp24_ = g_signal_connect_data ((GObject*) _data74_->window, "notify::is-active", (GCallback) ___lambda369__g_object_notify, block74_data_ref (_data74_), (GClosureNotify) block74_data_unref, 0);
	self->priv->window_active_handler = _tmp24_;
	_tmp25_ = g_signal_connect_object ((GObject*) _data74_->window, "notify::focus-widget", (GCallback) ___lambda371__g_object_notify, self, 0);
	self->priv->window_focus_handler = _tmp25_;
	_g_object_unref0 (face_labels);
	block74_data_unref (_data74_);
	_data74_ = NULL;
	return self;
}

ProtonPlusUtilsControllerManager*
proton_plus_utils_controller_manager_new (ProtonPlusWidgetsWindow* window)
{
	return proton_plus_utils_controller_manager_construct (PROTON_PLUS_UTILS_TYPE_CONTROLLER_MANAGER, window);
}

static void
_proton_plus_utils_controller_manager_refresh_presentation_g_settings_changed (GSettings* _sender,
                                                                               const gchar* key,
                                                                               gpointer self)
{
	proton_plus_utils_controller_manager_refresh_presentation ((ProtonPlusUtilsControllerManager*) self);
}

static void
___lambda372_ (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerHapticFeedback* _tmp0_;
	GSettings* _tmp1_;
	_tmp0_ = self->priv->haptic_feedback;
	_tmp1_ = proton_plus_globals_SETTINGS;
	proton_plus_utils_controller_haptic_feedback_set_enabled (_tmp0_, g_settings_get_boolean (_tmp1_, "controller-haptics-enabled"));
}

static void
____lambda372__g_settings_changed (GSettings* _sender,
                                   const gchar* key,
                                   gpointer self)
{
	___lambda372_ ((ProtonPlusUtilsControllerManager*) self);
}

static gboolean
_proton_plus_utils_controller_manager_poll_gsource_func (gpointer self)
{
	gboolean result;
	result = proton_plus_utils_controller_manager_poll ((ProtonPlusUtilsControllerManager*) self);
	return result;
}

void
proton_plus_utils_controller_manager_start (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerHapticFeedback* _tmp1_;
	ProtonPlusWidgetsWindow* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	GSettings* _tmp5_;
	SDL_JoystickID* ids = NULL;
	gint _tmp12_ = 0;
	SDL_JoystickID* _tmp13_;
	gint ids_length1;
	gint _ids_size_;
	SDL_JoystickID* _tmp14_;
	gint _tmp14__length1;
	ProtonPlusWidgetsWindow* _tmp18_;
	GtkEventControllerMotion* _tmp19_;
	GtkEventController* _tmp20_;
	ProtonPlusWidgetsWindow* _tmp21_;
	GtkGestureClick* _tmp22_;
	GtkEventController* _tmp23_;
	ProtonPlusWidgetsWindow* _tmp24_;
	GtkEventControllerKey* _tmp25_;
	GtkEventController* _tmp26_;
	g_return_if_fail (self != NULL);
	if (self->priv->timeout_id != ((guint) 0)) {
		return;
	}
	if (!SDL_Init (SDL_INIT_GAMEPAD)) {
		const gchar* _tmp0_;
		_tmp0_ = SDL_GetError ();
		g_warning ("controller-manager.vala:148: SDL3 gamepad init FAILED: %s", _tmp0_);
		return;
	}
	self->priv->sdl_initialized = TRUE;
	SDL_SetGamepadEventsEnabled (TRUE);
	_tmp1_ = self->priv->haptic_feedback;
	_tmp2_ = self->priv->window;
	g_object_get ((GtkWindow*) _tmp2_, "is-active", &_tmp3_, NULL);
	_tmp4_ = _tmp3_;
	proton_plus_utils_controller_haptic_feedback_set_input_active (_tmp1_, _tmp4_);
	_tmp5_ = proton_plus_globals_SETTINGS;
	if (_tmp5_ != NULL) {
		GSettings* _tmp6_;
		gulong _tmp7_;
		ProtonPlusUtilsControllerHapticFeedback* _tmp8_;
		GSettings* _tmp9_;
		GSettings* _tmp10_;
		gulong _tmp11_;
		_tmp6_ = proton_plus_globals_SETTINGS;
		_tmp7_ = g_signal_connect_object (_tmp6_, "changed::controller-confirm-button", (GCallback) _proton_plus_utils_controller_manager_refresh_presentation_g_settings_changed, self, 0);
		self->priv->confirm_button_changed_handler = _tmp7_;
		_tmp8_ = self->priv->haptic_feedback;
		_tmp9_ = proton_plus_globals_SETTINGS;
		proton_plus_utils_controller_haptic_feedback_set_enabled (_tmp8_, g_settings_get_boolean (_tmp9_, "controller-haptics-enabled"));
		_tmp10_ = proton_plus_globals_SETTINGS;
		_tmp11_ = g_signal_connect_object (_tmp10_, "changed::controller-haptics-enabled", (GCallback) ____lambda372__g_settings_changed, self, 0);
		self->priv->haptics_enabled_changed_handler = _tmp11_;
	}
	_tmp13_ = SDL_GetGamepads (&_tmp12_);
	ids = _tmp13_;
	ids_length1 = _tmp12_;
	_ids_size_ = ids_length1;
	_tmp14_ = ids;
	_tmp14__length1 = ids_length1;
	if (_tmp14_ != NULL) {
		SDL_JoystickID* _tmp15_;
		gint _tmp15__length1;
		SDL_JoystickID* _tmp16_;
		gint _tmp16__length1;
		_tmp15_ = ids;
		_tmp15__length1 = ids_length1;
		{
			SDL_JoystickID* id_collection = NULL;
			gint id_collection_length1 = 0;
			gint _id_collection_size_ = 0;
			gint id_it = 0;
			id_collection = _tmp15_;
			id_collection_length1 = _tmp15__length1;
			for (id_it = 0; id_it < id_collection_length1; id_it = id_it + 1) {
				SDL_JoystickID id = 0U;
				id = id_collection[id_it];
				{
					proton_plus_utils_controller_manager_open_gamepad (self, id);
				}
			}
		}
		_tmp16_ = ids;
		_tmp16__length1 = ids_length1;
		SDL_free ((void*) _tmp16_);
	} else {
		const gchar* _tmp17_;
		_tmp17_ = SDL_GetError ();
		g_warning ("controller-manager.vala:177: Unable to enumerate gamepads: %s", _tmp17_);
	}
	_tmp18_ = self->priv->window;
	_tmp19_ = self->priv->motion;
	_tmp20_ = _g_object_ref0 ((GtkEventController*) _tmp19_);
	gtk_widget_add_controller (G_TYPE_CHECK_INSTANCE_CAST (_tmp18_, gtk_widget_get_type (), GtkWidget), _tmp20_);
	_tmp21_ = self->priv->window;
	_tmp22_ = self->priv->press;
	_tmp23_ = _g_object_ref0 ((GtkEventController*) _tmp22_);
	gtk_widget_add_controller (G_TYPE_CHECK_INSTANCE_CAST (_tmp21_, gtk_widget_get_type (), GtkWidget), _tmp23_);
	_tmp24_ = self->priv->window;
	_tmp25_ = self->priv->keys;
	_tmp26_ = _g_object_ref0 ((GtkEventController*) _tmp25_);
	gtk_widget_add_controller (G_TYPE_CHECK_INSTANCE_CAST (_tmp24_, gtk_widget_get_type (), GtkWidget), _tmp26_);
	self->priv->input_controllers_attached = TRUE;
	self->priv->timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 16, _proton_plus_utils_controller_manager_poll_gsource_func, g_object_ref (self), g_object_unref);
}

void
proton_plus_utils_controller_manager_stop (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerHapticFeedback* _tmp0_;
	ProtonPlusUtilsControllerNavigationPolicy* _tmp7_;
	ProtonPlusUtilsControllerInputPolicy* _tmp8_;
	GeeArrayList* _tmp18_;
	ProtonPlusUtilsControllerSurfacePolicy* _tmp19_;
	gboolean _tmp20_ = FALSE;
	gboolean _tmp23_ = FALSE;
	g_return_if_fail (self != NULL);
	proton_plus_utils_controller_manager_stop_navigation_repeat (self);
	_tmp0_ = self->priv->haptic_feedback;
	proton_plus_utils_controller_haptic_feedback_stop (_tmp0_);
	if (self->priv->timeout_id != ((guint) 0)) {
		g_source_remove (self->priv->timeout_id);
		self->priv->timeout_id = (guint) 0;
	}
	if (self->priv->input_controllers_attached) {
		ProtonPlusWidgetsWindow* _tmp1_;
		GtkEventControllerMotion* _tmp2_;
		ProtonPlusWidgetsWindow* _tmp3_;
		GtkGestureClick* _tmp4_;
		ProtonPlusWidgetsWindow* _tmp5_;
		GtkEventControllerKey* _tmp6_;
		_tmp1_ = self->priv->window;
		_tmp2_ = self->priv->motion;
		gtk_widget_remove_controller (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_widget_get_type (), GtkWidget), (GtkEventController*) _tmp2_);
		_tmp3_ = self->priv->window;
		_tmp4_ = self->priv->press;
		gtk_widget_remove_controller (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, gtk_widget_get_type (), GtkWidget), (GtkEventController*) _tmp4_);
		_tmp5_ = self->priv->window;
		_tmp6_ = self->priv->keys;
		gtk_widget_remove_controller (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, gtk_widget_get_type (), GtkWidget), (GtkEventController*) _tmp6_);
	}
	self->priv->input_controllers_attached = FALSE;
	_g_object_unref0 (self->priv->motion);
	self->priv->motion = NULL;
	_g_object_unref0 (self->priv->press);
	self->priv->press = NULL;
	_g_object_unref0 (self->priv->keys);
	self->priv->keys = NULL;
	if (self->priv->focus_idle_id != ((guint) 0)) {
		g_source_remove (self->priv->focus_idle_id);
		self->priv->focus_idle_id = (guint) 0;
	}
	proton_plus_utils_controller_manager_cancel_window_inactive_check (self);
	proton_plus_utils_controller_manager_cancel_navigation_focus_restore (self);
	proton_plus_utils_controller_manager_cancel_scroll_to_focus (self);
	_tmp7_ = self->priv->navigation_policy;
	proton_plus_utils_controller_navigation_policy_invalidate_restores (_tmp7_);
	_tmp8_ = self->priv->input_policy;
	proton_plus_utils_controller_input_policy_reset (_tmp8_);
	proton_plus_utils_controller_manager_close_gamepads (self);
	{
		GeeArrayList* _surface_list = NULL;
		GeeArrayList* _tmp9_;
		gint _surface_size = 0;
		GeeArrayList* _tmp10_;
		gint _tmp11_;
		gint _tmp12_;
		gint _surface_index = 0;
		_tmp9_ = self->priv->registered_surfaces;
		_surface_list = _tmp9_;
		_tmp10_ = _surface_list;
		_tmp11_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp10_);
		_tmp12_ = _tmp11_;
		_surface_size = _tmp12_;
		_surface_index = -1;
		while (TRUE) {
			gint _tmp13_;
			gint _tmp14_;
			ProtonPlusUtilsControllerManagerGtkSurface* surface = NULL;
			GeeArrayList* _tmp15_;
			gpointer _tmp16_;
			ProtonPlusUtilsControllerManagerGtkSurface* _tmp17_;
			_surface_index = _surface_index + 1;
			_tmp13_ = _surface_index;
			_tmp14_ = _surface_size;
			if (!(_tmp13_ < _tmp14_)) {
				break;
			}
			_tmp15_ = _surface_list;
			_tmp16_ = gee_abstract_list_get ((GeeAbstractList*) _tmp15_, _surface_index);
			surface = (ProtonPlusUtilsControllerManagerGtkSurface*) _tmp16_;
			_tmp17_ = surface;
			proton_plus_utils_controller_manager_disconnect_surface (self, _tmp17_);
			_g_object_unref0 (surface);
		}
	}
	_tmp18_ = self->priv->registered_surfaces;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp18_);
	_tmp19_ = self->priv->surface_policy;
	proton_plus_utils_controller_surface_policy_reset (_tmp19_);
	proton_plus_utils_controller_manager_deactivate_controller_mode (self);
	proton_plus_utils_controller_manager_disconnect_presentation_range (self);
	if (self->priv->confirm_button_changed_handler != ((gulong) 0)) {
		GSettings* _tmp21_;
		_tmp21_ = proton_plus_globals_SETTINGS;
		_tmp20_ = _tmp21_ != NULL;
	} else {
		_tmp20_ = FALSE;
	}
	if (_tmp20_) {
		GSettings* _tmp22_;
		_tmp22_ = proton_plus_globals_SETTINGS;
		g_signal_handler_disconnect ((GObject*) _tmp22_, self->priv->confirm_button_changed_handler);
		self->priv->confirm_button_changed_handler = (gulong) 0;
	}
	if (self->priv->haptics_enabled_changed_handler != ((gulong) 0)) {
		GSettings* _tmp24_;
		_tmp24_ = proton_plus_globals_SETTINGS;
		_tmp23_ = _tmp24_ != NULL;
	} else {
		_tmp23_ = FALSE;
	}
	if (_tmp23_) {
		GSettings* _tmp25_;
		_tmp25_ = proton_plus_globals_SETTINGS;
		g_signal_handler_disconnect ((GObject*) _tmp25_, self->priv->haptics_enabled_changed_handler);
		self->priv->haptics_enabled_changed_handler = (gulong) 0;
	}
	if (self->priv->window_active_handler != ((gulong) 0)) {
		ProtonPlusWidgetsWindow* _tmp26_;
		_tmp26_ = self->priv->window;
		g_signal_handler_disconnect ((GObject*) _tmp26_, self->priv->window_active_handler);
		self->priv->window_active_handler = (gulong) 0;
	}
	if (self->priv->window_focus_handler != ((gulong) 0)) {
		ProtonPlusWidgetsWindow* _tmp27_;
		_tmp27_ = self->priv->window;
		g_signal_handler_disconnect ((GObject*) _tmp27_, self->priv->window_focus_handler);
		self->priv->window_focus_handler = (gulong) 0;
	}
	if (self->priv->sdl_initialized) {
		SDL_QuitSubSystem (SDL_INIT_GAMEPAD);
		self->priv->sdl_initialized = FALSE;
	}
}

static Block75Data*
block75_data_ref (Block75Data* _data75_)
{
	g_atomic_int_inc (&_data75_->_ref_count_);
	return _data75_;
}

static void
block75_data_unref (void * _userdata_)
{
	Block75Data* _data75_;
	_data75_ = (Block75Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data75_->_ref_count_)) {
		ProtonPlusUtilsControllerManager* self;
		self = _data75_->self;
		_g_object_unref0 (_data75_->dialog);
		_g_object_unref0 (self);
		g_slice_free (Block75Data, _data75_);
	}
}

static void
___lambda53_ (Block75Data* _data75_)
{
	ProtonPlusUtilsControllerManager* self;
	self = _data75_->self;
	proton_plus_utils_controller_manager_unregister_dialog (self, _data75_->dialog);
}

static void
____lambda53__adw_dialog_closed (AdwDialog* _sender,
                                 gpointer self)
{
	___lambda53_ (self);
}

void
proton_plus_utils_controller_manager_register_dialog (ProtonPlusUtilsControllerManager* self,
                                                      AdwDialog* dialog)
{
	Block75Data* _data75_;
	AdwDialog* _tmp0_;
	ProtonPlusUtilsControllerManagerGtkSurface* surface = NULL;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp1_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp2_;
	ProtonPlusUtilsControllerSurfacePolicy* _tmp8_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp9_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp10_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dialog != NULL);
	_data75_ = g_slice_new0 (Block75Data);
	_data75_->_ref_count_ = 1;
	_data75_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (dialog);
	_g_object_unref0 (_data75_->dialog);
	_data75_->dialog = _tmp0_;
	_tmp1_ = proton_plus_utils_controller_manager_find_registered_surface (self, (GtkWidget*) _data75_->dialog);
	surface = _tmp1_;
	_tmp2_ = surface;
	if (_tmp2_ == NULL) {
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp3_;
		GeeArrayList* _tmp4_;
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp5_;
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp6_;
		gulong _tmp7_;
		_tmp3_ = proton_plus_utils_controller_manager_gtk_surface_new (PROTON_PLUS_UTILS_CONTROLLER_SURFACE_KIND_DIALOG, (GtkWidget*) _data75_->dialog, NULL, NULL);
		_g_object_unref0 (surface);
		surface = _tmp3_;
		_tmp4_ = self->priv->registered_surfaces;
		_tmp5_ = surface;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp4_, _tmp5_);
		_tmp6_ = surface;
		_tmp7_ = g_signal_connect_data (_data75_->dialog, "closed", (GCallback) ____lambda53__adw_dialog_closed, block75_data_ref (_data75_), (GClosureNotify) block75_data_unref, 0);
		_tmp6_->state_handler = _tmp7_;
	}
	_tmp8_ = self->priv->surface_policy;
	_tmp9_ = surface;
	proton_plus_utils_controller_surface_policy_present (_tmp8_, (ProtonPlusUtilsControllerSurface*) _tmp9_);
	_tmp10_ = surface;
	proton_plus_utils_controller_manager_surface_changed (self, _tmp10_);
	_g_object_unref0 (surface);
	block75_data_unref (_data75_);
	_data75_ = NULL;
}

static void
proton_plus_utils_controller_manager_unregister_dialog (ProtonPlusUtilsControllerManager* self,
                                                        AdwDialog* dialog)
{
	ProtonPlusUtilsControllerManagerGtkSurface* surface = NULL;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp0_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp1_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp2_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp3_;
	GeeArrayList* _tmp4_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dialog != NULL);
	_tmp0_ = proton_plus_utils_controller_manager_find_registered_surface (self, (GtkWidget*) dialog);
	surface = _tmp0_;
	_tmp1_ = surface;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (surface);
		return;
	}
	_tmp2_ = surface;
	proton_plus_utils_controller_manager_remove_surface (self, _tmp2_);
	_tmp3_ = surface;
	proton_plus_utils_controller_manager_disconnect_surface (self, _tmp3_);
	_tmp4_ = self->priv->registered_surfaces;
	_tmp5_ = surface;
	gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp4_, _tmp5_);
	_g_object_unref0 (surface);
}

static Block76Data*
block76_data_ref (Block76Data* _data76_)
{
	g_atomic_int_inc (&_data76_->_ref_count_);
	return _data76_;
}

static void
block76_data_unref (void * _userdata_)
{
	Block76Data* _data76_;
	_data76_ = (Block76Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data76_->_ref_count_)) {
		ProtonPlusUtilsControllerManager* self;
		self = _data76_->self;
		_g_object_unref0 (_data76_->surface);
		_g_object_unref0 (_data76_->popover);
		_g_object_unref0 (self);
		g_slice_free (Block76Data, _data76_);
	}
}

static void
___lambda43_ (Block76Data* _data76_)
{
	ProtonPlusUtilsControllerManager* self;
	self = _data76_->self;
	if (gtk_widget_get_visible ((GtkWidget*) _data76_->popover)) {
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp0_;
		_tmp0_ = _data76_->surface;
		proton_plus_utils_controller_manager_present_popover (self, _tmp0_);
	} else {
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp1_;
		_tmp1_ = _data76_->surface;
		proton_plus_utils_controller_manager_remove_surface (self, _tmp1_);
	}
}

static void
____lambda43__g_object_notify (GObject* _sender,
                               GParamSpec* pspec,
                               gpointer self)
{
	___lambda43_ (self);
}

static void
___lambda50_ (Block76Data* _data76_)
{
	ProtonPlusUtilsControllerManager* self;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp0_;
	self = _data76_->self;
	_tmp0_ = _data76_->surface;
	proton_plus_utils_controller_manager_unregister_popover (self, _tmp0_);
}

static void
____lambda50__gtk_widget_destroy (GtkWidget* _sender,
                                  gpointer self)
{
	___lambda50_ (self);
}

void
proton_plus_utils_controller_manager_register_popover (ProtonPlusUtilsControllerManager* self,
                                                       GtkPopover* popover,
                                                       GtkWidget* opener,
                                                       GtkWidget* initial_focus)
{
	Block76Data* _data76_;
	GtkPopover* _tmp0_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp1_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (popover != NULL);
	_data76_ = g_slice_new0 (Block76Data);
	_data76_->_ref_count_ = 1;
	_data76_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (popover);
	_g_object_unref0 (_data76_->popover);
	_data76_->popover = _tmp0_;
	_tmp1_ = proton_plus_utils_controller_manager_find_registered_surface (self, (GtkWidget*) _data76_->popover);
	_data76_->surface = _tmp1_;
	_tmp2_ = _data76_->surface;
	if (_tmp2_ == NULL) {
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp3_;
		GeeArrayList* _tmp4_;
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp5_;
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp6_;
		gulong _tmp7_;
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp8_;
		gulong _tmp9_;
		_tmp3_ = proton_plus_utils_controller_manager_gtk_surface_new (PROTON_PLUS_UTILS_CONTROLLER_SURFACE_KIND_POPOVER, (GtkWidget*) _data76_->popover, opener, initial_focus);
		_g_object_unref0 (_data76_->surface);
		_data76_->surface = _tmp3_;
		_tmp4_ = self->priv->registered_surfaces;
		_tmp5_ = _data76_->surface;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp4_, _tmp5_);
		_tmp6_ = _data76_->surface;
		_tmp7_ = g_signal_connect_data ((GObject*) _data76_->popover, "notify::visible", (GCallback) ____lambda43__g_object_notify, block76_data_ref (_data76_), (GClosureNotify) block76_data_unref, 0);
		_tmp6_->state_handler = _tmp7_;
		_tmp8_ = _data76_->surface;
		_tmp9_ = g_signal_connect_data ((GtkWidget*) _data76_->popover, "destroy", (GCallback) ____lambda50__gtk_widget_destroy, block76_data_ref (_data76_), (GClosureNotify) block76_data_unref, 0);
		_tmp8_->destroy_handler = _tmp9_;
	} else {
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp10_;
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp11_;
		_tmp10_ = _data76_->surface;
		_tmp10_->opener = opener;
		_tmp11_ = _data76_->surface;
		_tmp11_->initial_focus = initial_focus;
	}
	if (gtk_widget_get_visible ((GtkWidget*) _data76_->popover)) {
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp12_;
		_tmp12_ = _data76_->surface;
		proton_plus_utils_controller_manager_present_popover (self, _tmp12_);
	}
	block76_data_unref (_data76_);
	_data76_ = NULL;
}

static void
proton_plus_utils_controller_manager_present_popover (ProtonPlusUtilsControllerManager* self,
                                                      ProtonPlusUtilsControllerManagerGtkSurface* surface)
{
	ProtonPlusUtilsControllerSurfacePolicy* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (surface != NULL);
	_tmp0_ = self->priv->surface_policy;
	proton_plus_utils_controller_surface_policy_present (_tmp0_, (ProtonPlusUtilsControllerSurface*) surface);
	proton_plus_utils_controller_manager_surface_changed (self, surface);
	proton_plus_utils_controller_manager_schedule_initial_focus (self, surface);
}

static void
proton_plus_utils_controller_manager_unregister_popover (ProtonPlusUtilsControllerManager* self,
                                                         ProtonPlusUtilsControllerManagerGtkSurface* surface)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (surface != NULL);
	proton_plus_utils_controller_manager_remove_surface (self, surface);
	proton_plus_utils_controller_manager_disconnect_surface (self, surface);
	_tmp0_ = self->priv->registered_surfaces;
	gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp0_, surface);
}

static void
proton_plus_utils_controller_manager_remove_surface (ProtonPlusUtilsControllerManager* self,
                                                     ProtonPlusUtilsControllerManagerGtkSurface* surface)
{
	GtkWidget* _tmp0_;
	ProtonPlusUtilsControllerSurfaceRemoval* removal = NULL;
	ProtonPlusUtilsControllerSurfacePolicy* _tmp1_;
	ProtonPlusUtilsControllerSurfaceRemoval* _tmp2_;
	ProtonPlusUtilsControllerSurfaceRemoval* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	ProtonPlusUtilsControllerInputPolicy* _tmp6_;
	ProtonPlusUtilsControllerHapticFeedback* _tmp7_;
	ProtonPlusUtilsControllerManagerGtkSurface* active = NULL;
	ProtonPlusUtilsControllerSurfaceRemoval* _tmp8_;
	ProtonPlusUtilsControllerSurface* _tmp9_;
	ProtonPlusUtilsControllerSurface* _tmp10_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp11_;
	gboolean _tmp12_ = FALSE;
	gboolean _tmp13_ = FALSE;
	ProtonPlusUtilsControllerSurfaceRemoval* _tmp14_;
	gboolean _tmp15_;
	gboolean _tmp16_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (surface != NULL);
	_tmp0_ = surface->opener;
	proton_plus_utils_controller_surface_set_opener_valid ((ProtonPlusUtilsControllerSurface*) surface, proton_plus_utils_controller_manager_is_valid_focus_target (self, _tmp0_));
	_tmp1_ = self->priv->surface_policy;
	_tmp2_ = proton_plus_utils_controller_surface_policy_remove (_tmp1_, (ProtonPlusUtilsControllerSurface*) surface);
	removal = _tmp2_;
	_tmp3_ = removal;
	_tmp4_ = proton_plus_utils_controller_surface_removal_get_was_active (_tmp3_);
	_tmp5_ = _tmp4_;
	if (!_tmp5_) {
		_g_object_unref0 (removal);
		return;
	}
	_tmp6_ = self->priv->input_policy;
	proton_plus_utils_controller_input_policy_surface_changed (_tmp6_);
	_tmp7_ = self->priv->haptic_feedback;
	proton_plus_utils_controller_haptic_feedback_context_changed (_tmp7_);
	proton_plus_utils_controller_manager_cancel_repeat_timer (self);
	proton_plus_utils_controller_manager_invalidate_navigation_deferred (self);
	proton_plus_utils_controller_manager_clear_highlight (self);
	_tmp8_ = removal;
	_tmp9_ = proton_plus_utils_controller_surface_removal_get_active_surface (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_SURFACE, ProtonPlusUtilsControllerManagerGtkSurface));
	active = _tmp11_;
	_tmp14_ = removal;
	_tmp15_ = proton_plus_utils_controller_surface_removal_get_restore_opener (_tmp14_);
	_tmp16_ = _tmp15_;
	if (_tmp16_) {
		GtkWidget* _tmp17_;
		_tmp17_ = surface->opener;
		_tmp13_ = _tmp17_ != NULL;
	} else {
		_tmp13_ = FALSE;
	}
	if (_tmp13_) {
		GtkWidget* _tmp18_;
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp19_;
		_tmp18_ = surface->opener;
		_tmp19_ = active;
		_tmp12_ = proton_plus_utils_controller_manager_is_inside_surface (self, _tmp18_, _tmp19_);
	} else {
		_tmp12_ = FALSE;
	}
	if (_tmp12_) {
		GtkWidget* _tmp20_;
		_tmp20_ = surface->opener;
		gtk_widget_grab_focus (G_TYPE_CHECK_INSTANCE_CAST (_tmp20_, gtk_widget_get_type (), GtkWidget));
	} else {
		proton_plus_utils_controller_manager_schedule_active_surface_focus (self);
	}
	proton_plus_utils_controller_manager_schedule_scroll_to_focus (self);
	proton_plus_utils_controller_manager_sync_highlight (self);
	proton_plus_utils_controller_manager_refresh_presentation (self);
	_g_object_unref0 (active);
	_g_object_unref0 (removal);
}

static void
proton_plus_utils_controller_manager_disconnect_surface (ProtonPlusUtilsControllerManager* self,
                                                         ProtonPlusUtilsControllerManagerGtkSurface* surface)
{
	GtkWidget* widget = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GtkWidget* _tmp3_;
	gboolean _tmp5_ = FALSE;
	GtkWidget* _tmp6_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (surface != NULL);
	_tmp0_ = surface->widget;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	widget = _tmp1_;
	_tmp3_ = widget;
	if (_tmp3_ != NULL) {
		_tmp2_ = surface->state_handler != ((gulong) 0);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		GtkWidget* _tmp4_;
		_tmp4_ = widget;
		g_signal_handler_disconnect ((GObject*) _tmp4_, surface->state_handler);
	}
	_tmp6_ = widget;
	if (_tmp6_ != NULL) {
		_tmp5_ = surface->destroy_handler != ((gulong) 0);
	} else {
		_tmp5_ = FALSE;
	}
	if (_tmp5_) {
		GtkWidget* _tmp7_;
		_tmp7_ = widget;
		g_signal_handler_disconnect ((GObject*) _tmp7_, surface->destroy_handler);
	}
	surface->state_handler = (gulong) 0;
	surface->destroy_handler = (gulong) 0;
	surface->widget = NULL;
	surface->opener = NULL;
	surface->initial_focus = NULL;
	_g_object_unref0 (widget);
}

static ProtonPlusUtilsControllerManagerGtkSurface*
proton_plus_utils_controller_manager_find_registered_surface (ProtonPlusUtilsControllerManager* self,
                                                              GtkWidget* widget)
{
	ProtonPlusUtilsControllerManagerGtkSurface* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (widget != NULL, NULL);
	{
		GeeArrayList* _surface_list = NULL;
		GeeArrayList* _tmp0_;
		gint _surface_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _surface_index = 0;
		_tmp0_ = self->priv->registered_surfaces;
		_surface_list = _tmp0_;
		_tmp1_ = _surface_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_surface_size = _tmp3_;
		_surface_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			ProtonPlusUtilsControllerManagerGtkSurface* surface = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			ProtonPlusUtilsControllerManagerGtkSurface* _tmp8_;
			GtkWidget* _tmp9_;
			_surface_index = _surface_index + 1;
			_tmp4_ = _surface_index;
			_tmp5_ = _surface_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _surface_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _surface_index);
			surface = (ProtonPlusUtilsControllerManagerGtkSurface*) _tmp7_;
			_tmp8_ = surface;
			_tmp9_ = _tmp8_->widget;
			if (_tmp9_ == widget) {
				result = surface;
				return result;
			}
			_g_object_unref0 (surface);
		}
	}
	result = NULL;
	return result;
}

static void
proton_plus_utils_controller_manager_surface_changed (ProtonPlusUtilsControllerManager* self,
                                                      ProtonPlusUtilsControllerManagerGtkSurface* surface)
{
	ProtonPlusUtilsControllerInputPolicy* _tmp0_;
	ProtonPlusUtilsControllerHapticFeedback* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (surface != NULL);
	_tmp0_ = self->priv->input_policy;
	proton_plus_utils_controller_input_policy_surface_changed (_tmp0_);
	_tmp1_ = self->priv->haptic_feedback;
	proton_plus_utils_controller_haptic_feedback_context_changed (_tmp1_);
	proton_plus_utils_controller_manager_cancel_repeat_timer (self);
	proton_plus_utils_controller_manager_invalidate_navigation_deferred (self);
	proton_plus_utils_controller_manager_clear_highlight (self);
	if (self->priv->controller_active) {
		proton_plus_utils_controller_manager_sync_highlight (self);
	}
	proton_plus_utils_controller_manager_refresh_presentation (self);
}

static Block77Data*
block77_data_ref (Block77Data* _data77_)
{
	g_atomic_int_inc (&_data77_->_ref_count_);
	return _data77_;
}

static void
block77_data_unref (void * _userdata_)
{
	Block77Data* _data77_;
	_data77_ = (Block77Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data77_->_ref_count_)) {
		ProtonPlusUtilsControllerManager* self;
		self = _data77_->self;
		_g_object_unref0 (_data77_->surface);
		_g_object_unref0 (self);
		g_slice_free (Block77Data, _data77_);
	}
}

static gboolean
__lambda47_ (Block77Data* _data77_)
{
	ProtonPlusUtilsControllerManager* self;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp3_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp4_;
	gboolean _tmp5_;
	GtkWidget* focused = NULL;
	GtkWidget* _tmp9_;
	GtkWidget* _tmp10_;
	gboolean result;
	self = _data77_->self;
	self->priv->focus_idle_id = (guint) 0;
	_tmp3_ = proton_plus_utils_controller_manager_get_active_surface (self);
	_tmp4_ = _tmp3_;
	_tmp5_ = _data77_->surface != _tmp4_;
	_g_object_unref0 (_tmp4_);
	if (_tmp5_) {
		_tmp2_ = TRUE;
	} else {
		GtkWidget* _tmp6_;
		_tmp6_ = _data77_->surface->widget;
		_tmp2_ = _tmp6_ == NULL;
	}
	if (_tmp2_) {
		_tmp1_ = TRUE;
	} else {
		GtkWidget* _tmp7_;
		_tmp7_ = _data77_->surface->widget;
		_tmp1_ = !gtk_widget_get_visible (_tmp7_);
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		GtkWidget* _tmp8_;
		_tmp8_ = _data77_->surface->widget;
		_tmp0_ = !gtk_widget_get_mapped (_tmp8_);
	}
	if (_tmp0_) {
		result = G_SOURCE_REMOVE;
		return result;
	}
	_tmp9_ = proton_plus_utils_controller_manager_get_focused_widget (self);
	focused = _tmp9_;
	_tmp10_ = focused;
	if (!proton_plus_utils_controller_manager_is_valid_focus_target (self, _tmp10_)) {
		GtkWidget* initial = NULL;
		GtkWidget* _tmp11_;
		GtkWidget* _tmp12_;
		gboolean _tmp13_ = FALSE;
		GtkWidget* _tmp14_;
		_tmp11_ = _data77_->surface->initial_focus;
		_tmp12_ = _g_object_ref0 (_tmp11_);
		initial = _tmp12_;
		_tmp14_ = initial;
		if (proton_plus_utils_controller_manager_is_valid_focus_target (self, _tmp14_)) {
			GtkWidget* _tmp15_;
			_tmp15_ = initial;
			_tmp13_ = proton_plus_utils_controller_manager_is_inside_surface (self, _tmp15_, _data77_->surface);
		} else {
			_tmp13_ = FALSE;
		}
		if (_tmp13_) {
			GtkWidget* _tmp16_;
			_tmp16_ = initial;
			gtk_widget_grab_focus (G_TYPE_CHECK_INSTANCE_CAST (_tmp16_, gtk_widget_get_type (), GtkWidget));
		} else {
			GtkWidget* _tmp17_;
			_tmp17_ = _data77_->surface->widget;
			gtk_widget_child_focus (_tmp17_, GTK_DIR_TAB_FORWARD);
		}
		_g_object_unref0 (initial);
	}
	proton_plus_utils_controller_manager_controller_focus_changed (self);
	proton_plus_utils_controller_manager_sync_highlight (self);
	proton_plus_utils_controller_manager_refresh_presentation (self);
	result = G_SOURCE_REMOVE;
	_g_object_unref0 (focused);
	return result;
}

static gboolean
___lambda47__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda47_ (self);
	return result;
}

static void
proton_plus_utils_controller_manager_schedule_initial_focus (ProtonPlusUtilsControllerManager* self,
                                                             ProtonPlusUtilsControllerManagerGtkSurface* surface)
{
	Block77Data* _data77_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (surface != NULL);
	_data77_ = g_slice_new0 (Block77Data);
	_data77_->_ref_count_ = 1;
	_data77_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (surface);
	_g_object_unref0 (_data77_->surface);
	_data77_->surface = _tmp0_;
	if (self->priv->focus_idle_id != ((guint) 0)) {
		g_source_remove (self->priv->focus_idle_id);
	}
	self->priv->focus_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda47__gsource_func, block77_data_ref (_data77_), block77_data_unref);
	block77_data_unref (_data77_);
	_data77_ = NULL;
}

static gboolean*
_bool_dup (gboolean* self)
{
	gboolean* dup;
	dup = g_new0 (gboolean, 1);
	memcpy (dup, self, sizeof (gboolean));
	return dup;
}

static gpointer
__bool_dup0 (gpointer self)
{
	return self ? _bool_dup (self) : NULL;
}

static gboolean
_bool_equal (const gboolean * s1,
             const gboolean * s2)
{
	if (s1 == s2) {
		return TRUE;
	}
	if (s1 == NULL) {
		return FALSE;
	}
	if (s2 == NULL) {
		return FALSE;
	}
	return (*s1) == (*s2);
}

static void
proton_plus_utils_controller_manager_focus_active_surface (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerManagerGtkSurface* surface = NULL;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp0_;
	GtkWidget* focused = NULL;
	GtkWidget* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GtkWidget* _tmp3_;
	GtkWidget* _tmp5_ = NULL;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp6_;
	GtkWidget* _tmp7_;
	gboolean* _tmp8_ = NULL;
	gboolean _tmp11_;
	g_return_if_fail (self != NULL);
	_tmp0_ = proton_plus_utils_controller_manager_get_active_surface (self);
	surface = _tmp0_;
	_tmp1_ = proton_plus_utils_controller_manager_get_focused_widget (self);
	focused = _tmp1_;
	_tmp3_ = focused;
	if (_tmp3_ != NULL) {
		GtkWidget* _tmp4_;
		_tmp4_ = focused;
		_tmp2_ = proton_plus_utils_controller_manager_is_valid_focus_target (self, _tmp4_);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		_g_object_unref0 (focused);
		_g_object_unref0 (surface);
		return;
	}
	_tmp6_ = surface;
	_tmp7_ = _tmp6_->widget;
	_tmp5_ = _tmp7_;
	_tmp8_ = NULL;
	if (_tmp5_ != NULL) {
		gboolean _tmp9_;
		gboolean* _tmp10_;
		_tmp9_ = gtk_widget_child_focus (_tmp5_, GTK_DIR_TAB_FORWARD);
		_tmp10_ = __bool_dup0 (&_tmp9_);
		_g_free0 (_tmp8_);
		_tmp8_ = _tmp10_;
	}
	_tmp11_ = TRUE;
	if (_bool_equal (_tmp8_, &_tmp11_) == TRUE) {
		proton_plus_utils_controller_manager_controller_focus_changed (self);
	}
	_g_free0 (_tmp8_);
	_g_object_unref0 (focused);
	_g_object_unref0 (surface);
}

static gboolean
__lambda49_ (ProtonPlusUtilsControllerManager* self)
{
	gboolean result;
	self->priv->focus_idle_id = (guint) 0;
	proton_plus_utils_controller_manager_focus_active_surface (self);
	proton_plus_utils_controller_manager_sync_highlight (self);
	proton_plus_utils_controller_manager_refresh_presentation (self);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda49__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda49_ ((ProtonPlusUtilsControllerManager*) self);
	return result;
}

static void
proton_plus_utils_controller_manager_schedule_active_surface_focus (ProtonPlusUtilsControllerManager* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->focus_idle_id != ((guint) 0)) {
		g_source_remove (self->priv->focus_idle_id);
	}
	self->priv->focus_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda49__gsource_func, g_object_ref (self), g_object_unref);
}

static gboolean
proton_plus_utils_controller_manager_is_valid_focus_target (ProtonPlusUtilsControllerManager* self,
                                                            GtkWidget* widget)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (widget != NULL) {
		GtkRoot* _tmp5_;
		_tmp5_ = gtk_widget_get_root (widget);
		_tmp4_ = _tmp5_ != NULL;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		_tmp3_ = gtk_widget_get_mapped (widget);
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		_tmp2_ = gtk_widget_is_visible (widget);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		_tmp1_ = gtk_widget_is_sensitive (widget);
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		_tmp0_ = gtk_widget_get_focusable (widget);
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static gboolean
proton_plus_utils_controller_manager_is_inside_surface (ProtonPlusUtilsControllerManager* self,
                                                        GtkWidget* widget,
                                                        ProtonPlusUtilsControllerManagerGtkSurface* surface)
{
	gboolean _tmp0_ = FALSE;
	ProtonPlusUtilsControllerSurfaceKind _tmp2_;
	ProtonPlusUtilsControllerSurfaceKind _tmp3_;
	GtkWidget* _tmp19_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (surface != NULL, FALSE);
	if (widget == NULL) {
		_tmp0_ = TRUE;
	} else {
		GtkWidget* _tmp1_;
		_tmp1_ = surface->widget;
		_tmp0_ = _tmp1_ == NULL;
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	_tmp2_ = proton_plus_utils_controller_surface_get_kind ((ProtonPlusUtilsControllerSurface*) surface);
	_tmp3_ = _tmp2_;
	if (_tmp3_ == PROTON_PLUS_UTILS_CONTROLLER_SURFACE_KIND_WINDOW) {
		GtkRoot* _tmp4_;
		ProtonPlusWidgetsWindow* _tmp5_;
		_tmp4_ = gtk_widget_get_root (widget);
		_tmp5_ = self->priv->window;
		if (_tmp4_ != G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, gtk_root_get_type (), GtkRoot)) {
			result = FALSE;
			return result;
		}
		{
			GeeArrayList* _registered_list = NULL;
			GeeArrayList* _tmp6_;
			gint _registered_size = 0;
			GeeArrayList* _tmp7_;
			gint _tmp8_;
			gint _tmp9_;
			gint _registered_index = 0;
			_tmp6_ = self->priv->registered_surfaces;
			_registered_list = _tmp6_;
			_tmp7_ = _registered_list;
			_tmp8_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp7_);
			_tmp9_ = _tmp8_;
			_registered_size = _tmp9_;
			_registered_index = -1;
			while (TRUE) {
				gint _tmp10_;
				gint _tmp11_;
				ProtonPlusUtilsControllerManagerGtkSurface* registered = NULL;
				GeeArrayList* _tmp12_;
				gpointer _tmp13_;
				gboolean _tmp14_ = FALSE;
				ProtonPlusUtilsControllerManagerGtkSurface* _tmp15_;
				ProtonPlusUtilsControllerManagerGtkSurface* _tmp16_;
				_registered_index = _registered_index + 1;
				_tmp10_ = _registered_index;
				_tmp11_ = _registered_size;
				if (!(_tmp10_ < _tmp11_)) {
					break;
				}
				_tmp12_ = _registered_list;
				_tmp13_ = gee_abstract_list_get ((GeeAbstractList*) _tmp12_, _registered_index);
				registered = (ProtonPlusUtilsControllerManagerGtkSurface*) _tmp13_;
				_tmp15_ = registered;
				_tmp16_ = self->priv->window_surface;
				if (_tmp15_ != _tmp16_) {
					ProtonPlusUtilsControllerManagerGtkSurface* _tmp17_;
					GtkWidget* _tmp18_;
					_tmp17_ = registered;
					_tmp18_ = _tmp17_->widget;
					_tmp14_ = proton_plus_utils_controller_manager_widget_is_descendant_of (self, widget, _tmp18_);
				} else {
					_tmp14_ = FALSE;
				}
				if (_tmp14_) {
					result = FALSE;
					_g_object_unref0 (registered);
					return result;
				}
				_g_object_unref0 (registered);
			}
		}
		result = TRUE;
		return result;
	}
	_tmp19_ = surface->widget;
	result = proton_plus_utils_controller_manager_widget_is_descendant_of (self, widget, _tmp19_);
	return result;
}

static gboolean
proton_plus_utils_controller_manager_widget_is_descendant_of (ProtonPlusUtilsControllerManager* self,
                                                              GtkWidget* widget,
                                                              GtkWidget* ancestor)
{
	GtkWidget* current = NULL;
	GtkWidget* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (widget != NULL, FALSE);
	if (ancestor == NULL) {
		result = FALSE;
		return result;
	}
	_tmp0_ = _g_object_ref0 (widget);
	current = _tmp0_;
	while (TRUE) {
		GtkWidget* _tmp1_;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp3_;
		GtkWidget* _tmp4_;
		GtkWidget* _tmp5_;
		_tmp1_ = current;
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = current;
		if (_tmp2_ == ancestor) {
			result = TRUE;
			_g_object_unref0 (current);
			return result;
		}
		_tmp3_ = current;
		_tmp4_ = gtk_widget_get_parent (_tmp3_);
		_tmp5_ = _g_object_ref0 (_tmp4_);
		_g_object_unref0 (current);
		current = _tmp5_;
	}
	result = FALSE;
	_g_object_unref0 (current);
	return result;
}

static gboolean
proton_plus_utils_controller_manager_poll (ProtonPlusUtilsControllerManager* self)
{
	SDL_Event event = {0};
	ProtonPlusWidgetsWindow* _tmp17_;
	gboolean _tmp18_;
	gboolean _tmp19_;
	ProtonPlusUtilsControllerInputPolicy* _tmp20_;
	gdouble _tmp21_;
	gdouble _tmp22_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	while (TRUE) {
		SDL_Event _tmp0_ = {0};
		gboolean _tmp1_;
		_tmp1_ = SDL_PollEvent (&_tmp0_);
		event = _tmp0_;
		if (!_tmp1_) {
			break;
		}
		switch (event.type) {
			case SDL_EVENT_GAMEPAD_ADDED:
			{
				SDL_GamepadDeviceEvent _tmp2_;
				_tmp2_ = event.gdevice;
				proton_plus_utils_controller_manager_open_gamepad (self, _tmp2_.which);
				break;
			}
			case SDL_EVENT_GAMEPAD_REMOVED:
			{
				SDL_GamepadDeviceEvent _tmp3_;
				_tmp3_ = event.gdevice;
				proton_plus_utils_controller_manager_close_gamepad (self, _tmp3_.which);
				break;
			}
			case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
			{
				ProtonPlusWidgetsWindow* _tmp4_;
				gboolean _tmp5_;
				gboolean _tmp6_;
				_tmp4_ = self->priv->window;
				g_object_get ((GtkWindow*) _tmp4_, "is-active", &_tmp5_, NULL);
				_tmp6_ = _tmp5_;
				if (_tmp6_) {
					SDL_GamepadButtonEvent _tmp7_;
					SDL_GamepadButtonEvent _tmp8_;
					_tmp7_ = event.gbutton;
					_tmp8_ = event.gbutton;
					proton_plus_utils_controller_manager_handle_button_down (self, _tmp7_.which, _tmp8_.button);
				}
				break;
			}
			case SDL_EVENT_GAMEPAD_BUTTON_UP:
			{
				SDL_GamepadButtonEvent _tmp9_;
				SDL_GamepadButtonEvent _tmp10_;
				_tmp9_ = event.gbutton;
				_tmp10_ = event.gbutton;
				proton_plus_utils_controller_manager_handle_button_up (self, _tmp9_.which, _tmp10_.button);
				break;
			}
			case SDL_EVENT_GAMEPAD_AXIS_MOTION:
			{
				ProtonPlusWidgetsWindow* _tmp11_;
				gboolean _tmp12_;
				gboolean _tmp13_;
				_tmp11_ = self->priv->window;
				g_object_get ((GtkWindow*) _tmp11_, "is-active", &_tmp12_, NULL);
				_tmp13_ = _tmp12_;
				if (_tmp13_) {
					SDL_GamepadAxisEvent _tmp14_;
					SDL_GamepadAxisEvent _tmp15_;
					SDL_GamepadAxisEvent _tmp16_;
					_tmp14_ = event.gaxis;
					_tmp15_ = event.gaxis;
					_tmp16_ = event.gaxis;
					proton_plus_utils_controller_manager_handle_axis (self, _tmp14_.which, _tmp15_.axis, _tmp16_.value);
				}
				break;
			}
			default:
			{
				break;
			}
		}
	}
	_tmp17_ = self->priv->window;
	g_object_get ((GtkWindow*) _tmp17_, "is-active", &_tmp18_, NULL);
	_tmp19_ = _tmp18_;
	if (!_tmp19_) {
		proton_plus_utils_controller_manager_reset_input_state (self);
		result = G_SOURCE_CONTINUE;
		return result;
	}
	_tmp20_ = self->priv->input_policy;
	_tmp21_ = proton_plus_utils_controller_input_policy_get_scroll_intent (_tmp20_);
	_tmp22_ = _tmp21_;
	if (_tmp22_ != ((gdouble) 0)) {
		ProtonPlusUtilsControllerInputPolicy* _tmp23_;
		gdouble _tmp24_;
		gdouble _tmp25_;
		_tmp23_ = self->priv->input_policy;
		_tmp24_ = proton_plus_utils_controller_input_policy_get_scroll_intent (_tmp23_);
		_tmp25_ = _tmp24_;
		proton_plus_utils_controller_manager_scroll (self, _tmp25_ * PROTON_PLUS_UTILS_CONTROLLER_MANAGER_SCROLL_SPEED);
	}
	result = G_SOURCE_CONTINUE;
	return result;
}

static void
proton_plus_utils_controller_manager_open_gamepad (ProtonPlusUtilsControllerManager* self,
                                                   SDL_JoystickID id)
{
	ProtonPlusUtilsControllerManagerGamepadState* _tmp0_;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp1_;
	gboolean _tmp2_;
	SDL_Gamepad* gamepad = NULL;
	SDL_Gamepad* _tmp3_;
	SDL_Gamepad* _tmp4_;
	GeeArrayList* _tmp6_;
	SDL_Gamepad* _tmp7_;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp8_;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp9_;
	ProtonPlusUtilsSdlControllerHapticSink* _tmp10_;
	SDL_Gamepad* _tmp11_;
	g_return_if_fail (self != NULL);
	_tmp0_ = proton_plus_utils_controller_manager_find_gamepad (self, id);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_ != NULL;
	_g_object_unref0 (_tmp1_);
	if (_tmp2_) {
		return;
	}
	_tmp3_ = SDL_OpenGamepad (id);
	gamepad = _tmp3_;
	_tmp4_ = gamepad;
	if (_tmp4_ == NULL) {
		const gchar* _tmp5_;
		_tmp5_ = SDL_GetError ();
		g_warning ("controller-manager.vala:481: Unable to open gamepad: %s", _tmp5_);
		return;
	}
	_tmp6_ = self->priv->gamepads;
	_tmp7_ = gamepad;
	_tmp8_ = proton_plus_utils_controller_manager_gamepad_state_new (id, _tmp7_);
	_tmp9_ = _tmp8_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp6_, _tmp9_);
	_g_object_unref0 (_tmp9_);
	_tmp10_ = self->priv->haptic_sink;
	_tmp11_ = gamepad;
	proton_plus_utils_sdl_controller_haptic_sink_register_device (_tmp10_, proton_plus_utils_controller_manager_controller_id (self, id), _tmp11_);
}

static void
proton_plus_utils_controller_manager_close_gamepad (ProtonPlusUtilsControllerManager* self,
                                                    SDL_JoystickID id)
{
	ProtonPlusUtilsControllerManagerGamepadState* state = NULL;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp0_;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp1_;
	ProtonPlusUtilsControllerHapticFeedback* _tmp2_;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp3_;
	ProtonPlusUtilsControllerInputPolicy* _tmp4_;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp5_;
	ProtonPlusUtilsSdlControllerHapticSink* _tmp6_;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp7_;
	GeeArrayList* _tmp8_;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp9_;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp10_;
	SDL_Gamepad* _tmp11_;
	g_return_if_fail (self != NULL);
	_tmp0_ = proton_plus_utils_controller_manager_find_gamepad (self, id);
	state = _tmp0_;
	_tmp1_ = state;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (state);
		return;
	}
	_tmp2_ = self->priv->haptic_feedback;
	_tmp3_ = state;
	proton_plus_utils_controller_haptic_feedback_disconnect_device (_tmp2_, proton_plus_utils_controller_manager_controller_id (self, _tmp3_->id));
	_tmp4_ = self->priv->input_policy;
	_tmp5_ = state;
	if (proton_plus_utils_controller_input_policy_disconnect_device (_tmp4_, proton_plus_utils_controller_manager_controller_id (self, _tmp5_->id))) {
		proton_plus_utils_controller_manager_cancel_repeat_timer (self);
		proton_plus_utils_controller_manager_deactivate_controller_mode (self);
	}
	_tmp6_ = self->priv->haptic_sink;
	_tmp7_ = state;
	proton_plus_utils_sdl_controller_haptic_sink_unregister_device (_tmp6_, proton_plus_utils_controller_manager_controller_id (self, _tmp7_->id));
	_tmp8_ = self->priv->gamepads;
	_tmp9_ = state;
	gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp8_, _tmp9_);
	_tmp10_ = state;
	_tmp11_ = _tmp10_->gamepad;
	SDL_CloseGamepad (_tmp11_);
	_g_object_unref0 (state);
}

static void
proton_plus_utils_controller_manager_close_gamepads (ProtonPlusUtilsControllerManager* self)
{
	GeeArrayList* _tmp12_;
	g_return_if_fail (self != NULL);
	{
		GeeArrayList* _state_list = NULL;
		GeeArrayList* _tmp0_;
		gint _state_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _state_index = 0;
		_tmp0_ = self->priv->gamepads;
		_state_list = _tmp0_;
		_tmp1_ = _state_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_state_size = _tmp3_;
		_state_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			ProtonPlusUtilsControllerManagerGamepadState* state = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			ProtonPlusUtilsSdlControllerHapticSink* _tmp8_;
			ProtonPlusUtilsControllerManagerGamepadState* _tmp9_;
			ProtonPlusUtilsControllerManagerGamepadState* _tmp10_;
			SDL_Gamepad* _tmp11_;
			_state_index = _state_index + 1;
			_tmp4_ = _state_index;
			_tmp5_ = _state_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _state_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _state_index);
			state = (ProtonPlusUtilsControllerManagerGamepadState*) _tmp7_;
			_tmp8_ = self->priv->haptic_sink;
			_tmp9_ = state;
			proton_plus_utils_sdl_controller_haptic_sink_unregister_device (_tmp8_, proton_plus_utils_controller_manager_controller_id (self, _tmp9_->id));
			_tmp10_ = state;
			_tmp11_ = _tmp10_->gamepad;
			SDL_CloseGamepad (_tmp11_);
			_g_object_unref0 (state);
		}
	}
	_tmp12_ = self->priv->gamepads;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp12_);
}

static ProtonPlusUtilsControllerManagerGamepadState*
proton_plus_utils_controller_manager_find_gamepad (ProtonPlusUtilsControllerManager* self,
                                                   SDL_JoystickID id)
{
	ProtonPlusUtilsControllerManagerGamepadState* result;
	g_return_val_if_fail (self != NULL, NULL);
	{
		GeeArrayList* _state_list = NULL;
		GeeArrayList* _tmp0_;
		gint _state_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _state_index = 0;
		_tmp0_ = self->priv->gamepads;
		_state_list = _tmp0_;
		_tmp1_ = _state_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_state_size = _tmp3_;
		_state_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			ProtonPlusUtilsControllerManagerGamepadState* state = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			ProtonPlusUtilsControllerManagerGamepadState* _tmp8_;
			_state_index = _state_index + 1;
			_tmp4_ = _state_index;
			_tmp5_ = _state_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _state_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _state_index);
			state = (ProtonPlusUtilsControllerManagerGamepadState*) _tmp7_;
			_tmp8_ = state;
			if (_tmp8_->id == id) {
				result = state;
				return result;
			}
			_g_object_unref0 (state);
		}
	}
	result = NULL;
	return result;
}

static ProtonPlusUtilsControllerManagerGamepadState*
proton_plus_utils_controller_manager_find_gamepad_by_controller_id (ProtonPlusUtilsControllerManager* self,
                                                                    gint64 id)
{
	ProtonPlusUtilsControllerManagerGamepadState* result;
	g_return_val_if_fail (self != NULL, NULL);
	{
		GeeArrayList* _state_list = NULL;
		GeeArrayList* _tmp0_;
		gint _state_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _state_index = 0;
		_tmp0_ = self->priv->gamepads;
		_state_list = _tmp0_;
		_tmp1_ = _state_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_state_size = _tmp3_;
		_state_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			ProtonPlusUtilsControllerManagerGamepadState* state = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			ProtonPlusUtilsControllerManagerGamepadState* _tmp8_;
			_state_index = _state_index + 1;
			_tmp4_ = _state_index;
			_tmp5_ = _state_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _state_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _state_index);
			state = (ProtonPlusUtilsControllerManagerGamepadState*) _tmp7_;
			_tmp8_ = state;
			if (proton_plus_utils_controller_manager_controller_id (self, _tmp8_->id) == id) {
				result = state;
				return result;
			}
			_g_object_unref0 (state);
		}
	}
	result = NULL;
	return result;
}

static gint64
proton_plus_utils_controller_manager_controller_id (ProtonPlusUtilsControllerManager* self,
                                                    SDL_JoystickID id)
{
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	result = (gint64) id;
	return result;
}

static void
proton_plus_utils_controller_manager_activate_controller_mode (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerInputPolicy* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->input_policy;
	proton_plus_utils_controller_input_policy_note_controller_activity (_tmp0_, g_get_monotonic_time ());
	if (!self->priv->controller_active) {
		ProtonPlusWidgetsWindow* _tmp1_;
		self->priv->controller_active = TRUE;
		_tmp1_ = self->priv->window;
		gtk_widget_add_css_class ((GtkWidget*) _tmp1_, "controller-active");
	}
	proton_plus_utils_controller_manager_sync_highlight (self);
	proton_plus_utils_controller_manager_refresh_presentation (self);
}

static void
proton_plus_utils_controller_manager_deactivate_controller_mode (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusWidgetsWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	if (!self->priv->controller_active) {
		proton_plus_utils_controller_manager_refresh_presentation (self);
		return;
	}
	self->priv->controller_active = FALSE;
	_tmp0_ = self->priv->window;
	gtk_widget_remove_css_class ((GtkWidget*) _tmp0_, "controller-active");
	proton_plus_utils_controller_manager_clear_highlight (self);
	proton_plus_utils_controller_manager_refresh_presentation (self);
}

static gboolean
__lambda370_ (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusWidgetsWindow* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	self->priv->window_inactive_timeout_id = (guint) 0;
	_tmp0_ = self->priv->window;
	g_object_get ((GtkWindow*) _tmp0_, "is-active", &_tmp1_, NULL);
	_tmp2_ = _tmp1_;
	if (!_tmp2_) {
		proton_plus_utils_controller_manager_reset_input_state (self);
		proton_plus_utils_controller_manager_deactivate_controller_mode (self);
	}
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda370__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda370_ ((ProtonPlusUtilsControllerManager*) self);
	return result;
}

static void
proton_plus_utils_controller_manager_schedule_window_inactive_check (ProtonPlusUtilsControllerManager* self)
{
	g_return_if_fail (self != NULL);
	proton_plus_utils_controller_manager_cancel_window_inactive_check (self);
	self->priv->window_inactive_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, PROTON_PLUS_UTILS_CONTROLLER_MANAGER_WINDOW_INACTIVE_DEBOUNCE_MS, ___lambda370__gsource_func, g_object_ref (self), g_object_unref);
}

static void
proton_plus_utils_controller_manager_cancel_window_inactive_check (ProtonPlusUtilsControllerManager* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->window_inactive_timeout_id == ((guint) 0)) {
		return;
	}
	g_source_remove (self->priv->window_inactive_timeout_id);
	self->priv->window_inactive_timeout_id = (guint) 0;
}

static void
proton_plus_utils_controller_manager_yield_to_non_controller_input (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerInputPolicy* _tmp0_;
	ProtonPlusUtilsControllerHapticFeedback* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->input_policy;
	proton_plus_utils_controller_input_policy_surface_changed (_tmp0_);
	_tmp1_ = self->priv->haptic_feedback;
	proton_plus_utils_controller_haptic_feedback_context_changed (_tmp1_);
	proton_plus_utils_controller_manager_cancel_repeat_timer (self);
	proton_plus_utils_controller_manager_deactivate_controller_mode (self);
}

static gboolean
proton_plus_utils_controller_manager_is_controller_echo_key (ProtonPlusUtilsControllerManager* self,
                                                             guint keyval)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	switch (keyval) {
		case GDK_KEY_Up:
		case GDK_KEY_Down:
		case GDK_KEY_Left:
		case GDK_KEY_Right:
		case GDK_KEY_KP_Up:
		case GDK_KEY_KP_Down:
		case GDK_KEY_KP_Left:
		case GDK_KEY_KP_Right:
		case GDK_KEY_Return:
		case GDK_KEY_KP_Enter:
		case GDK_KEY_space:
		case GDK_KEY_Escape:
		{
			result = TRUE;
			return result;
		}
		default:
		{
			result = FALSE;
			return result;
		}
	}
}

static void
__lambda44_ (ProtonPlusUtilsControllerManager* self)
{
	proton_plus_utils_controller_manager_sync_highlight (self);
}

static void
___lambda44__g_object_notify (GObject* _sender,
                              GParamSpec* pspec,
                              gpointer self)
{
	__lambda44_ ((ProtonPlusUtilsControllerManager*) self);
}

static void
__lambda45_ (ProtonPlusUtilsControllerManager* self)
{
	proton_plus_utils_controller_manager_clear_highlight (self);
}

static void
___lambda45__gtk_widget_unmap (GtkWidget* _sender,
                               gpointer self)
{
	__lambda45_ ((ProtonPlusUtilsControllerManager*) self);
}

static void
__lambda46_ (ProtonPlusUtilsControllerManager* self)
{
	proton_plus_utils_controller_manager_clear_highlight (self);
}

static void
___lambda46__gtk_widget_destroy (GtkWidget* _sender,
                                 gpointer self)
{
	__lambda46_ ((ProtonPlusUtilsControllerManager*) self);
}

static void
proton_plus_utils_controller_manager_update_highlight (ProtonPlusUtilsControllerManager* self,
                                                       GtkWidget* widget)
{
	gboolean _tmp0_ = FALSE;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp3_;
	GtkWidget* _tmp5_;
	gulong _tmp6_;
	GtkWidget* _tmp7_;
	gulong _tmp8_;
	GtkWidget* _tmp9_;
	gulong _tmp10_;
	g_return_if_fail (self != NULL);
	if (!self->priv->controller_active) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = !proton_plus_utils_controller_manager_is_valid_highlight (self, widget);
	}
	if (_tmp0_) {
		widget = NULL;
	}
	_tmp1_ = self->priv->highlighted;
	if (_tmp1_ == widget) {
		return;
	}
	proton_plus_utils_controller_manager_clear_highlight (self);
	self->priv->highlighted = widget;
	_tmp2_ = self->priv->highlighted;
	if (_tmp2_ == NULL) {
		return;
	}
	_tmp3_ = self->priv->highlighted;
	if (!proton_plus_utils_controller_manager_uses_native_focus_highlight (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, gtk_widget_get_type (), GtkWidget))) {
		GtkWidget* _tmp4_;
		_tmp4_ = self->priv->highlighted;
		gtk_widget_add_css_class (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_widget_get_type (), GtkWidget), "controller-focus");
	}
	_tmp5_ = self->priv->highlighted;
	_tmp6_ = g_signal_connect_object ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, gtk_widget_get_type (), GtkWidget), "notify::visible", (GCallback) ___lambda44__g_object_notify, self, 0);
	self->priv->highlight_visible_handler = _tmp6_;
	_tmp7_ = self->priv->highlighted;
	_tmp8_ = g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, gtk_widget_get_type (), GtkWidget), "unmap", (GCallback) ___lambda45__gtk_widget_unmap, self, 0);
	self->priv->highlight_unmap_handler = _tmp8_;
	_tmp9_ = self->priv->highlighted;
	_tmp10_ = g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, gtk_widget_get_type (), GtkWidget), "destroy", (GCallback) ___lambda46__gtk_widget_destroy, self, 0);
	self->priv->highlight_destroy_handler = _tmp10_;
}

static void
proton_plus_utils_controller_manager_clear_highlight (ProtonPlusUtilsControllerManager* self)
{
	GtkWidget* widget = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->highlighted;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	widget = _tmp1_;
	_tmp2_ = widget;
	if (_tmp2_ != NULL) {
		GtkWidget* _tmp6_;
		if (self->priv->highlight_visible_handler != ((gulong) 0)) {
			GtkWidget* _tmp3_;
			_tmp3_ = widget;
			g_signal_handler_disconnect ((GObject*) _tmp3_, self->priv->highlight_visible_handler);
		}
		if (self->priv->highlight_unmap_handler != ((gulong) 0)) {
			GtkWidget* _tmp4_;
			_tmp4_ = widget;
			g_signal_handler_disconnect ((GObject*) _tmp4_, self->priv->highlight_unmap_handler);
		}
		if (self->priv->highlight_destroy_handler != ((gulong) 0)) {
			GtkWidget* _tmp5_;
			_tmp5_ = widget;
			g_signal_handler_disconnect ((GObject*) _tmp5_, self->priv->highlight_destroy_handler);
		}
		_tmp6_ = widget;
		gtk_widget_remove_css_class (_tmp6_, "controller-focus");
	}
	self->priv->highlight_visible_handler = (gulong) 0;
	self->priv->highlight_unmap_handler = (gulong) 0;
	self->priv->highlight_destroy_handler = (gulong) 0;
	self->priv->highlighted = NULL;
	_g_object_unref0 (widget);
}

static gboolean
proton_plus_utils_controller_manager_uses_native_focus_highlight (ProtonPlusUtilsControllerManager* self,
                                                                  GtkWidget* widget)
{
	GtkWidget* current = NULL;
	GtkWidget* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (widget != NULL, FALSE);
	_tmp0_ = _g_object_ref0 (widget);
	current = _tmp0_;
	while (TRUE) {
		GtkWidget* _tmp1_;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp3_;
		GtkWidget* _tmp4_;
		GtkWidget* _tmp5_;
		_tmp1_ = current;
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = current;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, gtk_search_entry_get_type ())) {
			result = TRUE;
			_g_object_unref0 (current);
			return result;
		}
		_tmp3_ = current;
		_tmp4_ = gtk_widget_get_parent (_tmp3_);
		_tmp5_ = _g_object_ref0 (_tmp4_);
		_g_object_unref0 (current);
		current = _tmp5_;
	}
	result = FALSE;
	_g_object_unref0 (current);
	return result;
}

static void
proton_plus_utils_controller_manager_sync_highlight (ProtonPlusUtilsControllerManager* self)
{
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = proton_plus_utils_controller_manager_get_focused_widget (self);
	_tmp1_ = _tmp0_;
	proton_plus_utils_controller_manager_update_highlight (self, _tmp1_);
	_g_object_unref0 (_tmp1_);
}

static gboolean
proton_plus_utils_controller_manager_is_valid_highlight (ProtonPlusUtilsControllerManager* self,
                                                         GtkWidget* widget)
{
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp0_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (!proton_plus_utils_controller_manager_is_valid_focus_target (self, widget)) {
		result = FALSE;
		return result;
	}
	_tmp0_ = proton_plus_utils_controller_manager_get_active_surface (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = proton_plus_utils_controller_manager_is_inside_surface (self, widget, _tmp1_);
	_g_object_unref0 (_tmp1_);
	result = _tmp2_;
	return result;
}

void
proton_plus_utils_controller_manager_presentation_context_changed (ProtonPlusUtilsControllerManager* self)
{
	g_return_if_fail (self != NULL);
	proton_plus_utils_controller_manager_refresh_presentation (self);
}

static void
proton_plus_utils_controller_manager_refresh_presentation (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerManagerGamepadState* _tmp0_ = NULL;
	ProtonPlusUtilsControllerInputPolicy* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	ProtonPlusUtilsControllerManagerGamepadState* active_gamepad = NULL;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp8_;
	gboolean _tmp9_ = FALSE;
	ProtonPlusWidgetsWindow* _tmp10_;
	gboolean _tmp11_;
	gboolean _tmp12_;
	gboolean presentation_window_active = FALSE;
	gboolean _tmp13_ = FALSE;
	gboolean _tmp14_ = FALSE;
	gboolean presentation_active = FALSE;
	ProtonPlusUtilsControllerManagerGtkSurface* surface = NULL;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp16_;
	GtkWidget* focused = NULL;
	GtkWidget* _tmp17_;
	ProtonPlusUtilsControllerHintControlKind control_kind = 0;
	GtkWidget* _tmp18_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp19_;
	gboolean _tmp20_ = FALSE;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp21_;
	ProtonPlusUtilsControllerSurfaceKind _tmp22_;
	ProtonPlusUtilsControllerSurfaceKind _tmp23_;
	gboolean has_popover = FALSE;
	gboolean has_dialog = FALSE;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp26_;
	ProtonPlusUtilsControllerSurfaceKind _tmp27_;
	ProtonPlusUtilsControllerSurfaceKind _tmp28_;
	ProtonPlusUtilsControllerNavigationHost* host = NULL;
	ProtonPlusUtilsControllerNavigationHost* _tmp29_;
	ProtonPlusUtilsControllerPageShortcuts* shortcuts = NULL;
	ProtonPlusUtilsControllerNavigationHost* _tmp30_;
	ProtonPlusUtilsControllerPageShortcuts* _tmp31_;
	gboolean _tmp32_ = FALSE;
	ProtonPlusUtilsControllerNavigationHost* _tmp33_;
	gboolean _tmp35_ = FALSE;
	ProtonPlusUtilsControllerNavigationHost* _tmp36_;
	gboolean _tmp38_ = FALSE;
	ProtonPlusUtilsControllerNavigationHost* _tmp39_;
	gboolean _tmp41_ = FALSE;
	ProtonPlusUtilsControllerPageShortcuts* _tmp42_;
	gboolean _tmp44_ = FALSE;
	ProtonPlusUtilsControllerPageShortcuts* _tmp45_;
	ProtonPlusUtilsControllerHintContext* context = NULL;
	ProtonPlusUtilsControllerHintContext* _tmp47_ = NULL;
	SDL_GamepadButtonLabel south_label = 0;
	SDL_GamepadButtonLabel east_label = 0;
	SDL_GamepadButtonLabel west_label = 0;
	SDL_GamepadButtonLabel north_label = 0;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp48_;
	ProtonPlusUtilsControllerFaceButtonLabelFacts* face_labels = NULL;
	ProtonPlusUtilsControllerFaceButtonLabelFacts* _tmp57_;
	ProtonPlusUtilsControllerConfirmButton confirm_button = 0;
	GSettings* _tmp58_;
	ProtonPlusUtilsControllerPresentationState* next = NULL;
	ProtonPlusUtilsControllerHintContext* _tmp60_;
	gint _tmp61_ = 0;
	ProtonPlusUtilsControllerHintKind* _tmp62_;
	ProtonPlusUtilsControllerHintKind* _tmp63_;
	gint _tmp63__length1;
	ProtonPlusUtilsControllerFaceButtonLabelFacts* _tmp64_;
	ProtonPlusUtilsControllerFaceButtonLabelFacts* _tmp65_;
	ProtonPlusUtilsControllerPromptButtonLabels* _tmp66_;
	ProtonPlusUtilsControllerPromptButtonLabels* _tmp67_;
	ProtonPlusUtilsControllerPresentationState* _tmp68_;
	ProtonPlusUtilsControllerPresentationState* _tmp69_;
	ProtonPlusUtilsControllerPresentationState* _tmp70_;
	ProtonPlusUtilsControllerPresentationState* _tmp71_;
	ProtonPlusUtilsControllerPresentationState* _tmp72_;
	ProtonPlusUtilsControllerPresentationState* _tmp73_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->input_policy;
	_tmp2_ = proton_plus_utils_controller_input_policy_get_has_active_device (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		ProtonPlusUtilsControllerInputPolicy* _tmp4_;
		gint64 _tmp5_;
		gint64 _tmp6_;
		ProtonPlusUtilsControllerManagerGamepadState* _tmp7_;
		_tmp4_ = self->priv->input_policy;
		_tmp5_ = proton_plus_utils_controller_input_policy_get_active_device_id (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = proton_plus_utils_controller_manager_find_gamepad_by_controller_id (self, _tmp6_);
		_g_object_unref0 (_tmp0_);
		_tmp0_ = _tmp7_;
	} else {
		_g_object_unref0 (_tmp0_);
		_tmp0_ = NULL;
	}
	_tmp8_ = _tmp0_;
	_tmp0_ = NULL;
	active_gamepad = _tmp8_;
	_tmp10_ = self->priv->window;
	g_object_get ((GtkWindow*) _tmp10_, "is-active", &_tmp11_, NULL);
	_tmp12_ = _tmp11_;
	if (_tmp12_) {
		_tmp9_ = TRUE;
	} else {
		_tmp9_ = self->priv->window_inactive_timeout_id != ((guint) 0);
	}
	presentation_window_active = _tmp9_;
	if (self->priv->controller_active) {
		_tmp14_ = presentation_window_active;
	} else {
		_tmp14_ = FALSE;
	}
	if (_tmp14_) {
		ProtonPlusUtilsControllerManagerGamepadState* _tmp15_;
		_tmp15_ = active_gamepad;
		_tmp13_ = _tmp15_ != NULL;
	} else {
		_tmp13_ = FALSE;
	}
	presentation_active = _tmp13_;
	_tmp16_ = proton_plus_utils_controller_manager_get_active_surface (self);
	surface = _tmp16_;
	_tmp17_ = proton_plus_utils_controller_manager_get_focused_widget (self);
	focused = _tmp17_;
	_tmp18_ = focused;
	_tmp19_ = surface;
	control_kind = proton_plus_utils_controller_manager_classify_hint_control (self, _tmp18_, _tmp19_);
	_tmp21_ = surface;
	_tmp22_ = proton_plus_utils_controller_surface_get_kind ((ProtonPlusUtilsControllerSurface*) _tmp21_);
	_tmp23_ = _tmp22_;
	if (_tmp23_ == PROTON_PLUS_UTILS_CONTROLLER_SURFACE_KIND_POPOVER) {
		_tmp20_ = TRUE;
	} else {
		GtkPopover* _tmp24_;
		GtkPopover* _tmp25_;
		_tmp24_ = proton_plus_utils_controller_manager_find_focused_popover (self);
		_tmp25_ = _tmp24_;
		_tmp20_ = _tmp25_ != NULL;
		_g_object_unref0 (_tmp25_);
	}
	has_popover = _tmp20_;
	_tmp26_ = surface;
	_tmp27_ = proton_plus_utils_controller_surface_get_kind ((ProtonPlusUtilsControllerSurface*) _tmp26_);
	_tmp28_ = _tmp27_;
	has_dialog = _tmp28_ == PROTON_PLUS_UTILS_CONTROLLER_SURFACE_KIND_DIALOG;
	_tmp29_ = proton_plus_utils_controller_manager_get_active_navigation_host (self);
	host = _tmp29_;
	_tmp30_ = host;
	_tmp31_ = _g_object_ref0 (PROTON_PLUS_UTILS_IS_CONTROLLER_PAGE_SHORTCUTS (_tmp30_) ? ((ProtonPlusUtilsControllerPageShortcuts*) _tmp30_) : NULL);
	shortcuts = _tmp31_;
	_tmp33_ = host;
	if (_tmp33_ != NULL) {
		ProtonPlusUtilsControllerNavigationHost* _tmp34_;
		_tmp34_ = host;
		_tmp32_ = proton_plus_utils_controller_navigation_host_controller_can_navigate_back (_tmp34_);
	} else {
		_tmp32_ = FALSE;
	}
	_tmp36_ = host;
	if (_tmp36_ != NULL) {
		ProtonPlusUtilsControllerNavigationHost* _tmp37_;
		_tmp37_ = host;
		_tmp35_ = !proton_plus_utils_controller_navigation_host_controller_can_navigate_back (_tmp37_);
	} else {
		_tmp35_ = FALSE;
	}
	_tmp39_ = host;
	if (_tmp39_ != NULL) {
		ProtonPlusUtilsControllerNavigationHost* _tmp40_;
		_tmp40_ = host;
		_tmp38_ = proton_plus_utils_controller_navigation_host_controller_can_switch_page (_tmp40_);
	} else {
		_tmp38_ = FALSE;
	}
	_tmp42_ = shortcuts;
	if (_tmp42_ != NULL) {
		ProtonPlusUtilsControllerPageShortcuts* _tmp43_;
		_tmp43_ = shortcuts;
		_tmp41_ = proton_plus_utils_controller_page_shortcuts_controller_can_open_search (_tmp43_);
	} else {
		_tmp41_ = FALSE;
	}
	_tmp45_ = shortcuts;
	if (_tmp45_ != NULL) {
		ProtonPlusUtilsControllerPageShortcuts* _tmp46_;
		_tmp46_ = shortcuts;
		_tmp44_ = proton_plus_utils_controller_page_shortcuts_controller_can_open_filter (_tmp46_);
	} else {
		_tmp44_ = FALSE;
	}
	_tmp47_ = proton_plus_utils_controller_hint_context_new ();
	proton_plus_utils_controller_hint_context_set_controller_mode_active (_tmp47_, presentation_active);
	proton_plus_utils_controller_hint_context_set_has_dialog (_tmp47_, has_dialog);
	proton_plus_utils_controller_hint_context_set_has_popover (_tmp47_, has_popover);
	proton_plus_utils_controller_hint_context_set_control_kind (_tmp47_, control_kind);
	proton_plus_utils_controller_hint_context_set_can_navigate_back (_tmp47_, _tmp32_);
	proton_plus_utils_controller_hint_context_set_can_exit (_tmp47_, _tmp35_);
	proton_plus_utils_controller_hint_context_set_can_switch_section (_tmp47_, _tmp38_);
	proton_plus_utils_controller_hint_context_set_can_open_search (_tmp47_, _tmp41_);
	proton_plus_utils_controller_hint_context_set_can_open_filter (_tmp47_, _tmp44_);
	context = _tmp47_;
	south_label = SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN;
	east_label = SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN;
	west_label = SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN;
	north_label = SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN;
	_tmp48_ = active_gamepad;
	if (_tmp48_ != NULL) {
		ProtonPlusUtilsControllerManagerGamepadState* _tmp49_;
		SDL_Gamepad* _tmp50_;
		ProtonPlusUtilsControllerManagerGamepadState* _tmp51_;
		SDL_Gamepad* _tmp52_;
		ProtonPlusUtilsControllerManagerGamepadState* _tmp53_;
		SDL_Gamepad* _tmp54_;
		ProtonPlusUtilsControllerManagerGamepadState* _tmp55_;
		SDL_Gamepad* _tmp56_;
		_tmp49_ = active_gamepad;
		_tmp50_ = _tmp49_->gamepad;
		south_label = SDL_GetGamepadButtonLabel (_tmp50_, SDL_GAMEPAD_BUTTON_SOUTH);
		_tmp51_ = active_gamepad;
		_tmp52_ = _tmp51_->gamepad;
		east_label = SDL_GetGamepadButtonLabel (_tmp52_, SDL_GAMEPAD_BUTTON_EAST);
		_tmp53_ = active_gamepad;
		_tmp54_ = _tmp53_->gamepad;
		west_label = SDL_GetGamepadButtonLabel (_tmp54_, SDL_GAMEPAD_BUTTON_WEST);
		_tmp55_ = active_gamepad;
		_tmp56_ = _tmp55_->gamepad;
		north_label = SDL_GetGamepadButtonLabel (_tmp56_, SDL_GAMEPAD_BUTTON_NORTH);
	}
	_tmp57_ = proton_plus_utils_controller_physical_label_resolver_from_sdl (south_label, east_label, west_label, north_label);
	face_labels = _tmp57_;
	confirm_button = PROTON_PLUS_UTILS_CONTROLLER_CONFIRM_BUTTON_SOUTH;
	_tmp58_ = proton_plus_globals_SETTINGS;
	if (_tmp58_ != NULL) {
		GSettings* _tmp59_;
		_tmp59_ = proton_plus_globals_SETTINGS;
		confirm_button = (ProtonPlusUtilsControllerConfirmButton) g_settings_get_enum (_tmp59_, "controller-confirm-button");
	}
	_tmp60_ = context;
	_tmp62_ = proton_plus_utils_controller_hint_policy_get_hints (_tmp60_, &_tmp61_);
	_tmp63_ = _tmp62_;
	_tmp63__length1 = _tmp61_;
	_tmp64_ = face_labels;
	_tmp65_ = face_labels;
	_tmp66_ = proton_plus_utils_controller_physical_label_resolver_map_prompts (_tmp65_, confirm_button);
	_tmp67_ = _tmp66_;
	_tmp68_ = proton_plus_utils_controller_presentation_state_new (presentation_active, _tmp63_, _tmp61_, _tmp64_, _tmp67_);
	_tmp69_ = _tmp68_;
	_g_object_unref0 (_tmp67_);
	_tmp63_ = (g_free (_tmp63_), NULL);
	next = _tmp69_;
	_tmp70_ = self->priv->_presentation_state;
	_tmp71_ = next;
	if (proton_plus_utils_controller_presentation_state_equal_to (_tmp70_, _tmp71_)) {
		_g_object_unref0 (next);
		_g_object_unref0 (face_labels);
		_g_object_unref0 (context);
		_g_object_unref0 (shortcuts);
		_g_object_unref0 (host);
		_g_object_unref0 (focused);
		_g_object_unref0 (surface);
		_g_object_unref0 (active_gamepad);
		_g_object_unref0 (_tmp0_);
		return;
	}
	_tmp72_ = next;
	proton_plus_utils_controller_manager_set_presentation_state (self, _tmp72_);
	_tmp73_ = self->priv->_presentation_state;
	g_signal_emit (self, proton_plus_utils_controller_manager_signals[PROTON_PLUS_UTILS_CONTROLLER_MANAGER_PRESENTATION_CHANGED_SIGNAL], 0, _tmp73_);
	_g_object_unref0 (next);
	_g_object_unref0 (face_labels);
	_g_object_unref0 (context);
	_g_object_unref0 (shortcuts);
	_g_object_unref0 (host);
	_g_object_unref0 (focused);
	_g_object_unref0 (surface);
	_g_object_unref0 (active_gamepad);
	_g_object_unref0 (_tmp0_);
}

static ProtonPlusUtilsControllerHintControlKind
proton_plus_utils_controller_manager_classify_hint_control (ProtonPlusUtilsControllerManager* self,
                                                            GtkWidget* focused,
                                                            ProtonPlusUtilsControllerManagerGtkSurface* surface)
{
	GtkWidget* root = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* current = NULL;
	GtkWidget* _tmp1_;
	GtkRange* range = NULL;
	GtkRange* _tmp11_;
	GtkRange* _tmp12_;
	GtkWidget* _tmp15_ = NULL;
	GtkWidget* redirected_target = NULL;
	GtkWidget* _tmp18_;
	gboolean _tmp19_ = FALSE;
	gboolean _tmp20_ = FALSE;
	gboolean _tmp21_ = FALSE;
	GtkWidget* _tmp22_;
	GtkWidget* _tmp26_;
	GtkWidget* _tmp47_;
	GtkWidget* _tmp48_;
	GtkWidget* _tmp49_;
	gboolean _tmp50_;
	ProtonPlusUtilsControllerHintControlKind result;
	g_return_val_if_fail (self != NULL, 0);
	g_return_val_if_fail (surface != NULL, 0);
	_tmp0_ = proton_plus_utils_controller_manager_get_direction_input_root (self, focused, surface);
	root = _tmp0_;
	_tmp1_ = _g_object_ref0 (focused);
	current = _tmp1_;
	range = NULL;
	while (TRUE) {
		GtkWidget* _tmp2_;
		GtkWidget* _tmp3_;
		GtkWidget* _tmp6_;
		GtkWidget* _tmp7_;
		GtkWidget* _tmp8_;
		GtkWidget* _tmp9_;
		GtkWidget* _tmp10_;
		_tmp2_ = current;
		if (!(_tmp2_ != NULL)) {
			break;
		}
		_tmp3_ = current;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, gtk_range_get_type ())) {
			GtkWidget* _tmp4_;
			GtkRange* _tmp5_;
			_tmp4_ = current;
			_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_range_get_type (), GtkRange));
			_g_object_unref0 (range);
			range = _tmp5_;
			break;
		}
		_tmp6_ = current;
		_tmp7_ = root;
		if (_tmp6_ == _tmp7_) {
			break;
		}
		_tmp8_ = current;
		_tmp9_ = gtk_widget_get_parent (_tmp8_);
		_tmp10_ = _g_object_ref0 (_tmp9_);
		_g_object_unref0 (current);
		current = _tmp10_;
	}
	_tmp11_ = range;
	proton_plus_utils_controller_manager_sync_presentation_range (self, _tmp11_);
	_tmp12_ = range;
	if (_tmp12_ != NULL) {
		ProtonPlusUtilsControllerHintControlKind _tmp13_ = 0;
		GtkRange* _tmp14_;
		_tmp14_ = range;
		if (gtk_orientable_get_orientation (G_TYPE_CHECK_INSTANCE_CAST (_tmp14_, gtk_orientable_get_type (), GtkOrientable)) == GTK_ORIENTATION_HORIZONTAL) {
			_tmp13_ = PROTON_PLUS_UTILS_CONTROLLER_HINT_CONTROL_KIND_HORIZONTAL_RANGE;
		} else {
			_tmp13_ = PROTON_PLUS_UTILS_CONTROLLER_HINT_CONTROL_KIND_VERTICAL_RANGE;
		}
		result = _tmp13_;
		_g_object_unref0 (range);
		_g_object_unref0 (current);
		_g_object_unref0 (root);
		return result;
	}
	if (focused == NULL) {
		_g_object_unref0 (_tmp15_);
		_tmp15_ = NULL;
	} else {
		GtkWidget* _tmp16_;
		GtkWidget* _tmp17_;
		_tmp16_ = root;
		_tmp17_ = proton_plus_utils_controller_manager_find_controller_activation_target (self, G_TYPE_CHECK_INSTANCE_CAST (focused, gtk_widget_get_type (), GtkWidget), _tmp16_);
		_g_object_unref0 (_tmp15_);
		_tmp15_ = _tmp17_;
	}
	_tmp18_ = _tmp15_;
	_tmp15_ = NULL;
	redirected_target = _tmp18_;
	_tmp22_ = redirected_target;
	if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp22_, gtk_switch_get_type ())) {
		_tmp21_ = TRUE;
	} else {
		GtkWidget* _tmp23_;
		_tmp23_ = redirected_target;
		_tmp21_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp23_, gtk_check_button_get_type ());
	}
	if (_tmp21_) {
		_tmp20_ = TRUE;
	} else {
		GtkWidget* _tmp24_;
		_tmp24_ = redirected_target;
		_tmp20_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp24_, gtk_toggle_button_get_type ());
	}
	if (_tmp20_) {
		_tmp19_ = TRUE;
	} else {
		GtkWidget* _tmp25_;
		_tmp25_ = redirected_target;
		_tmp19_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp25_, adw_switch_row_get_type ());
	}
	if (_tmp19_) {
		result = PROTON_PLUS_UTILS_CONTROLLER_HINT_CONTROL_KIND_TOGGLE;
		_g_object_unref0 (redirected_target);
		_g_object_unref0 (_tmp15_);
		_g_object_unref0 (range);
		_g_object_unref0 (current);
		_g_object_unref0 (root);
		return result;
	}
	_tmp26_ = _g_object_ref0 (focused);
	_g_object_unref0 (current);
	current = _tmp26_;
	while (TRUE) {
		GtkWidget* _tmp27_;
		gboolean _tmp28_ = FALSE;
		gboolean _tmp29_ = FALSE;
		gboolean _tmp30_ = FALSE;
		GtkWidget* _tmp31_;
		gboolean _tmp35_ = FALSE;
		gboolean _tmp36_ = FALSE;
		gboolean _tmp37_ = FALSE;
		GtkWidget* _tmp38_;
		GtkWidget* _tmp42_;
		GtkWidget* _tmp43_;
		GtkWidget* _tmp44_;
		GtkWidget* _tmp45_;
		GtkWidget* _tmp46_;
		_tmp27_ = current;
		if (!(_tmp27_ != NULL)) {
			break;
		}
		_tmp31_ = current;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp31_, gtk_switch_get_type ())) {
			_tmp30_ = TRUE;
		} else {
			GtkWidget* _tmp32_;
			_tmp32_ = current;
			_tmp30_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp32_, gtk_check_button_get_type ());
		}
		if (_tmp30_) {
			_tmp29_ = TRUE;
		} else {
			GtkWidget* _tmp33_;
			_tmp33_ = current;
			_tmp29_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp33_, gtk_toggle_button_get_type ());
		}
		if (_tmp29_) {
			_tmp28_ = TRUE;
		} else {
			GtkWidget* _tmp34_;
			_tmp34_ = current;
			_tmp28_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp34_, adw_switch_row_get_type ());
		}
		if (_tmp28_) {
			result = PROTON_PLUS_UTILS_CONTROLLER_HINT_CONTROL_KIND_TOGGLE;
			_g_object_unref0 (redirected_target);
			_g_object_unref0 (_tmp15_);
			_g_object_unref0 (range);
			_g_object_unref0 (current);
			_g_object_unref0 (root);
			return result;
		}
		_tmp38_ = current;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp38_, gtk_drop_down_get_type ())) {
			_tmp37_ = TRUE;
		} else {
			GtkWidget* _tmp39_;
			_tmp39_ = current;
			_tmp37_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp39_, gtk_combo_box_get_type ());
		}
		if (_tmp37_) {
			_tmp36_ = TRUE;
		} else {
			GtkWidget* _tmp40_;
			_tmp40_ = current;
			_tmp36_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp40_, gtk_menu_button_get_type ());
		}
		if (_tmp36_) {
			_tmp35_ = TRUE;
		} else {
			GtkWidget* _tmp41_;
			_tmp41_ = current;
			_tmp35_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp41_, adw_combo_row_get_type ());
		}
		if (_tmp35_) {
			result = PROTON_PLUS_UTILS_CONTROLLER_HINT_CONTROL_KIND_OPEN;
			_g_object_unref0 (redirected_target);
			_g_object_unref0 (_tmp15_);
			_g_object_unref0 (range);
			_g_object_unref0 (current);
			_g_object_unref0 (root);
			return result;
		}
		_tmp42_ = current;
		_tmp43_ = root;
		if (_tmp42_ == _tmp43_) {
			break;
		}
		_tmp44_ = current;
		_tmp45_ = gtk_widget_get_parent (_tmp44_);
		_tmp46_ = _g_object_ref0 (_tmp45_);
		_g_object_unref0 (current);
		current = _tmp46_;
	}
	_tmp47_ = root;
	_tmp48_ = proton_plus_utils_controller_editable_target_resolver_resolve (focused, _tmp47_);
	_tmp49_ = _tmp48_;
	_tmp50_ = _tmp49_ != NULL;
	_g_object_unref0 (_tmp49_);
	if (_tmp50_) {
		result = PROTON_PLUS_UTILS_CONTROLLER_HINT_CONTROL_KIND_EDITABLE;
		_g_object_unref0 (redirected_target);
		_g_object_unref0 (_tmp15_);
		_g_object_unref0 (range);
		_g_object_unref0 (current);
		_g_object_unref0 (root);
		return result;
	}
	result = PROTON_PLUS_UTILS_CONTROLLER_HINT_CONTROL_KIND_DEFAULT;
	_g_object_unref0 (redirected_target);
	_g_object_unref0 (_tmp15_);
	_g_object_unref0 (range);
	_g_object_unref0 (current);
	_g_object_unref0 (root);
	return result;
}

static void
_proton_plus_utils_controller_manager_refresh_presentation_g_object_notify (GObject* _sender,
                                                                            GParamSpec* pspec,
                                                                            gpointer self)
{
	proton_plus_utils_controller_manager_refresh_presentation ((ProtonPlusUtilsControllerManager*) self);
}

static void
proton_plus_utils_controller_manager_sync_presentation_range (ProtonPlusUtilsControllerManager* self,
                                                              GtkRange* range)
{
	GtkRange* _tmp0_;
	GtkRange* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->presentation_range;
	if (_tmp0_ == range) {
		return;
	}
	proton_plus_utils_controller_manager_disconnect_presentation_range (self);
	self->priv->presentation_range = range;
	_tmp1_ = self->priv->presentation_range;
	if (_tmp1_ != NULL) {
		GtkRange* _tmp2_;
		gulong _tmp3_;
		_tmp2_ = self->priv->presentation_range;
		_tmp3_ = g_signal_connect_object ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, gtk_range_get_type (), GtkRange), "notify::orientation", (GCallback) _proton_plus_utils_controller_manager_refresh_presentation_g_object_notify, self, 0);
		self->priv->presentation_range_orientation_handler = _tmp3_;
	}
}

static void
proton_plus_utils_controller_manager_disconnect_presentation_range (ProtonPlusUtilsControllerManager* self)
{
	GtkRange* range = NULL;
	GtkRange* _tmp0_;
	GtkRange* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GtkRange* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->presentation_range;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	range = _tmp1_;
	_tmp3_ = range;
	if (_tmp3_ != NULL) {
		_tmp2_ = self->priv->presentation_range_orientation_handler != ((gulong) 0);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		GtkRange* _tmp4_;
		_tmp4_ = range;
		g_signal_handler_disconnect ((GObject*) _tmp4_, self->priv->presentation_range_orientation_handler);
	}
	self->priv->presentation_range_orientation_handler = (gulong) 0;
	self->priv->presentation_range = NULL;
	_g_object_unref0 (range);
}

static void
proton_plus_utils_controller_manager_handle_button_down (ProtonPlusUtilsControllerManager* self,
                                                         SDL_JoystickID id,
                                                         SDL_GamepadButton button)
{
	ProtonPlusUtilsControllerManagerGamepadState* gamepad = NULL;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp0_;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp1_;
	gint64 device_id = 0LL;
	ProtonPlusUtilsControllerInputPolicy* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = proton_plus_utils_controller_manager_find_gamepad (self, id);
	gamepad = _tmp0_;
	_tmp1_ = gamepad;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (gamepad);
		return;
	}
	device_id = proton_plus_utils_controller_manager_controller_id (self, id);
	_tmp2_ = self->priv->input_policy;
	if (proton_plus_utils_controller_input_policy_note_button_press (_tmp2_, device_id)) {
		ProtonPlusUtilsControllerHapticFeedback* _tmp3_;
		proton_plus_utils_controller_manager_cancel_repeat_timer (self);
		_tmp3_ = self->priv->haptic_feedback;
		proton_plus_utils_controller_haptic_feedback_claim_device (_tmp3_, device_id);
	}
	proton_plus_utils_controller_manager_activate_controller_mode (self);
	switch (button) {
		case SDL_GAMEPAD_BUTTON_DPAD_UP:
		case SDL_GAMEPAD_BUTTON_DPAD_DOWN:
		case SDL_GAMEPAD_BUTTON_DPAD_LEFT:
		case SDL_GAMEPAD_BUTTON_DPAD_RIGHT:
		{
			ProtonPlusUtilsControllerNavigationDirection direction = 0;
			ProtonPlusUtilsControllerInputPolicy* _tmp4_;
			direction = proton_plus_utils_controller_manager_direction_for_dpad (self, button);
			proton_plus_utils_controller_manager_handle_controller_direction (self, device_id, direction);
			_tmp4_ = self->priv->input_policy;
			proton_plus_utils_controller_input_policy_begin_repeat (_tmp4_, device_id, direction, PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_SOURCE_DPAD);
			proton_plus_utils_controller_manager_restart_repeat_timer (self);
			break;
		}
		case SDL_GAMEPAD_BUTTON_SOUTH:
		case SDL_GAMEPAD_BUTTON_EAST:
		{
			proton_plus_utils_controller_manager_handle_face_button (self, device_id, button);
			break;
		}
		case SDL_GAMEPAD_BUTTON_WEST:
		{
			proton_plus_utils_controller_manager_handle_page_shortcut (self, device_id, TRUE);
			break;
		}
		case SDL_GAMEPAD_BUTTON_NORTH:
		{
			proton_plus_utils_controller_manager_handle_page_shortcut (self, device_id, FALSE);
			break;
		}
		case SDL_GAMEPAD_BUTTON_START:
		{
			if (!proton_plus_utils_controller_manager_has_active_modal_surface (self)) {
				ProtonPlusWidgetsWindow* _tmp5_;
				_tmp5_ = self->priv->window;
				proton_plus_widgets_window_open_menu (_tmp5_);
			}
			break;
		}
		case SDL_GAMEPAD_BUTTON_BACK:
		{
			if (!proton_plus_utils_controller_manager_has_active_modal_surface (self)) {
				ProtonPlusWidgetsWindow* _tmp6_;
				_tmp6_ = self->priv->window;
				proton_plus_widgets_window_open_launchers (_tmp6_);
			}
			break;
		}
		case SDL_GAMEPAD_BUTTON_LEFT_SHOULDER:
		{
			ProtonPlusUtilsControllerHapticFeedback* _tmp7_;
			_tmp7_ = self->priv->haptic_feedback;
			proton_plus_utils_controller_haptic_feedback_navigation_outcome (_tmp7_, device_id, proton_plus_utils_controller_manager_switch_tab (self, -1), g_get_monotonic_time ());
			break;
		}
		case SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER:
		{
			ProtonPlusUtilsControllerHapticFeedback* _tmp8_;
			_tmp8_ = self->priv->haptic_feedback;
			proton_plus_utils_controller_haptic_feedback_navigation_outcome (_tmp8_, device_id, proton_plus_utils_controller_manager_switch_tab (self, 1), g_get_monotonic_time ());
			break;
		}
		default:
		{
			break;
		}
	}
	proton_plus_utils_controller_manager_sync_highlight (self);
	_g_object_unref0 (gamepad);
}

static void
proton_plus_utils_controller_manager_handle_button_up (ProtonPlusUtilsControllerManager* self,
                                                       SDL_JoystickID id,
                                                       SDL_GamepadButton button)
{
	ProtonPlusUtilsControllerNavigationDirection direction = 0;
	ProtonPlusUtilsControllerHapticFeedback* _tmp0_;
	gboolean _tmp1_ = FALSE;
	g_return_if_fail (self != NULL);
	direction = proton_plus_utils_controller_manager_direction_for_dpad (self, button);
	_tmp0_ = self->priv->haptic_feedback;
	proton_plus_utils_controller_haptic_feedback_direction_released (_tmp0_, proton_plus_utils_controller_manager_controller_id (self, id), direction);
	if (direction != PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_NONE) {
		ProtonPlusUtilsControllerInputPolicy* _tmp2_;
		_tmp2_ = self->priv->input_policy;
		_tmp1_ = proton_plus_utils_controller_input_policy_release_repeat (_tmp2_, proton_plus_utils_controller_manager_controller_id (self, id), direction, PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_SOURCE_DPAD);
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		proton_plus_utils_controller_manager_cancel_repeat_timer (self);
	}
}

static ProtonPlusUtilsControllerNavigationDirection
proton_plus_utils_controller_manager_direction_for_dpad (ProtonPlusUtilsControllerManager* self,
                                                         SDL_GamepadButton button)
{
	ProtonPlusUtilsControllerNavigationDirection result;
	g_return_val_if_fail (self != NULL, 0);
	switch (button) {
		case SDL_GAMEPAD_BUTTON_DPAD_UP:
		{
			result = PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_UP;
			return result;
		}
		case SDL_GAMEPAD_BUTTON_DPAD_DOWN:
		{
			result = PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_DOWN;
			return result;
		}
		case SDL_GAMEPAD_BUTTON_DPAD_LEFT:
		{
			result = PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_LEFT;
			return result;
		}
		case SDL_GAMEPAD_BUTTON_DPAD_RIGHT:
		{
			result = PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_RIGHT;
			return result;
		}
		default:
		{
			result = PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_NONE;
			return result;
		}
	}
}

static void
proton_plus_utils_controller_manager_handle_face_button (ProtonPlusUtilsControllerManager* self,
                                                         gint64 device_id,
                                                         SDL_GamepadButton button)
{
	ProtonPlusUtilsControllerConfirmButton confirm_button = 0;
	GSettings* _tmp0_;
	ProtonPlusUtilsControllerFaceButton _tmp2_ = 0;
	ProtonPlusUtilsControllerFaceButton face_button = 0;
	g_return_if_fail (self != NULL);
	confirm_button = PROTON_PLUS_UTILS_CONTROLLER_CONFIRM_BUTTON_SOUTH;
	_tmp0_ = proton_plus_globals_SETTINGS;
	if (_tmp0_ != NULL) {
		GSettings* _tmp1_;
		_tmp1_ = proton_plus_globals_SETTINGS;
		confirm_button = (ProtonPlusUtilsControllerConfirmButton) g_settings_get_enum (_tmp1_, "controller-confirm-button");
	}
	if (button == SDL_GAMEPAD_BUTTON_SOUTH) {
		_tmp2_ = PROTON_PLUS_UTILS_CONTROLLER_FACE_BUTTON_SOUTH;
	} else {
		_tmp2_ = PROTON_PLUS_UTILS_CONTROLLER_FACE_BUTTON_EAST;
	}
	face_button = _tmp2_;
	if (proton_plus_utils_controller_input_policy_get_face_button_action (confirm_button, face_button) == PROTON_PLUS_UTILS_CONTROLLER_FACE_BUTTON_ACTION_ACTIVATE) {
		ProtonPlusUtilsControllerActivationDecision decision = 0;
		gboolean succeeded = FALSE;
		ProtonPlusUtilsControllerActivationDecision _tmp3_ = 0;
		gboolean _tmp4_;
		ProtonPlusUtilsControllerHapticFeedback* _tmp5_;
		_tmp4_ = proton_plus_utils_controller_manager_activate_focused (self, &_tmp3_);
		decision = _tmp3_;
		succeeded = _tmp4_;
		_tmp5_ = self->priv->haptic_feedback;
		proton_plus_utils_controller_haptic_feedback_activation_outcome (_tmp5_, device_id, decision, succeeded, g_get_monotonic_time ());
	} else {
		gboolean succeeded = FALSE;
		ProtonPlusUtilsControllerHapticFeedback* _tmp6_;
		succeeded = proton_plus_utils_controller_manager_perform_navigate_back (self);
		_tmp6_ = self->priv->haptic_feedback;
		proton_plus_utils_controller_haptic_feedback_navigation_outcome (_tmp6_, device_id, succeeded, g_get_monotonic_time ());
	}
}

static void
proton_plus_utils_controller_manager_handle_page_shortcut (ProtonPlusUtilsControllerManager* self,
                                                           gint64 device_id,
                                                           gboolean search)
{
	gboolean succeeded = FALSE;
	ProtonPlusUtilsControllerHapticFeedback* _tmp6_;
	g_return_if_fail (self != NULL);
	succeeded = FALSE;
	if (!proton_plus_utils_controller_manager_has_active_modal_surface (self)) {
		ProtonPlusUtilsControllerPageShortcuts* shortcuts = NULL;
		ProtonPlusUtilsControllerNavigationHost* _tmp0_;
		ProtonPlusUtilsControllerPageShortcuts* _tmp1_;
		ProtonPlusUtilsControllerPageShortcuts* _tmp2_;
		_tmp0_ = proton_plus_utils_controller_manager_get_active_navigation_host (self);
		_tmp1_ = PROTON_PLUS_UTILS_IS_CONTROLLER_PAGE_SHORTCUTS (_tmp0_) ? ((ProtonPlusUtilsControllerPageShortcuts*) _tmp0_) : NULL;
		if (_tmp1_ == NULL) {
			_g_object_unref0 (_tmp0_);
		}
		shortcuts = _tmp1_;
		_tmp2_ = shortcuts;
		if (_tmp2_ != NULL) {
			gboolean _tmp3_ = FALSE;
			if (search) {
				ProtonPlusUtilsControllerPageShortcuts* _tmp4_;
				_tmp4_ = shortcuts;
				_tmp3_ = proton_plus_utils_controller_page_shortcuts_controller_open_search (_tmp4_);
			} else {
				ProtonPlusUtilsControllerPageShortcuts* _tmp5_;
				_tmp5_ = shortcuts;
				_tmp3_ = proton_plus_utils_controller_page_shortcuts_controller_open_filter (_tmp5_);
			}
			succeeded = _tmp3_;
		}
		_g_object_unref0 (shortcuts);
	}
	_tmp6_ = self->priv->haptic_feedback;
	proton_plus_utils_controller_haptic_feedback_activation_outcome (_tmp6_, device_id, PROTON_PLUS_UTILS_CONTROLLER_ACTIVATION_DECISION_ACTIVATE, succeeded, g_get_monotonic_time ());
	if (succeeded) {
		proton_plus_utils_controller_manager_save_current_page_focus (self);
		proton_plus_utils_controller_manager_schedule_scroll_to_focus (self);
		proton_plus_utils_controller_manager_refresh_presentation (self);
	}
}

static gboolean
__lambda374_ (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerInputPolicy* _tmp1_;
	gint64 _tmp2_;
	gint64 _tmp3_;
	ProtonPlusUtilsControllerInputPolicy* _tmp4_;
	ProtonPlusUtilsControllerNavigationDirection _tmp5_;
	ProtonPlusUtilsControllerNavigationDirection _tmp6_;
	gboolean result;
	if (!proton_plus_utils_controller_manager_can_repeat_navigation (self)) {
		ProtonPlusUtilsControllerInputPolicy* _tmp0_;
		_tmp0_ = self->priv->input_policy;
		proton_plus_utils_controller_input_policy_cancel_repeat (_tmp0_);
		self->priv->repeat_timeout_id = (guint) 0;
		result = G_SOURCE_REMOVE;
		return result;
	}
	_tmp1_ = self->priv->input_policy;
	_tmp2_ = proton_plus_utils_controller_input_policy_get_repeat_device_id (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = self->priv->input_policy;
	_tmp5_ = proton_plus_utils_controller_input_policy_get_repeat_direction (_tmp4_);
	_tmp6_ = _tmp5_;
	proton_plus_utils_controller_manager_handle_controller_direction (self, _tmp3_, _tmp6_);
	result = G_SOURCE_CONTINUE;
	return result;
}

static gboolean
___lambda374__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda374_ ((ProtonPlusUtilsControllerManager*) self);
	return result;
}

static gboolean
__lambda373_ (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerInputPolicy* _tmp1_;
	gint64 _tmp2_;
	gint64 _tmp3_;
	ProtonPlusUtilsControllerInputPolicy* _tmp4_;
	ProtonPlusUtilsControllerNavigationDirection _tmp5_;
	ProtonPlusUtilsControllerNavigationDirection _tmp6_;
	gboolean result;
	if (!proton_plus_utils_controller_manager_can_repeat_navigation (self)) {
		ProtonPlusUtilsControllerInputPolicy* _tmp0_;
		_tmp0_ = self->priv->input_policy;
		proton_plus_utils_controller_input_policy_cancel_repeat (_tmp0_);
		self->priv->repeat_timeout_id = (guint) 0;
		result = G_SOURCE_REMOVE;
		return result;
	}
	_tmp1_ = self->priv->input_policy;
	_tmp2_ = proton_plus_utils_controller_input_policy_get_repeat_device_id (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = self->priv->input_policy;
	_tmp5_ = proton_plus_utils_controller_input_policy_get_repeat_direction (_tmp4_);
	_tmp6_ = _tmp5_;
	proton_plus_utils_controller_manager_handle_controller_direction (self, _tmp3_, _tmp6_);
	self->priv->repeat_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, PROTON_PLUS_UTILS_CONTROLLER_MANAGER_REPEAT_INTERVAL, ___lambda374__gsource_func, g_object_ref (self), g_object_unref);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda373__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda373_ ((ProtonPlusUtilsControllerManager*) self);
	return result;
}

static void
proton_plus_utils_controller_manager_restart_repeat_timer (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerInputPolicy* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	proton_plus_utils_controller_manager_cancel_repeat_timer (self);
	_tmp0_ = self->priv->input_policy;
	_tmp1_ = proton_plus_utils_controller_input_policy_get_has_repeat (_tmp0_);
	_tmp2_ = _tmp1_;
	if (!_tmp2_) {
		return;
	}
	self->priv->repeat_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, PROTON_PLUS_UTILS_CONTROLLER_MANAGER_INITIAL_REPEAT_DELAY, ___lambda373__gsource_func, g_object_ref (self), g_object_unref);
}

static gboolean
proton_plus_utils_controller_manager_can_repeat_navigation (ProtonPlusUtilsControllerManager* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	ProtonPlusWidgetsWindow* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp2_ = self->priv->window;
	g_object_get ((GtkWindow*) _tmp2_, "is-active", &_tmp3_, NULL);
	_tmp4_ = _tmp3_;
	if (_tmp4_) {
		ProtonPlusUtilsControllerInputPolicy* _tmp5_;
		gboolean _tmp6_;
		gboolean _tmp7_;
		_tmp5_ = self->priv->input_policy;
		_tmp6_ = proton_plus_utils_controller_input_policy_get_has_repeat (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp1_ = _tmp7_;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		ProtonPlusUtilsControllerInputPolicy* _tmp8_;
		gint64 _tmp9_;
		gint64 _tmp10_;
		ProtonPlusUtilsControllerManagerGamepadState* _tmp11_;
		ProtonPlusUtilsControllerManagerGamepadState* _tmp12_;
		_tmp8_ = self->priv->input_policy;
		_tmp9_ = proton_plus_utils_controller_input_policy_get_repeat_device_id (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = proton_plus_utils_controller_manager_find_gamepad_by_controller_id (self, _tmp10_);
		_tmp12_ = _tmp11_;
		_tmp0_ = _tmp12_ != NULL;
		_g_object_unref0 (_tmp12_);
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static void
proton_plus_utils_controller_manager_stop_navigation_repeat (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerInputPolicy* _tmp0_;
	g_return_if_fail (self != NULL);
	proton_plus_utils_controller_manager_cancel_repeat_timer (self);
	_tmp0_ = self->priv->input_policy;
	proton_plus_utils_controller_input_policy_cancel_repeat (_tmp0_);
}

static void
proton_plus_utils_controller_manager_cancel_repeat_timer (ProtonPlusUtilsControllerManager* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->repeat_timeout_id != ((guint) 0)) {
		g_source_remove (self->priv->repeat_timeout_id);
		self->priv->repeat_timeout_id = (guint) 0;
	}
}

static void
proton_plus_utils_controller_manager_handle_controller_direction (ProtonPlusUtilsControllerManager* self,
                                                                  gint64 device_id,
                                                                  ProtonPlusUtilsControllerNavigationDirection direction)
{
	ProtonPlusUtilsControllerManagerGtkSurface* surface = NULL;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp0_;
	GtkWidget* focused = NULL;
	GtkWidget* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GtkWidget* _tmp3_;
	GtkWidget* root = NULL;
	GtkWidget* _tmp6_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp7_;
	GtkWidget* _tmp8_;
	GtkWidget* control = NULL;
	GtkWidget* _tmp9_;
	GtkWidget* _tmp10_;
	GtkWidget* _tmp11_;
	GtkRange* range = NULL;
	GtkWidget* _tmp12_;
	GtkRange* _tmp13_;
	ProtonPlusUtilsControllerControlKind control_kind = 0;
	GtkRange* _tmp14_;
	ProtonPlusUtilsControllerDirectionAction action = 0;
	gboolean moved = FALSE;
	ProtonPlusUtilsControllerDirectionalFocus* directional_focus = NULL;
	GtkWidget* _tmp15_;
	GtkWidget* _tmp16_;
	ProtonPlusUtilsControllerDirectionalFocus* _tmp17_;
	gboolean _tmp18_ = FALSE;
	GtkWidget* _tmp19_;
	ProtonPlusUtilsControllerHapticFeedback* _tmp27_;
	g_return_if_fail (self != NULL);
	if (direction == PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_NONE) {
		return;
	}
	_tmp0_ = proton_plus_utils_controller_manager_get_active_surface (self);
	surface = _tmp0_;
	_tmp1_ = proton_plus_utils_controller_manager_get_focused_widget (self);
	focused = _tmp1_;
	_tmp3_ = focused;
	if (_tmp3_ != NULL) {
		GtkWidget* _tmp4_;
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp5_;
		_tmp4_ = focused;
		_tmp5_ = surface;
		_tmp2_ = !proton_plus_utils_controller_manager_is_inside_surface (self, _tmp4_, _tmp5_);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		_g_object_unref0 (focused);
		focused = NULL;
	}
	_tmp6_ = focused;
	_tmp7_ = surface;
	_tmp8_ = proton_plus_utils_controller_manager_get_direction_input_root (self, _tmp6_, _tmp7_);
	root = _tmp8_;
	_tmp9_ = focused;
	_tmp10_ = root;
	_tmp11_ = proton_plus_utils_controller_manager_resolve_effective_standard_control (self, _tmp9_, _tmp10_);
	control = _tmp11_;
	_tmp12_ = control;
	_tmp13_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp12_, gtk_range_get_type ()) ? ((GtkRange*) _tmp12_) : NULL);
	range = _tmp13_;
	_tmp14_ = range;
	control_kind = proton_plus_utils_controller_manager_get_control_kind (self, _tmp14_);
	action = proton_plus_utils_controller_control_policy_get_direction_action (control_kind, direction);
	moved = FALSE;
	_tmp15_ = focused;
	_tmp16_ = root;
	_tmp17_ = proton_plus_utils_controller_manager_find_directional_focus_ancestor (self, _tmp15_, _tmp16_);
	directional_focus = _tmp17_;
	_tmp19_ = focused;
	if (_tmp19_ != NULL) {
		ProtonPlusUtilsControllerDirectionalFocus* _tmp20_;
		_tmp20_ = directional_focus;
		_tmp18_ = _tmp20_ != NULL;
	} else {
		_tmp18_ = FALSE;
	}
	if (_tmp18_) {
		ProtonPlusUtilsControllerDirectionalFocus* _tmp21_;
		GtkWidget* _tmp22_;
		_tmp21_ = directional_focus;
		_tmp22_ = focused;
		moved = proton_plus_utils_controller_directional_focus_controller_focus_direction (_tmp21_, (GObject*) G_TYPE_CHECK_INSTANCE_CAST (_tmp22_, gtk_widget_get_type (), GtkWidget), direction);
	}
	if (moved) {
		proton_plus_utils_controller_manager_controller_focus_changed (self);
	} else {
		gboolean _tmp23_ = FALSE;
		GtkRange* _tmp24_;
		_tmp24_ = range;
		if (_tmp24_ != NULL) {
			_tmp23_ = action != PROTON_PLUS_UTILS_CONTROLLER_DIRECTION_ACTION_MOVE_FOCUS;
		} else {
			_tmp23_ = FALSE;
		}
		if (_tmp23_) {
			GtkRange* _tmp25_;
			_tmp25_ = range;
			moved = proton_plus_utils_controller_manager_adjust_range (self, _tmp25_, action);
		} else {
			GtkWidget* _tmp26_;
			_tmp26_ = root;
			moved = proton_plus_utils_controller_manager_move_focus (self, _tmp26_, direction);
		}
	}
	_tmp27_ = self->priv->haptic_feedback;
	proton_plus_utils_controller_haptic_feedback_direction_outcome (_tmp27_, device_id, direction, moved, g_get_monotonic_time ());
	proton_plus_utils_controller_manager_sync_highlight (self);
	_g_object_unref0 (directional_focus);
	_g_object_unref0 (range);
	_g_object_unref0 (control);
	_g_object_unref0 (root);
	_g_object_unref0 (focused);
	_g_object_unref0 (surface);
}

static ProtonPlusUtilsControllerDirectionalFocus*
proton_plus_utils_controller_manager_find_directional_focus_ancestor (ProtonPlusUtilsControllerManager* self,
                                                                      GtkWidget* focused,
                                                                      GtkWidget* root)
{
	GtkWidget* current = NULL;
	GtkWidget* _tmp0_;
	ProtonPlusUtilsControllerDirectionalFocus* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (root != NULL, NULL);
	_tmp0_ = _g_object_ref0 (focused);
	current = _tmp0_;
	while (TRUE) {
		GtkWidget* _tmp1_;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		GtkWidget* _tmp7_;
		GtkWidget* _tmp8_;
		_tmp1_ = current;
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = current;
		if (PROTON_PLUS_UTILS_IS_CONTROLLER_DIRECTIONAL_FOCUS (_tmp2_)) {
			GtkWidget* _tmp3_;
			ProtonPlusUtilsControllerDirectionalFocus* _tmp4_;
			_tmp3_ = current;
			_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, PROTON_PLUS_UTILS_TYPE_CONTROLLER_DIRECTIONAL_FOCUS, ProtonPlusUtilsControllerDirectionalFocus));
			result = _tmp4_;
			_g_object_unref0 (current);
			return result;
		}
		_tmp5_ = current;
		if (_tmp5_ == root) {
			break;
		}
		_tmp6_ = current;
		_tmp7_ = gtk_widget_get_parent (_tmp6_);
		_tmp8_ = _g_object_ref0 (_tmp7_);
		_g_object_unref0 (current);
		current = _tmp8_;
	}
	result = NULL;
	_g_object_unref0 (current);
	return result;
}

static GtkWidget*
proton_plus_utils_controller_manager_get_direction_input_root (ProtonPlusUtilsControllerManager* self,
                                                               GtkWidget* focused,
                                                               ProtonPlusUtilsControllerManagerGtkSurface* surface)
{
	GtkWidget* current = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp6_ = NULL;
	GtkWidget* _tmp7_;
	GtkWidget* _tmp9_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (surface != NULL, NULL);
	_tmp0_ = _g_object_ref0 (focused);
	current = _tmp0_;
	while (TRUE) {
		GtkWidget* _tmp1_;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp3_;
		GtkWidget* _tmp4_;
		GtkWidget* _tmp5_;
		_tmp1_ = current;
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = current;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, gtk_popover_get_type ())) {
			result = current;
			return result;
		}
		_tmp3_ = current;
		_tmp4_ = gtk_widget_get_parent (_tmp3_);
		_tmp5_ = _g_object_ref0 (_tmp4_);
		_g_object_unref0 (current);
		current = _tmp5_;
	}
	_tmp7_ = surface->widget;
	_tmp6_ = _tmp7_;
	if (_tmp6_ == NULL) {
		ProtonPlusWidgetsWindow* _tmp8_;
		_tmp8_ = self->priv->window;
		_tmp6_ = (GtkWidget*) _tmp8_;
	}
	_tmp9_ = _g_object_ref0 (_tmp6_);
	result = _tmp9_;
	_g_object_unref0 (current);
	return result;
}

static GtkWidget*
proton_plus_utils_controller_manager_resolve_effective_standard_control (ProtonPlusUtilsControllerManager* self,
                                                                         GtkWidget* focused,
                                                                         GtkWidget* root)
{
	GtkWidget* current = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp7_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (root != NULL, NULL);
	_tmp0_ = _g_object_ref0 (focused);
	current = _tmp0_;
	while (TRUE) {
		GtkWidget* _tmp1_;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp3_;
		GtkWidget* _tmp4_;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		_tmp1_ = current;
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = current;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, gtk_range_get_type ())) {
			result = current;
			return result;
		}
		_tmp3_ = current;
		if (_tmp3_ == root) {
			break;
		}
		_tmp4_ = current;
		_tmp5_ = gtk_widget_get_parent (_tmp4_);
		_tmp6_ = _g_object_ref0 (_tmp5_);
		_g_object_unref0 (current);
		current = _tmp6_;
	}
	_tmp7_ = _g_object_ref0 (focused);
	result = _tmp7_;
	_g_object_unref0 (current);
	return result;
}

static ProtonPlusUtilsControllerControlKind
proton_plus_utils_controller_manager_get_control_kind (ProtonPlusUtilsControllerManager* self,
                                                       GtkRange* range)
{
	ProtonPlusUtilsControllerControlKind _tmp0_ = 0;
	ProtonPlusUtilsControllerControlKind result;
	g_return_val_if_fail (self != NULL, 0);
	if (range == NULL) {
		result = PROTON_PLUS_UTILS_CONTROLLER_CONTROL_KIND_DEFAULT;
		return result;
	}
	if (gtk_orientable_get_orientation (G_TYPE_CHECK_INSTANCE_CAST (range, gtk_orientable_get_type (), GtkOrientable)) == GTK_ORIENTATION_HORIZONTAL) {
		_tmp0_ = PROTON_PLUS_UTILS_CONTROLLER_CONTROL_KIND_HORIZONTAL_RANGE;
	} else {
		_tmp0_ = PROTON_PLUS_UTILS_CONTROLLER_CONTROL_KIND_VERTICAL_RANGE;
	}
	result = _tmp0_;
	return result;
}

static gboolean
proton_plus_utils_controller_manager_adjust_range (ProtonPlusUtilsControllerManager* self,
                                                   GtkRange* range,
                                                   ProtonPlusUtilsControllerDirectionAction action)
{
	gboolean horizontal = FALSE;
	GtkScrollType movement = 0;
	gdouble previous_value = 0.0;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (range != NULL, FALSE);
	horizontal = gtk_orientable_get_orientation (G_TYPE_CHECK_INSTANCE_CAST (range, gtk_orientable_get_type (), GtkOrientable)) == GTK_ORIENTATION_HORIZONTAL;
	if (horizontal) {
		GtkScrollType _tmp0_ = 0;
		if (action == PROTON_PLUS_UTILS_CONTROLLER_DIRECTION_ACTION_ADJUST_BACKWARD) {
			_tmp0_ = GTK_SCROLL_STEP_LEFT;
		} else {
			_tmp0_ = GTK_SCROLL_STEP_RIGHT;
		}
		movement = _tmp0_;
	} else {
		GtkScrollType _tmp1_ = 0;
		if (action == PROTON_PLUS_UTILS_CONTROLLER_DIRECTION_ACTION_ADJUST_BACKWARD) {
			_tmp1_ = GTK_SCROLL_STEP_UP;
		} else {
			_tmp1_ = GTK_SCROLL_STEP_DOWN;
		}
		movement = _tmp1_;
	}
	previous_value = gtk_range_get_value (range);
	g_signal_emit_by_name (range, "move-slider", movement);
	result = gtk_range_get_value (range) != previous_value;
	return result;
}

static gboolean
proton_plus_utils_controller_manager_move_focus (ProtonPlusUtilsControllerManager* self,
                                                 GtkWidget* root,
                                                 ProtonPlusUtilsControllerNavigationDirection direction)
{
	gboolean moved = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (root != NULL, FALSE);
	moved = FALSE;
	switch (direction) {
		case PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_UP:
		{
			moved = gtk_widget_child_focus (root, GTK_DIR_UP);
			if (!moved) {
				moved = gtk_widget_child_focus (root, GTK_DIR_TAB_BACKWARD);
			}
			break;
		}
		case PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_DOWN:
		{
			moved = gtk_widget_child_focus (root, GTK_DIR_DOWN);
			if (!moved) {
				moved = gtk_widget_child_focus (root, GTK_DIR_TAB_FORWARD);
			}
			break;
		}
		case PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_LEFT:
		{
			moved = gtk_widget_child_focus (root, GTK_DIR_LEFT);
			break;
		}
		case PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_RIGHT:
		{
			moved = gtk_widget_child_focus (root, GTK_DIR_RIGHT);
			break;
		}
		default:
		{
			break;
		}
	}
	if (moved) {
		proton_plus_utils_controller_manager_controller_focus_changed (self);
	}
	result = moved;
	return result;
}

static void
proton_plus_utils_controller_manager_handle_axis (ProtonPlusUtilsControllerManager* self,
                                                  SDL_JoystickID id,
                                                  SDL_GamepadAxis axis,
                                                  gint16 raw)
{
	ProtonPlusUtilsControllerManagerGamepadState* gamepad = NULL;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp0_;
	ProtonPlusUtilsControllerManagerGamepadState* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = proton_plus_utils_controller_manager_find_gamepad (self, id);
	gamepad = _tmp0_;
	_tmp1_ = gamepad;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (gamepad);
		return;
	}
	switch (axis) {
		case SDL_GAMEPAD_AXIS_LEFTX:
		case SDL_GAMEPAD_AXIS_LEFTY:
		{
			ProtonPlusUtilsControllerNavigationDirection _tmp2_ = 0;
			gboolean _tmp3_ = FALSE;
			gboolean _tmp4_ = FALSE;
			ProtonPlusUtilsControllerInputPolicy* _tmp5_;
			gboolean _tmp6_;
			gboolean _tmp7_;
			ProtonPlusUtilsControllerNavigationDirection released_direction = 0;
			ProtonPlusUtilsControllerNavigationUpdate* update = NULL;
			ProtonPlusUtilsControllerInputPolicy* _tmp17_;
			ProtonPlusUtilsControllerNavigationUpdate* _tmp18_;
			ProtonPlusUtilsControllerNavigationUpdate* _tmp19_;
			gboolean _tmp20_;
			gboolean _tmp21_;
			ProtonPlusUtilsControllerNavigationUpdate* _tmp23_;
			ProtonPlusUtilsControllerNavigationDirection _tmp24_;
			ProtonPlusUtilsControllerNavigationDirection _tmp25_;
			gboolean _tmp29_ = FALSE;
			ProtonPlusUtilsControllerNavigationUpdate* _tmp30_;
			ProtonPlusUtilsControllerNavigationDirection _tmp31_;
			ProtonPlusUtilsControllerNavigationDirection _tmp32_;
			ProtonPlusUtilsControllerNavigationUpdate* _tmp37_;
			gboolean _tmp38_;
			gboolean _tmp39_;
			_tmp5_ = self->priv->input_policy;
			_tmp6_ = proton_plus_utils_controller_input_policy_get_has_repeat (_tmp5_);
			_tmp7_ = _tmp6_;
			if (_tmp7_) {
				ProtonPlusUtilsControllerInputPolicy* _tmp8_;
				gint64 _tmp9_;
				gint64 _tmp10_;
				_tmp8_ = self->priv->input_policy;
				_tmp9_ = proton_plus_utils_controller_input_policy_get_repeat_device_id (_tmp8_);
				_tmp10_ = _tmp9_;
				_tmp4_ = _tmp10_ == proton_plus_utils_controller_manager_controller_id (self, id);
			} else {
				_tmp4_ = FALSE;
			}
			if (_tmp4_) {
				ProtonPlusUtilsControllerInputPolicy* _tmp11_;
				ProtonPlusUtilsControllerNavigationSource _tmp12_;
				ProtonPlusUtilsControllerNavigationSource _tmp13_;
				_tmp11_ = self->priv->input_policy;
				_tmp12_ = proton_plus_utils_controller_input_policy_get_repeat_source (_tmp11_);
				_tmp13_ = _tmp12_;
				_tmp3_ = _tmp13_ == PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_SOURCE_LEFT_STICK;
			} else {
				_tmp3_ = FALSE;
			}
			if (_tmp3_) {
				ProtonPlusUtilsControllerInputPolicy* _tmp14_;
				ProtonPlusUtilsControllerNavigationDirection _tmp15_;
				ProtonPlusUtilsControllerNavigationDirection _tmp16_;
				_tmp14_ = self->priv->input_policy;
				_tmp15_ = proton_plus_utils_controller_input_policy_get_repeat_direction (_tmp14_);
				_tmp16_ = _tmp15_;
				_tmp2_ = _tmp16_;
			} else {
				_tmp2_ = PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_NONE;
			}
			released_direction = _tmp2_;
			_tmp17_ = self->priv->input_policy;
			_tmp18_ = proton_plus_utils_controller_input_policy_update_left_axis (_tmp17_, proton_plus_utils_controller_manager_controller_id (self, id), axis == SDL_GAMEPAD_AXIS_LEFTX, raw);
			update = _tmp18_;
			_tmp19_ = update;
			_tmp20_ = proton_plus_utils_controller_navigation_update_get_ownership_changed (_tmp19_);
			_tmp21_ = _tmp20_;
			if (_tmp21_) {
				ProtonPlusUtilsControllerHapticFeedback* _tmp22_;
				proton_plus_utils_controller_manager_cancel_repeat_timer (self);
				_tmp22_ = self->priv->haptic_feedback;
				proton_plus_utils_controller_haptic_feedback_claim_device (_tmp22_, proton_plus_utils_controller_manager_controller_id (self, id));
			}
			_tmp23_ = update;
			_tmp24_ = proton_plus_utils_controller_navigation_update_get_emitted_direction (_tmp23_);
			_tmp25_ = _tmp24_;
			if (_tmp25_ != PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_NONE) {
				ProtonPlusUtilsControllerNavigationUpdate* _tmp26_;
				ProtonPlusUtilsControllerNavigationDirection _tmp27_;
				ProtonPlusUtilsControllerNavigationDirection _tmp28_;
				proton_plus_utils_controller_manager_activate_controller_mode (self);
				_tmp26_ = update;
				_tmp27_ = proton_plus_utils_controller_navigation_update_get_emitted_direction (_tmp26_);
				_tmp28_ = _tmp27_;
				proton_plus_utils_controller_manager_handle_controller_direction (self, proton_plus_utils_controller_manager_controller_id (self, id), _tmp28_);
			}
			_tmp30_ = update;
			_tmp31_ = proton_plus_utils_controller_navigation_update_get_emitted_direction (_tmp30_);
			_tmp32_ = _tmp31_;
			if (_tmp32_ == PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_NONE) {
				ProtonPlusUtilsControllerNavigationUpdate* _tmp33_;
				gboolean _tmp34_;
				gboolean _tmp35_;
				_tmp33_ = update;
				_tmp34_ = proton_plus_utils_controller_navigation_update_get_repeat_changed (_tmp33_);
				_tmp35_ = _tmp34_;
				_tmp29_ = _tmp35_;
			} else {
				_tmp29_ = FALSE;
			}
			if (_tmp29_) {
				ProtonPlusUtilsControllerHapticFeedback* _tmp36_;
				_tmp36_ = self->priv->haptic_feedback;
				proton_plus_utils_controller_haptic_feedback_direction_released (_tmp36_, proton_plus_utils_controller_manager_controller_id (self, id), released_direction);
			}
			_tmp37_ = update;
			_tmp38_ = proton_plus_utils_controller_navigation_update_get_repeat_changed (_tmp37_);
			_tmp39_ = _tmp38_;
			if (_tmp39_) {
				proton_plus_utils_controller_manager_restart_repeat_timer (self);
			}
			_g_object_unref0 (update);
			break;
		}
		case SDL_GAMEPAD_AXIS_RIGHTY:
		{
			ProtonPlusUtilsControllerInputPolicy* _tmp40_;
			gboolean _tmp42_ = FALSE;
			gboolean _tmp43_ = FALSE;
			ProtonPlusUtilsControllerInputPolicy* _tmp44_;
			gboolean _tmp45_;
			gboolean _tmp46_;
			_tmp40_ = self->priv->input_policy;
			if (proton_plus_utils_controller_input_policy_update_right_axis (_tmp40_, proton_plus_utils_controller_manager_controller_id (self, id), raw)) {
				ProtonPlusUtilsControllerHapticFeedback* _tmp41_;
				proton_plus_utils_controller_manager_cancel_repeat_timer (self);
				_tmp41_ = self->priv->haptic_feedback;
				proton_plus_utils_controller_haptic_feedback_claim_device (_tmp41_, proton_plus_utils_controller_manager_controller_id (self, id));
			}
			_tmp44_ = self->priv->input_policy;
			_tmp45_ = proton_plus_utils_controller_input_policy_get_has_active_device (_tmp44_);
			_tmp46_ = _tmp45_;
			if (_tmp46_) {
				ProtonPlusUtilsControllerInputPolicy* _tmp47_;
				gint64 _tmp48_;
				gint64 _tmp49_;
				_tmp47_ = self->priv->input_policy;
				_tmp48_ = proton_plus_utils_controller_input_policy_get_active_device_id (_tmp47_);
				_tmp49_ = _tmp48_;
				_tmp43_ = _tmp49_ == proton_plus_utils_controller_manager_controller_id (self, id);
			} else {
				_tmp43_ = FALSE;
			}
			if (_tmp43_) {
				ProtonPlusUtilsControllerInputPolicy* _tmp50_;
				gdouble _tmp51_;
				gdouble _tmp52_;
				_tmp50_ = self->priv->input_policy;
				_tmp51_ = proton_plus_utils_controller_input_policy_get_scroll_intent (_tmp50_);
				_tmp52_ = _tmp51_;
				_tmp42_ = _tmp52_ != ((gdouble) 0);
			} else {
				_tmp42_ = FALSE;
			}
			if (_tmp42_) {
				proton_plus_utils_controller_manager_activate_controller_mode (self);
			}
			break;
		}
		default:
		{
			break;
		}
	}
	_g_object_unref0 (gamepad);
}

static void
proton_plus_utils_controller_manager_reset_input_state (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerInputPolicy* _tmp0_;
	g_return_if_fail (self != NULL);
	proton_plus_utils_controller_manager_cancel_repeat_timer (self);
	_tmp0_ = self->priv->input_policy;
	proton_plus_utils_controller_input_policy_reset_transient_input (_tmp0_);
}

static GtkWidget*
proton_plus_utils_controller_manager_get_input_root (ProtonPlusUtilsControllerManager* self)
{
	GtkWidget* _tmp0_ = NULL;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp1_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp2_;
	GtkWidget* _tmp3_;
	GtkWidget* _tmp4_;
	GtkWidget* _tmp6_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = proton_plus_utils_controller_manager_get_active_surface (self);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_->widget;
	_tmp4_ = _tmp3_;
	_g_object_unref0 (_tmp2_);
	_tmp0_ = _tmp4_;
	if (_tmp0_ == NULL) {
		ProtonPlusWidgetsWindow* _tmp5_;
		_tmp5_ = self->priv->window;
		_tmp0_ = (GtkWidget*) _tmp5_;
	}
	_tmp6_ = _g_object_ref0 (_tmp0_);
	result = _tmp6_;
	return result;
}

static GtkWidget*
proton_plus_utils_controller_manager_get_focused_widget (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerManagerGtkSurface* surface = NULL;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp0_;
	GtkWidget* focused = NULL;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp1_;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp7_;
	GtkWidget* _tmp11_ = NULL;
	GtkWidget* _tmp12_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp13_;
	GtkWidget* _tmp15_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = proton_plus_utils_controller_manager_get_active_surface (self);
	surface = _tmp0_;
	focused = NULL;
	_tmp1_ = surface;
	_tmp2_ = _tmp1_->widget;
	if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, adw_dialog_get_type ())) {
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp3_;
		GtkWidget* _tmp4_;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		_tmp3_ = surface;
		_tmp4_ = _tmp3_->widget;
		_tmp5_ = adw_dialog_get_focus (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, adw_dialog_get_type (), AdwDialog));
		_tmp6_ = _g_object_ref0 (_tmp5_);
		_g_object_unref0 (focused);
		focused = _tmp6_;
	}
	_tmp7_ = focused;
	if (_tmp7_ == NULL) {
		ProtonPlusWidgetsWindow* _tmp8_;
		GtkWidget* _tmp9_;
		GtkWidget* _tmp10_;
		_tmp8_ = self->priv->window;
		_tmp9_ = gtk_root_get_focus ((GtkRoot*) _tmp8_);
		_tmp10_ = _g_object_ref0 (_tmp9_);
		_g_object_unref0 (focused);
		focused = _tmp10_;
	}
	_tmp12_ = focused;
	_tmp13_ = surface;
	if (proton_plus_utils_controller_manager_is_inside_surface (self, _tmp12_, _tmp13_)) {
		GtkWidget* _tmp14_;
		_tmp14_ = focused;
		_tmp11_ = _tmp14_;
	} else {
		_tmp11_ = NULL;
	}
	_tmp15_ = _g_object_ref0 (_tmp11_);
	result = _tmp15_;
	_g_object_unref0 (focused);
	_g_object_unref0 (surface);
	return result;
}

static ProtonPlusUtilsControllerManagerGtkSurface*
proton_plus_utils_controller_manager_get_active_surface (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerSurfacePolicy* _tmp0_;
	ProtonPlusUtilsControllerSurface* _tmp1_;
	ProtonPlusUtilsControllerSurface* _tmp2_;
	ProtonPlusUtilsControllerManagerGtkSurface* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->surface_policy;
	_tmp1_ = proton_plus_utils_controller_surface_policy_get_active_surface (_tmp0_);
	_tmp2_ = _tmp1_;
	result = G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_SURFACE, ProtonPlusUtilsControllerManagerGtkSurface);
	return result;
}

static gboolean
proton_plus_utils_controller_manager_has_active_modal_surface (ProtonPlusUtilsControllerManager* self)
{
	gboolean _tmp0_ = FALSE;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp1_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp2_;
	ProtonPlusUtilsControllerSurfaceKind _tmp3_;
	ProtonPlusUtilsControllerSurfaceKind _tmp4_;
	gboolean _tmp5_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp1_ = proton_plus_utils_controller_manager_get_active_surface (self);
	_tmp2_ = _tmp1_;
	_tmp3_ = proton_plus_utils_controller_surface_get_kind ((ProtonPlusUtilsControllerSurface*) _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_ != PROTON_PLUS_UTILS_CONTROLLER_SURFACE_KIND_WINDOW;
	_g_object_unref0 (_tmp2_);
	if (_tmp5_) {
		_tmp0_ = TRUE;
	} else {
		GtkPopover* _tmp6_;
		GtkPopover* _tmp7_;
		_tmp6_ = proton_plus_utils_controller_manager_find_focused_popover (self);
		_tmp7_ = _tmp6_;
		_tmp0_ = _tmp7_ != NULL;
		_g_object_unref0 (_tmp7_);
	}
	result = _tmp0_;
	return result;
}

static gboolean
proton_plus_utils_controller_manager_activate_focused (ProtonPlusUtilsControllerManager* self,
                                                       ProtonPlusUtilsControllerActivationDecision* decision)
{
	ProtonPlusUtilsControllerActivationDecision _vala_decision = 0;
	GtkWidget* focused = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* root = NULL;
	GtkWidget* _tmp2_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp3_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp4_;
	GtkWidget* _tmp5_;
	GtkWidget* _tmp6_;
	GtkWidget* editable = NULL;
	GtkWidget* _tmp7_;
	GtkWidget* _tmp8_;
	GtkWidget* _tmp9_;
	GtkWidget* _tmp10_;
	gchar* previous_page_id = NULL;
	GtkWidget* previous_page_root = NULL;
	gchar* _tmp12_ = NULL;
	GtkWidget* _tmp13_ = NULL;
	guint64 previous_surface_generation = 0ULL;
	GtkListView* list_view = NULL;
	GtkWidget* _tmp14_;
	GtkWidget* _tmp15_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp16_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp17_;
	GtkWidget* _tmp18_;
	GtkWidget* _tmp19_;
	GtkListView* _tmp20_;
	GtkListView* _tmp21_;
	ProtonPlusUtilsControllerActivationHandler* activation_handler = NULL;
	GtkWidget* _tmp22_;
	GtkWidget* _tmp23_;
	ProtonPlusUtilsControllerActivationHandler* _tmp24_;
	GtkWidget* redirected_target = NULL;
	GtkWidget* _tmp25_;
	GtkWidget* _tmp26_;
	GtkWidget* _tmp27_;
	gboolean succeeded = FALSE;
	ProtonPlusUtilsControllerActivationHandler* _tmp28_;
	gchar* active_page_id = NULL;
	GtkWidget* active_page_root = NULL;
	gchar* _tmp49_ = NULL;
	GtkWidget* _tmp50_ = NULL;
	gboolean _tmp51_ = FALSE;
	gboolean _tmp52_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_vala_decision = PROTON_PLUS_UTILS_CONTROLLER_ACTIVATION_DECISION_ACTIVATE;
	_tmp0_ = proton_plus_utils_controller_manager_get_focused_widget (self);
	focused = _tmp0_;
	_tmp1_ = focused;
	if (_tmp1_ == NULL) {
		result = FALSE;
		_g_object_unref0 (focused);
		if (decision) {
			*decision = _vala_decision;
		}
		return result;
	}
	_tmp2_ = focused;
	_tmp3_ = proton_plus_utils_controller_manager_get_active_surface (self);
	_tmp4_ = _tmp3_;
	_tmp5_ = proton_plus_utils_controller_manager_get_direction_input_root (self, _tmp2_, _tmp4_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp4_);
	root = _tmp6_;
	_tmp7_ = focused;
	_tmp8_ = root;
	_tmp9_ = proton_plus_utils_controller_editable_target_resolver_resolve (_tmp7_, _tmp8_);
	editable = _tmp9_;
	_tmp10_ = editable;
	_vala_decision = proton_plus_utils_controller_activation_policy_for_focused_control (_tmp10_ != NULL);
	if (_vala_decision == PROTON_PLUS_UTILS_CONTROLLER_ACTIVATION_DECISION_FOCUS_TEXT_INPUT) {
		GtkWidget* _tmp11_;
		proton_plus_utils_controller_manager_save_current_page_focus (self);
		_tmp11_ = editable;
		proton_plus_utils_controller_manager_focus_text_input (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp11_, gtk_widget_get_type (), GtkWidget));
		proton_plus_utils_controller_manager_schedule_scroll_to_focus (self);
		proton_plus_utils_controller_manager_refresh_presentation (self);
		result = FALSE;
		_g_object_unref0 (editable);
		_g_object_unref0 (root);
		_g_object_unref0 (focused);
		if (decision) {
			*decision = _vala_decision;
		}
		return result;
	}
	proton_plus_utils_controller_manager_get_active_page_context (self, &_tmp12_, &_tmp13_);
	_g_free0 (previous_page_id);
	previous_page_id = _tmp12_;
	_g_object_unref0 (previous_page_root);
	previous_page_root = _tmp13_;
	proton_plus_utils_controller_manager_save_current_page_focus (self);
	previous_surface_generation = self->priv->surface_generation;
	_tmp14_ = focused;
	_tmp15_ = focused;
	_tmp16_ = proton_plus_utils_controller_manager_get_active_surface (self);
	_tmp17_ = _tmp16_;
	_tmp18_ = proton_plus_utils_controller_manager_get_direction_input_root (self, _tmp15_, _tmp17_);
	_tmp19_ = _tmp18_;
	_tmp20_ = proton_plus_utils_controller_manager_find_list_view_ancestor (self, _tmp14_, _tmp19_);
	_tmp21_ = _tmp20_;
	_g_object_unref0 (_tmp19_);
	_g_object_unref0 (_tmp17_);
	list_view = _tmp21_;
	_tmp22_ = focused;
	_tmp23_ = root;
	_tmp24_ = proton_plus_utils_controller_manager_find_controller_activation_handler (self, _tmp22_, _tmp23_);
	activation_handler = _tmp24_;
	_tmp25_ = focused;
	_tmp26_ = root;
	_tmp27_ = proton_plus_utils_controller_manager_find_controller_activation_target (self, _tmp25_, _tmp26_);
	redirected_target = _tmp27_;
	succeeded = FALSE;
	_tmp28_ = activation_handler;
	if (_tmp28_ != NULL) {
		ProtonPlusUtilsControllerActivationHandler* _tmp29_;
		GtkWidget* _tmp30_;
		_tmp29_ = activation_handler;
		_tmp30_ = focused;
		succeeded = proton_plus_utils_controller_activation_handler_controller_activate (G_TYPE_CHECK_INSTANCE_CAST (_tmp29_, PROTON_PLUS_UTILS_TYPE_CONTROLLER_ACTIVATION_HANDLER, ProtonPlusUtilsControllerActivationHandler), (GObject*) _tmp30_);
	} else {
		GtkWidget* _tmp31_;
		_tmp31_ = redirected_target;
		if (_tmp31_ != NULL) {
			GtkWidget* _tmp32_;
			_tmp32_ = redirected_target;
			succeeded = gtk_widget_activate (G_TYPE_CHECK_INSTANCE_CAST (_tmp32_, gtk_widget_get_type (), GtkWidget));
		} else {
			GtkListView* _tmp33_;
			_tmp33_ = list_view;
			if (_tmp33_ != NULL) {
				GtkWidget* _tmp34_;
				GtkSelectionModel* model = NULL;
				GtkListView* _tmp35_;
				GtkSelectionModel* _tmp36_;
				GtkSelectionModel* _tmp37_;
				GtkSelectionModel* _tmp38_ = NULL;
				GtkSelectionModel* _tmp39_;
				GtkBitset* _tmp40_ = NULL;
				GtkBitset* selection = NULL;
				GtkBitset* _tmp42_;
				gboolean _tmp43_ = FALSE;
				GtkBitset* _tmp44_;
				_tmp34_ = focused;
				gtk_widget_activate_action (_tmp34_, "listitem.select", "(bb)", FALSE, FALSE, NULL);
				_tmp35_ = list_view;
				_tmp36_ = gtk_list_view_get_model (_tmp35_);
				_tmp37_ = _g_object_ref0 (_tmp36_);
				model = _tmp37_;
				_tmp39_ = model;
				_tmp38_ = _tmp39_;
				_tmp40_ = NULL;
				if (_tmp38_ != NULL) {
					GtkBitset* _tmp41_;
					_tmp41_ = gtk_selection_model_get_selection (_tmp38_);
					_gtk_bitset_unref0 (_tmp40_);
					_tmp40_ = _tmp41_;
				}
				_tmp42_ = _tmp40_;
				_tmp40_ = NULL;
				selection = _tmp42_;
				_tmp44_ = selection;
				if (_tmp44_ != NULL) {
					GtkBitset* _tmp45_;
					_tmp45_ = selection;
					_tmp43_ = !gtk_bitset_is_empty (_tmp45_);
				} else {
					_tmp43_ = FALSE;
				}
				if (_tmp43_) {
					GtkListView* _tmp46_;
					GtkBitset* _tmp47_;
					_tmp46_ = list_view;
					_tmp47_ = selection;
					g_signal_emit_by_name (_tmp46_, "activate", gtk_bitset_get_minimum (_tmp47_));
					succeeded = TRUE;
				}
				_gtk_bitset_unref0 (selection);
				_gtk_bitset_unref0 (_tmp40_);
				_g_object_unref0 (model);
			} else {
				GtkWidget* _tmp48_;
				_tmp48_ = focused;
				succeeded = gtk_widget_activate (_tmp48_);
			}
		}
	}
	proton_plus_utils_controller_manager_get_active_page_context (self, &_tmp49_, &_tmp50_);
	_g_free0 (active_page_id);
	active_page_id = _tmp49_;
	_g_object_unref0 (active_page_root);
	active_page_root = _tmp50_;
	if (previous_surface_generation == self->priv->surface_generation) {
		const gchar* _tmp53_;
		const gchar* _tmp54_;
		_tmp53_ = previous_page_id;
		_tmp54_ = active_page_id;
		_tmp52_ = g_strcmp0 (_tmp53_, _tmp54_) != 0;
	} else {
		_tmp52_ = FALSE;
	}
	if (_tmp52_) {
		GtkWidget* _tmp55_;
		_tmp55_ = active_page_root;
		_tmp51_ = _tmp55_ != NULL;
	} else {
		_tmp51_ = FALSE;
	}
	if (_tmp51_) {
		proton_plus_utils_controller_manager_schedule_page_focus_restore (self, FALSE);
	}
	proton_plus_utils_controller_manager_refresh_presentation (self);
	result = succeeded;
	_g_object_unref0 (active_page_root);
	_g_free0 (active_page_id);
	_g_object_unref0 (redirected_target);
	_g_object_unref0 (activation_handler);
	_g_object_unref0 (list_view);
	_g_object_unref0 (previous_page_root);
	_g_free0 (previous_page_id);
	_g_object_unref0 (editable);
	_g_object_unref0 (root);
	_g_object_unref0 (focused);
	if (decision) {
		*decision = _vala_decision;
	}
	return result;
}

static ProtonPlusUtilsControllerActivationHandler*
proton_plus_utils_controller_manager_find_controller_activation_handler (ProtonPlusUtilsControllerManager* self,
                                                                         GtkWidget* focused,
                                                                         GtkWidget* root)
{
	GtkWidget* current = NULL;
	GtkWidget* _tmp0_;
	ProtonPlusUtilsControllerActivationHandler* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (focused != NULL, NULL);
	g_return_val_if_fail (root != NULL, NULL);
	_tmp0_ = _g_object_ref0 (focused);
	current = _tmp0_;
	while (TRUE) {
		GtkWidget* _tmp1_;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		GtkWidget* _tmp7_;
		GtkWidget* _tmp8_;
		_tmp1_ = current;
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = current;
		if (PROTON_PLUS_UTILS_IS_CONTROLLER_ACTIVATION_HANDLER (_tmp2_)) {
			GtkWidget* _tmp3_;
			ProtonPlusUtilsControllerActivationHandler* _tmp4_;
			_tmp3_ = current;
			_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, PROTON_PLUS_UTILS_TYPE_CONTROLLER_ACTIVATION_HANDLER, ProtonPlusUtilsControllerActivationHandler));
			result = _tmp4_;
			_g_object_unref0 (current);
			return result;
		}
		_tmp5_ = current;
		if (_tmp5_ == root) {
			break;
		}
		_tmp6_ = current;
		_tmp7_ = gtk_widget_get_parent (_tmp6_);
		_tmp8_ = _g_object_ref0 (_tmp7_);
		_g_object_unref0 (current);
		current = _tmp8_;
	}
	result = NULL;
	_g_object_unref0 (current);
	return result;
}

static GtkWidget*
proton_plus_utils_controller_manager_find_controller_activation_target (ProtonPlusUtilsControllerManager* self,
                                                                        GtkWidget* focused,
                                                                        GtkWidget* root)
{
	GtkWidget* current = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (focused != NULL, NULL);
	g_return_val_if_fail (root != NULL, NULL);
	_tmp0_ = _g_object_ref0 (focused);
	current = _tmp0_;
	while (TRUE) {
		GtkWidget* _tmp1_;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp6_;
		GtkWidget* _tmp7_;
		GtkWidget* _tmp8_;
		GtkWidget* _tmp9_;
		_tmp1_ = current;
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = current;
		if (PROTON_PLUS_UTILS_IS_CONTROLLER_ACTIVATION_REDIRECT (_tmp2_)) {
			GtkWidget* _tmp3_;
			GObject* _tmp4_;
			GtkWidget* _tmp5_;
			_tmp3_ = current;
			_tmp4_ = proton_plus_utils_controller_activation_redirect_get_controller_activation_target (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, PROTON_PLUS_UTILS_TYPE_CONTROLLER_ACTIVATION_REDIRECT, ProtonPlusUtilsControllerActivationRedirect), (GObject*) focused);
			_tmp5_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp4_, gtk_widget_get_type ()) ? ((GtkWidget*) _tmp4_) : NULL;
			if (_tmp5_ == NULL) {
				_g_object_unref0 (_tmp4_);
			}
			result = _tmp5_;
			_g_object_unref0 (current);
			return result;
		}
		_tmp6_ = current;
		if (_tmp6_ == root) {
			break;
		}
		_tmp7_ = current;
		_tmp8_ = gtk_widget_get_parent (_tmp7_);
		_tmp9_ = _g_object_ref0 (_tmp8_);
		_g_object_unref0 (current);
		current = _tmp9_;
	}
	result = NULL;
	_g_object_unref0 (current);
	return result;
}

static void
proton_plus_utils_controller_manager_focus_text_input (ProtonPlusUtilsControllerManager* self,
                                                       GtkWidget* target)
{
	GtkWidget* focused = NULL;
	GtkWidget* _tmp0_;
	gboolean _tmp1_ = FALSE;
	GtkWidget* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (target != NULL);
	_tmp0_ = proton_plus_utils_controller_manager_get_focused_widget (self);
	focused = _tmp0_;
	_tmp2_ = focused;
	if (_tmp2_ != NULL) {
		GtkWidget* _tmp3_;
		_tmp3_ = focused;
		_tmp1_ = proton_plus_utils_controller_manager_widget_is_descendant_of (self, _tmp3_, target);
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		_g_object_unref0 (focused);
		return;
	}
	if (G_TYPE_CHECK_INSTANCE_TYPE (target, adw_entry_row_get_type ())) {
		adw_entry_row_grab_focus_without_selecting (G_TYPE_CHECK_INSTANCE_CAST (target, adw_entry_row_get_type (), AdwEntryRow));
	} else {
		if (G_TYPE_CHECK_INSTANCE_TYPE (target, gtk_entry_get_type ())) {
			gtk_entry_grab_focus_without_selecting (G_TYPE_CHECK_INSTANCE_CAST (target, gtk_entry_get_type (), GtkEntry));
		} else {
			if (G_TYPE_CHECK_INSTANCE_TYPE (target, gtk_editable_get_type ())) {
				GtkEditable* editable_delegate = NULL;
				GtkEditable* _tmp4_;
				GtkEditable* _tmp5_;
				GtkEditable* _tmp6_;
				_tmp4_ = gtk_editable_get_delegate (G_TYPE_CHECK_INSTANCE_CAST (target, gtk_editable_get_type (), GtkEditable));
				_tmp5_ = _g_object_ref0 (_tmp4_);
				editable_delegate = _tmp5_;
				_tmp6_ = editable_delegate;
				if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp6_, gtk_text_get_type ())) {
					GtkEditable* _tmp7_;
					_tmp7_ = editable_delegate;
					gtk_text_grab_focus_without_selecting (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, gtk_text_get_type (), GtkText));
				} else {
					gtk_widget_grab_focus (target);
				}
				_g_object_unref0 (editable_delegate);
			} else {
				gtk_widget_grab_focus (target);
			}
		}
	}
	_g_object_unref0 (focused);
}

static GtkListView*
proton_plus_utils_controller_manager_find_list_view_ancestor (ProtonPlusUtilsControllerManager* self,
                                                              GtkWidget* focused,
                                                              GtkWidget* root)
{
	GtkWidget* current = NULL;
	GtkWidget* _tmp0_;
	GtkListView* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (focused != NULL, NULL);
	g_return_val_if_fail (root != NULL, NULL);
	_tmp0_ = _g_object_ref0 (focused);
	current = _tmp0_;
	while (TRUE) {
		GtkWidget* _tmp1_;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		GtkWidget* _tmp7_;
		GtkWidget* _tmp8_;
		_tmp1_ = current;
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = current;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, gtk_list_view_get_type ())) {
			GtkWidget* _tmp3_;
			GtkListView* _tmp4_;
			_tmp3_ = current;
			_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, gtk_list_view_get_type (), GtkListView));
			result = _tmp4_;
			_g_object_unref0 (current);
			return result;
		}
		_tmp5_ = current;
		if (_tmp5_ == root) {
			break;
		}
		_tmp6_ = current;
		_tmp7_ = gtk_widget_get_parent (_tmp6_);
		_tmp8_ = _g_object_ref0 (_tmp7_);
		_g_object_unref0 (current);
		current = _tmp8_;
	}
	result = NULL;
	_g_object_unref0 (current);
	return result;
}

static void
proton_plus_utils_controller_manager_scroll (ProtonPlusUtilsControllerManager* self,
                                             gdouble delta)
{
	ProtonPlusUtilsControllerManagerGtkSurface* surface = NULL;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp0_;
	GtkWidget* root = NULL;
	GtkWidget* _tmp1_;
	GtkWidget* widget = NULL;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp3_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp15_;
	ProtonPlusUtilsControllerSurfaceKind _tmp16_;
	ProtonPlusUtilsControllerSurfaceKind _tmp17_;
	g_return_if_fail (self != NULL);
	_tmp0_ = proton_plus_utils_controller_manager_get_active_surface (self);
	surface = _tmp0_;
	_tmp1_ = proton_plus_utils_controller_manager_get_input_root (self);
	root = _tmp1_;
	_tmp2_ = proton_plus_utils_controller_manager_get_focused_widget (self);
	widget = _tmp2_;
	_tmp3_ = widget;
	if (_tmp3_ == NULL) {
		GtkWidget* _tmp4_;
		GtkWidget* _tmp5_;
		_tmp4_ = root;
		_tmp5_ = _g_object_ref0 (_tmp4_);
		_g_object_unref0 (widget);
		widget = _tmp5_;
	}
	while (TRUE) {
		GtkWidget* _tmp6_;
		GtkWidget* _tmp7_;
		GtkWidget* _tmp10_;
		GtkWidget* _tmp11_;
		GtkWidget* _tmp12_;
		GtkWidget* _tmp13_;
		GtkWidget* _tmp14_;
		_tmp6_ = widget;
		if (!(_tmp6_ != NULL)) {
			break;
		}
		_tmp7_ = widget;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp7_, gtk_scrolled_window_get_type ())) {
			GtkWidget* _tmp8_;
			GtkAdjustment* _tmp9_;
			_tmp8_ = widget;
			_tmp9_ = gtk_scrolled_window_get_vadjustment (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, gtk_scrolled_window_get_type (), GtkScrolledWindow));
			proton_plus_utils_controller_manager_scroll_adjustment (self, _tmp9_, delta);
			_g_object_unref0 (widget);
			_g_object_unref0 (root);
			_g_object_unref0 (surface);
			return;
		}
		_tmp10_ = widget;
		_tmp11_ = root;
		if (_tmp10_ == _tmp11_) {
			break;
		}
		_tmp12_ = widget;
		_tmp13_ = gtk_widget_get_parent (_tmp12_);
		_tmp14_ = _g_object_ref0 (_tmp13_);
		_g_object_unref0 (widget);
		widget = _tmp14_;
	}
	_tmp15_ = surface;
	_tmp16_ = proton_plus_utils_controller_surface_get_kind ((ProtonPlusUtilsControllerSurface*) _tmp15_);
	_tmp17_ = _tmp16_;
	if (_tmp17_ != PROTON_PLUS_UTILS_CONTROLLER_SURFACE_KIND_WINDOW) {
		GtkScrolledWindow* scrolled = NULL;
		GtkWidget* _tmp18_;
		GtkScrolledWindow* _tmp19_;
		GtkScrolledWindow* _tmp20_;
		_tmp18_ = root;
		_tmp19_ = proton_plus_utils_controller_manager_find_scrolled_descendant (self, _tmp18_);
		scrolled = _tmp19_;
		_tmp20_ = scrolled;
		if (_tmp20_ != NULL) {
			GtkScrolledWindow* _tmp21_;
			GtkAdjustment* _tmp22_;
			_tmp21_ = scrolled;
			_tmp22_ = gtk_scrolled_window_get_vadjustment (_tmp21_);
			proton_plus_utils_controller_manager_scroll_adjustment (self, _tmp22_, delta);
		}
		_g_object_unref0 (scrolled);
	}
	_g_object_unref0 (widget);
	_g_object_unref0 (root);
	_g_object_unref0 (surface);
}

static GtkScrolledWindow*
proton_plus_utils_controller_manager_find_scrolled_descendant (ProtonPlusUtilsControllerManager* self,
                                                               GtkWidget* root)
{
	GtkWidget* child = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkScrolledWindow* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (root != NULL, NULL);
	_tmp0_ = gtk_widget_get_first_child (root);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	child = _tmp1_;
	while (TRUE) {
		GtkWidget* _tmp2_;
		GtkWidget* _tmp3_;
		GtkScrolledWindow* nested = NULL;
		GtkWidget* _tmp6_;
		GtkScrolledWindow* _tmp7_;
		GtkScrolledWindow* _tmp8_;
		GtkWidget* _tmp9_;
		GtkWidget* _tmp10_;
		GtkWidget* _tmp11_;
		_tmp2_ = child;
		if (!(_tmp2_ != NULL)) {
			break;
		}
		_tmp3_ = child;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, gtk_scrolled_window_get_type ())) {
			GtkWidget* _tmp4_;
			GtkScrolledWindow* _tmp5_;
			_tmp4_ = child;
			_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_scrolled_window_get_type (), GtkScrolledWindow));
			result = _tmp5_;
			_g_object_unref0 (child);
			return result;
		}
		_tmp6_ = child;
		_tmp7_ = proton_plus_utils_controller_manager_find_scrolled_descendant (self, _tmp6_);
		nested = _tmp7_;
		_tmp8_ = nested;
		if (_tmp8_ != NULL) {
			result = nested;
			_g_object_unref0 (child);
			return result;
		}
		_tmp9_ = child;
		_tmp10_ = gtk_widget_get_next_sibling (_tmp9_);
		_tmp11_ = _g_object_ref0 (_tmp10_);
		_g_object_unref0 (child);
		child = _tmp11_;
		_g_object_unref0 (nested);
	}
	result = NULL;
	_g_object_unref0 (child);
	return result;
}

static void
proton_plus_utils_controller_manager_scroll_adjustment (ProtonPlusUtilsControllerManager* self,
                                                        GtkAdjustment* adjustment,
                                                        gdouble delta)
{
	gdouble maximum = 0.0;
	gdouble _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	gdouble _tmp3_;
	gdouble _tmp4_;
	gdouble _tmp5_;
	gdouble target = 0.0;
	gdouble _tmp8_;
	gdouble _tmp9_;
	gdouble _tmp10_;
	gdouble _tmp11_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (adjustment != NULL);
	_tmp0_ = gtk_adjustment_get_upper (adjustment);
	_tmp1_ = _tmp0_;
	_tmp2_ = gtk_adjustment_get_page_size (adjustment);
	_tmp3_ = _tmp2_;
	maximum = _tmp1_ - _tmp3_;
	_tmp4_ = gtk_adjustment_get_lower (adjustment);
	_tmp5_ = _tmp4_;
	if (maximum < _tmp5_) {
		gdouble _tmp6_;
		gdouble _tmp7_;
		_tmp6_ = gtk_adjustment_get_lower (adjustment);
		_tmp7_ = _tmp6_;
		maximum = _tmp7_;
	}
	_tmp8_ = gtk_adjustment_get_value (adjustment);
	_tmp9_ = _tmp8_;
	target = _tmp9_ + delta;
	_tmp10_ = gtk_adjustment_get_lower (adjustment);
	_tmp11_ = _tmp10_;
	if (target < _tmp11_) {
		gdouble _tmp12_;
		gdouble _tmp13_;
		_tmp12_ = gtk_adjustment_get_lower (adjustment);
		_tmp13_ = _tmp12_;
		target = _tmp13_;
	}
	if (target > maximum) {
		target = maximum;
	}
	gtk_adjustment_set_value (adjustment, target);
}

static gboolean
proton_plus_utils_controller_manager_dismiss_active_surface (ProtonPlusUtilsControllerManager* self)
{
	GtkPopover* focused_popover = NULL;
	GtkPopover* _tmp0_;
	GtkPopover* _tmp1_;
	ProtonPlusUtilsControllerManagerGtkSurface* surface = NULL;
	ProtonPlusUtilsControllerSurfacePolicy* _tmp3_;
	ProtonPlusUtilsControllerSurface* _tmp4_;
	ProtonPlusUtilsControllerSurface* _tmp5_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp6_;
	gboolean _tmp7_ = FALSE;
	gboolean _tmp8_ = FALSE;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp9_;
	gboolean _tmp17_ = FALSE;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp18_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = proton_plus_utils_controller_manager_find_focused_popover (self);
	focused_popover = _tmp0_;
	_tmp1_ = focused_popover;
	if (_tmp1_ != NULL) {
		GtkPopover* _tmp2_;
		_tmp2_ = focused_popover;
		gtk_popover_popdown (_tmp2_);
		result = TRUE;
		_g_object_unref0 (focused_popover);
		return result;
	}
	_tmp3_ = self->priv->surface_policy;
	_tmp4_ = proton_plus_utils_controller_surface_policy_get_dismissable_surface (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = PROTON_PLUS_UTILS_CONTROLLER_MANAGER_IS_GTK_SURFACE (_tmp5_) ? ((ProtonPlusUtilsControllerManagerGtkSurface*) _tmp5_) : NULL;
	if (_tmp6_ == NULL) {
		_g_object_unref0 (_tmp5_);
	}
	surface = _tmp6_;
	_tmp9_ = surface;
	if (_tmp9_ != NULL) {
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp10_;
		ProtonPlusUtilsControllerSurfaceKind _tmp11_;
		ProtonPlusUtilsControllerSurfaceKind _tmp12_;
		_tmp10_ = surface;
		_tmp11_ = proton_plus_utils_controller_surface_get_kind ((ProtonPlusUtilsControllerSurface*) _tmp10_);
		_tmp12_ = _tmp11_;
		_tmp8_ = _tmp12_ == PROTON_PLUS_UTILS_CONTROLLER_SURFACE_KIND_POPOVER;
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp13_;
		GtkWidget* _tmp14_;
		_tmp13_ = surface;
		_tmp14_ = _tmp13_->widget;
		_tmp7_ = _tmp14_ != NULL;
	} else {
		_tmp7_ = FALSE;
	}
	if (_tmp7_) {
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp15_;
		GtkWidget* _tmp16_;
		_tmp15_ = surface;
		_tmp16_ = _tmp15_->widget;
		gtk_popover_popdown (G_TYPE_CHECK_INSTANCE_CAST (_tmp16_, gtk_popover_get_type (), GtkPopover));
		result = TRUE;
		_g_object_unref0 (surface);
		_g_object_unref0 (focused_popover);
		return result;
	}
	_tmp18_ = surface;
	if (_tmp18_ != NULL) {
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp19_;
		GtkWidget* _tmp20_;
		_tmp19_ = surface;
		_tmp20_ = _tmp19_->widget;
		_tmp17_ = _tmp20_ != NULL;
	} else {
		_tmp17_ = FALSE;
	}
	if (_tmp17_) {
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp21_;
		GtkWidget* _tmp22_;
		_tmp21_ = surface;
		_tmp22_ = _tmp21_->widget;
		adw_dialog_close (G_TYPE_CHECK_INSTANCE_CAST (_tmp22_, adw_dialog_get_type (), AdwDialog));
		result = TRUE;
		_g_object_unref0 (surface);
		_g_object_unref0 (focused_popover);
		return result;
	}
	result = FALSE;
	_g_object_unref0 (surface);
	_g_object_unref0 (focused_popover);
	return result;
}

void
proton_plus_utils_controller_manager_navigate_back (ProtonPlusUtilsControllerManager* self)
{
	g_return_if_fail (self != NULL);
	proton_plus_utils_controller_manager_perform_navigate_back (self);
}

static gboolean
proton_plus_utils_controller_manager_perform_navigate_back (ProtonPlusUtilsControllerManager* self)
{
	gboolean has_modal = FALSE;
	ProtonPlusUtilsControllerNavigationHost* host = NULL;
	ProtonPlusUtilsControllerNavigationHost* _tmp0_;
	ProtonPlusUtilsControllerBackAction action = 0;
	ProtonPlusUtilsControllerNavigationPolicy* _tmp1_;
	ProtonPlusUtilsControllerNavigationHost* _tmp2_;
	gboolean succeeded = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	has_modal = proton_plus_utils_controller_manager_has_active_modal_surface (self);
	_tmp0_ = proton_plus_utils_controller_manager_get_active_navigation_host (self);
	host = _tmp0_;
	if (!has_modal) {
		proton_plus_utils_controller_manager_save_current_page_focus (self);
	}
	_tmp1_ = self->priv->navigation_policy;
	_tmp2_ = host;
	action = proton_plus_utils_controller_navigation_policy_navigate_back (_tmp1_, has_modal, _tmp2_, TRUE);
	succeeded = FALSE;
	switch (action) {
		case PROTON_PLUS_UTILS_CONTROLLER_BACK_ACTION_DISMISS_SURFACE:
		{
			succeeded = proton_plus_utils_controller_manager_dismiss_active_surface (self);
			break;
		}
		case PROTON_PLUS_UTILS_CONTROLLER_BACK_ACTION_NAVIGATE_APPLICATION:
		{
			proton_plus_utils_controller_manager_schedule_page_focus_restore (self, FALSE);
			succeeded = TRUE;
			break;
		}
		case PROTON_PLUS_UTILS_CONTROLLER_BACK_ACTION_REQUEST_EXIT:
		{
			ProtonPlusWidgetsWindow* _tmp3_;
			_tmp3_ = self->priv->window;
			proton_plus_widgets_window_request_controller_exit (_tmp3_);
			succeeded = TRUE;
			break;
		}
		default:
		{
			break;
		}
	}
	proton_plus_utils_controller_manager_refresh_presentation (self);
	result = succeeded;
	_g_object_unref0 (host);
	return result;
}

void
proton_plus_utils_controller_manager_navigate_application_back (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerBackAction action = 0;
	ProtonPlusUtilsControllerNavigationPolicy* _tmp0_;
	ProtonPlusUtilsControllerNavigationHost* _tmp1_;
	ProtonPlusUtilsControllerNavigationHost* _tmp2_;
	ProtonPlusUtilsControllerBackAction _tmp3_;
	g_return_if_fail (self != NULL);
	if (proton_plus_utils_controller_manager_has_active_modal_surface (self)) {
		return;
	}
	proton_plus_utils_controller_manager_save_current_page_focus (self);
	_tmp0_ = self->priv->navigation_policy;
	_tmp1_ = proton_plus_utils_controller_manager_get_active_navigation_host (self);
	_tmp2_ = _tmp1_;
	_tmp3_ = proton_plus_utils_controller_navigation_policy_navigate_back (_tmp0_, FALSE, _tmp2_, FALSE);
	_g_object_unref0 (_tmp2_);
	action = _tmp3_;
	if (action == PROTON_PLUS_UTILS_CONTROLLER_BACK_ACTION_NAVIGATE_APPLICATION) {
		proton_plus_utils_controller_manager_schedule_page_focus_restore (self, FALSE);
	}
	proton_plus_utils_controller_manager_refresh_presentation (self);
}

static GtkPopover*
proton_plus_utils_controller_manager_find_focused_popover (ProtonPlusUtilsControllerManager* self)
{
	GtkWidget* widget = NULL;
	GtkWidget* _tmp0_;
	GtkPopover* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = proton_plus_utils_controller_manager_get_focused_widget (self);
	widget = _tmp0_;
	while (TRUE) {
		GtkWidget* _tmp1_;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		GtkWidget* _tmp7_;
		_tmp1_ = widget;
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = widget;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, gtk_popover_get_type ())) {
			GtkWidget* _tmp3_;
			GtkPopover* _tmp4_;
			_tmp3_ = widget;
			_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, gtk_popover_get_type (), GtkPopover));
			result = _tmp4_;
			_g_object_unref0 (widget);
			return result;
		}
		_tmp5_ = widget;
		_tmp6_ = gtk_widget_get_parent (_tmp5_);
		_tmp7_ = _g_object_ref0 (_tmp6_);
		_g_object_unref0 (widget);
		widget = _tmp7_;
	}
	result = NULL;
	_g_object_unref0 (widget);
	return result;
}

static gboolean
proton_plus_utils_controller_manager_switch_tab (ProtonPlusUtilsControllerManager* self,
                                                 gint delta)
{
	ProtonPlusUtilsControllerManagerGtkSurface* surface = NULL;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp0_;
	gboolean _tmp1_ = FALSE;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp2_;
	ProtonPlusUtilsControllerSurfaceKind _tmp3_;
	ProtonPlusUtilsControllerSurfaceKind _tmp4_;
	ProtonPlusUtilsControllerNavigationHost* host = NULL;
	ProtonPlusUtilsControllerNavigationHost* _tmp7_;
	gboolean switched = FALSE;
	ProtonPlusUtilsControllerNavigationPolicy* _tmp8_;
	ProtonPlusUtilsControllerNavigationHost* _tmp9_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = proton_plus_utils_controller_manager_get_active_surface (self);
	surface = _tmp0_;
	_tmp2_ = surface;
	_tmp3_ = proton_plus_utils_controller_surface_get_kind ((ProtonPlusUtilsControllerSurface*) _tmp2_);
	_tmp4_ = _tmp3_;
	if (_tmp4_ == PROTON_PLUS_UTILS_CONTROLLER_SURFACE_KIND_POPOVER) {
		_tmp1_ = TRUE;
	} else {
		GtkPopover* _tmp5_;
		GtkPopover* _tmp6_;
		_tmp5_ = proton_plus_utils_controller_manager_find_focused_popover (self);
		_tmp6_ = _tmp5_;
		_tmp1_ = _tmp6_ != NULL;
		_g_object_unref0 (_tmp6_);
	}
	if (_tmp1_) {
		result = FALSE;
		_g_object_unref0 (surface);
		return result;
	}
	_tmp7_ = proton_plus_utils_controller_manager_get_active_navigation_host (self);
	host = _tmp7_;
	proton_plus_utils_controller_manager_save_current_page_focus (self);
	_tmp8_ = self->priv->navigation_policy;
	_tmp9_ = host;
	switched = proton_plus_utils_controller_navigation_policy_switch_page (_tmp8_, _tmp9_, delta);
	if (switched) {
		ProtonPlusUtilsControllerHapticFeedback* _tmp10_;
		gboolean _tmp11_ = FALSE;
		ProtonPlusUtilsControllerNavigationHost* _tmp12_;
		_tmp10_ = self->priv->haptic_feedback;
		proton_plus_utils_controller_haptic_feedback_context_changed (_tmp10_);
		_tmp12_ = host;
		if (_tmp12_ != NULL) {
			ProtonPlusUtilsControllerNavigationHost* _tmp13_;
			_tmp13_ = host;
			_tmp11_ = proton_plus_utils_controller_navigation_host_controller_prefers_initial_focus_after_switch (_tmp13_);
		} else {
			_tmp11_ = FALSE;
		}
		proton_plus_utils_controller_manager_schedule_page_focus_restore (self, _tmp11_);
	}
	proton_plus_utils_controller_manager_refresh_presentation (self);
	result = switched;
	_g_object_unref0 (host);
	_g_object_unref0 (surface);
	return result;
}

static ProtonPlusUtilsControllerNavigationHost*
proton_plus_utils_controller_manager_get_active_navigation_host (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerManagerGtkSurface* surface = NULL;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp0_;
	ProtonPlusUtilsControllerNavigationHost* host = NULL;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp1_;
	GtkWidget* _tmp2_;
	ProtonPlusUtilsControllerNavigationHost* _tmp3_;
	ProtonPlusUtilsControllerNavigationHost* _tmp4_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp5_;
	ProtonPlusUtilsControllerSurfaceKind _tmp6_;
	ProtonPlusUtilsControllerSurfaceKind _tmp7_;
	ProtonPlusUtilsControllerNavigationHost* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = proton_plus_utils_controller_manager_get_active_surface (self);
	surface = _tmp0_;
	_tmp1_ = surface;
	_tmp2_ = _tmp1_->widget;
	_tmp3_ = _g_object_ref0 (PROTON_PLUS_UTILS_IS_CONTROLLER_NAVIGATION_HOST (_tmp2_) ? ((ProtonPlusUtilsControllerNavigationHost*) _tmp2_) : NULL);
	host = _tmp3_;
	_tmp4_ = host;
	if (_tmp4_ != NULL) {
		result = host;
		_g_object_unref0 (surface);
		return result;
	}
	_tmp5_ = surface;
	_tmp6_ = proton_plus_utils_controller_surface_get_kind ((ProtonPlusUtilsControllerSurface*) _tmp5_);
	_tmp7_ = _tmp6_;
	if (_tmp7_ == PROTON_PLUS_UTILS_CONTROLLER_SURFACE_KIND_WINDOW) {
		ProtonPlusUtilsControllerNavigationHost* _tmp8_ = NULL;
		gboolean _tmp9_ = FALSE;
		gboolean _tmp10_ = FALSE;
		ProtonPlusWidgetsWindow* _tmp11_;
		ProtonPlusWidgetsMainBox* _tmp12_;
		ProtonPlusWidgetsMainBox* _tmp13_;
		GtkRoot* _tmp14_;
		ProtonPlusWidgetsWindow* _tmp15_;
		ProtonPlusUtilsControllerNavigationHost* _tmp25_;
		_tmp11_ = self->priv->window;
		_tmp12_ = proton_plus_widgets_window_get_main_box (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp14_ = gtk_widget_get_root ((GtkWidget*) _tmp13_);
		_tmp15_ = self->priv->window;
		if (_tmp14_ == G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, gtk_root_get_type (), GtkRoot)) {
			ProtonPlusWidgetsWindow* _tmp16_;
			ProtonPlusWidgetsMainBox* _tmp17_;
			ProtonPlusWidgetsMainBox* _tmp18_;
			_tmp16_ = self->priv->window;
			_tmp17_ = proton_plus_widgets_window_get_main_box (_tmp16_);
			_tmp18_ = _tmp17_;
			_tmp10_ = gtk_widget_get_mapped ((GtkWidget*) _tmp18_);
		} else {
			_tmp10_ = FALSE;
		}
		if (_tmp10_) {
			ProtonPlusWidgetsWindow* _tmp19_;
			ProtonPlusWidgetsMainBox* _tmp20_;
			ProtonPlusWidgetsMainBox* _tmp21_;
			_tmp19_ = self->priv->window;
			_tmp20_ = proton_plus_widgets_window_get_main_box (_tmp19_);
			_tmp21_ = _tmp20_;
			_tmp9_ = gtk_widget_get_visible ((GtkWidget*) _tmp21_);
		} else {
			_tmp9_ = FALSE;
		}
		if (_tmp9_) {
			ProtonPlusWidgetsWindow* _tmp22_;
			ProtonPlusWidgetsMainBox* _tmp23_;
			ProtonPlusWidgetsMainBox* _tmp24_;
			_tmp22_ = self->priv->window;
			_tmp23_ = proton_plus_widgets_window_get_main_box (_tmp22_);
			_tmp24_ = _tmp23_;
			_tmp8_ = PROTON_PLUS_UTILS_IS_CONTROLLER_NAVIGATION_HOST (_tmp24_) ? ((ProtonPlusUtilsControllerNavigationHost*) _tmp24_) : NULL;
		} else {
			_tmp8_ = NULL;
		}
		_tmp25_ = _g_object_ref0 (_tmp8_);
		result = _tmp25_;
		_g_object_unref0 (host);
		_g_object_unref0 (surface);
		return result;
	}
	result = NULL;
	_g_object_unref0 (host);
	_g_object_unref0 (surface);
	return result;
}

static void
proton_plus_utils_controller_manager_get_active_page_context (ProtonPlusUtilsControllerManager* self,
                                                              gchar** page_id,
                                                              GtkWidget** page_root)
{
	gchar* _vala_page_id = NULL;
	GtkWidget* _vala_page_root = NULL;
	ProtonPlusUtilsControllerNavigationHost* host = NULL;
	ProtonPlusUtilsControllerNavigationHost* _tmp0_;
	ProtonPlusUtilsControllerNavigationHost* _tmp1_;
	gchar* _tmp7_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp8_;
	ProtonPlusUtilsControllerManagerGtkSurface* _tmp9_;
	GtkWidget* _tmp10_;
	GtkWidget* _tmp11_;
	g_return_if_fail (self != NULL);
	_tmp0_ = proton_plus_utils_controller_manager_get_active_navigation_host (self);
	host = _tmp0_;
	_tmp1_ = host;
	if (_tmp1_ != NULL) {
		ProtonPlusUtilsControllerNavigationHost* _tmp2_;
		gchar* _tmp3_;
		ProtonPlusUtilsControllerNavigationHost* _tmp4_;
		GObject* _tmp5_;
		GtkWidget* _tmp6_;
		_tmp2_ = host;
		_tmp3_ = proton_plus_utils_controller_navigation_host_get_controller_page_id (_tmp2_);
		_g_free0 (_vala_page_id);
		_vala_page_id = _tmp3_;
		_tmp4_ = host;
		_tmp5_ = proton_plus_utils_controller_navigation_host_get_controller_page_root (_tmp4_);
		_tmp6_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp5_, gtk_widget_get_type ()) ? ((GtkWidget*) _tmp5_) : NULL;
		if (_tmp6_ == NULL) {
			_g_object_unref0 (_tmp5_);
		}
		_g_object_unref0 (_vala_page_root);
		_vala_page_root = _tmp6_;
		_g_object_unref0 (host);
		if (page_id) {
			*page_id = _vala_page_id;
		} else {
			_g_free0 (_vala_page_id);
		}
		if (page_root) {
			*page_root = _vala_page_root;
		} else {
			_g_object_unref0 (_vala_page_root);
		}
		return;
	}
	_tmp7_ = g_strdup ("");
	_g_free0 (_vala_page_id);
	_vala_page_id = _tmp7_;
	_tmp8_ = proton_plus_utils_controller_manager_get_active_surface (self);
	_tmp9_ = _tmp8_;
	_tmp10_ = _tmp9_->widget;
	_tmp11_ = _g_object_ref0 (_tmp10_);
	_g_object_unref0 (_vala_page_root);
	_vala_page_root = _tmp11_;
	_g_object_unref0 (_tmp9_);
	_g_object_unref0 (host);
	if (page_id) {
		*page_id = _vala_page_id;
	} else {
		_g_free0 (_vala_page_id);
	}
	if (page_root) {
		*page_root = _vala_page_root;
	} else {
		_g_object_unref0 (_vala_page_root);
	}
}

static void
proton_plus_utils_controller_manager_save_current_page_focus (ProtonPlusUtilsControllerManager* self)
{
	gchar* page_id = NULL;
	GtkWidget* page_root = NULL;
	gchar* _tmp0_ = NULL;
	GtkWidget* _tmp1_ = NULL;
	GtkWidget* focused = NULL;
	GtkWidget* _tmp2_;
	gboolean _tmp3_ = FALSE;
	GtkWidget* _tmp4_;
	g_return_if_fail (self != NULL);
	proton_plus_utils_controller_manager_get_active_page_context (self, &_tmp0_, &_tmp1_);
	_g_free0 (page_id);
	page_id = _tmp0_;
	_g_object_unref0 (page_root);
	page_root = _tmp1_;
	_tmp2_ = proton_plus_utils_controller_manager_get_focused_widget (self);
	focused = _tmp2_;
	_tmp4_ = page_root;
	if (_tmp4_ != NULL) {
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		_tmp5_ = focused;
		_tmp6_ = page_root;
		_tmp3_ = proton_plus_utils_controller_manager_is_valid_page_focus_target (self, _tmp5_, _tmp6_);
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		ProtonPlusUtilsControllerNavigationPolicy* _tmp7_;
		const gchar* _tmp8_;
		GtkWidget* _tmp9_;
		_tmp7_ = self->priv->navigation_policy;
		_tmp8_ = page_id;
		_tmp9_ = focused;
		proton_plus_utils_controller_navigation_policy_remember_focus (_tmp7_, _tmp8_, (GObject*) _tmp9_);
	}
	_g_object_unref0 (focused);
	_g_object_unref0 (page_root);
	_g_free0 (page_id);
}

static gboolean
proton_plus_utils_controller_manager_is_valid_page_focus_target (ProtonPlusUtilsControllerManager* self,
                                                                 GtkWidget* widget,
                                                                 GtkWidget* page_root)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (page_root != NULL, FALSE);
	if (proton_plus_utils_controller_manager_is_valid_focus_target (self, widget)) {
		_tmp1_ = proton_plus_utils_controller_manager_widget_is_descendant_of (self, G_TYPE_CHECK_INSTANCE_CAST (widget, gtk_widget_get_type (), GtkWidget), page_root);
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp2_;
		ProtonPlusUtilsControllerManagerGtkSurface* _tmp3_;
		_tmp2_ = proton_plus_utils_controller_manager_get_active_surface (self);
		_tmp3_ = _tmp2_;
		_tmp0_ = proton_plus_utils_controller_manager_is_inside_surface (self, widget, _tmp3_);
		_g_object_unref0 (_tmp3_);
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static void
proton_plus_utils_controller_manager_controller_focus_changed (ProtonPlusUtilsControllerManager* self)
{
	g_return_if_fail (self != NULL);
	proton_plus_utils_controller_manager_save_current_page_focus (self);
	proton_plus_utils_controller_manager_schedule_scroll_to_focus (self);
	proton_plus_utils_controller_manager_refresh_presentation (self);
}

static void
proton_plus_utils_controller_manager_schedule_page_focus_restore (ProtonPlusUtilsControllerManager* self,
                                                                  gboolean prefer_initial)
{
	ProtonPlusUtilsControllerNavigationHost* host = NULL;
	ProtonPlusUtilsControllerNavigationHost* _tmp0_;
	ProtonPlusUtilsControllerNavigationHost* _tmp1_;
	ProtonPlusUtilsControllerFocusRestoreRequest* request = NULL;
	ProtonPlusUtilsControllerNavigationPolicy* _tmp2_;
	ProtonPlusUtilsControllerNavigationHost* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	ProtonPlusUtilsControllerFocusRestoreRequest* _tmp6_;
	ProtonPlusUtilsControllerFocusRestoreRequest* _tmp7_;
	ProtonPlusUtilsControllerFocusRestoreRequest* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = proton_plus_utils_controller_manager_get_active_navigation_host (self);
	host = _tmp0_;
	_tmp1_ = host;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (host);
		return;
	}
	proton_plus_utils_controller_manager_cancel_navigation_focus_restore (self);
	_tmp2_ = self->priv->navigation_policy;
	_tmp3_ = host;
	_tmp4_ = proton_plus_utils_controller_navigation_host_get_controller_page_id (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = proton_plus_utils_controller_navigation_policy_begin_restore (_tmp2_, _tmp5_, self->priv->surface_generation);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	request = _tmp7_;
	_tmp8_ = request;
	proton_plus_utils_controller_manager_schedule_page_focus_restore_attempt (self, _tmp8_, 0, prefer_initial);
	_g_object_unref0 (request);
	_g_object_unref0 (host);
}

static Block78Data*
block78_data_ref (Block78Data* _data78_)
{
	g_atomic_int_inc (&_data78_->_ref_count_);
	return _data78_;
}

static void
block78_data_unref (void * _userdata_)
{
	Block78Data* _data78_;
	_data78_ = (Block78Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data78_->_ref_count_)) {
		ProtonPlusUtilsControllerManager* self;
		self = _data78_->self;
		_g_object_unref0 (_data78_->request);
		_g_object_unref0 (self);
		g_slice_free (Block78Data, _data78_);
	}
}

static gboolean
__lambda375_ (Block78Data* _data78_)
{
	ProtonPlusUtilsControllerManager* self;
	ProtonPlusUtilsControllerNavigationHost* host = NULL;
	ProtonPlusUtilsControllerNavigationHost* _tmp0_;
	gboolean _tmp1_ = FALSE;
	ProtonPlusUtilsControllerNavigationHost* _tmp2_;
	GtkWidget* page_root = NULL;
	ProtonPlusUtilsControllerNavigationHost* _tmp7_;
	GObject* _tmp8_;
	GtkWidget* _tmp9_;
	gboolean _tmp10_ = FALSE;
	gboolean _tmp11_ = FALSE;
	gboolean _tmp12_ = FALSE;
	gboolean _tmp13_ = FALSE;
	GtkWidget* _tmp14_;
	GtkWidget* remembered = NULL;
	ProtonPlusUtilsControllerNavigationPolicy* _tmp19_;
	const gchar* _tmp20_;
	const gchar* _tmp21_;
	GObject* _tmp22_;
	GtkWidget* _tmp23_;
	GtkWidget* initial = NULL;
	ProtonPlusUtilsControllerNavigationHost* _tmp24_;
	GObject* _tmp25_;
	GtkWidget* _tmp26_;
	ProtonPlusUtilsControllerFocusTargetChoice choice = 0;
	GtkWidget* _tmp27_;
	GtkWidget* _tmp28_;
	GtkWidget* _tmp29_;
	GtkWidget* _tmp30_;
	gboolean focused = FALSE;
	gboolean result;
	self = _data78_->self;
	self->priv->navigation_focus_source_id = (guint) 0;
	_tmp0_ = proton_plus_utils_controller_manager_get_active_navigation_host (self);
	host = _tmp0_;
	_tmp2_ = host;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		ProtonPlusUtilsControllerNavigationPolicy* _tmp3_;
		ProtonPlusUtilsControllerNavigationHost* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp3_ = self->priv->navigation_policy;
		_tmp4_ = host;
		_tmp5_ = proton_plus_utils_controller_navigation_host_get_controller_page_id (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp1_ = !proton_plus_utils_controller_navigation_policy_can_apply_restore (_tmp3_, _data78_->request, _tmp6_, self->priv->surface_generation);
		_g_free0 (_tmp6_);
	}
	if (_tmp1_) {
		result = G_SOURCE_REMOVE;
		_g_object_unref0 (host);
		return result;
	}
	_tmp7_ = host;
	_tmp8_ = proton_plus_utils_controller_navigation_host_get_controller_page_root (_tmp7_);
	_tmp9_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp8_, gtk_widget_get_type ()) ? ((GtkWidget*) _tmp8_) : NULL;
	if (_tmp9_ == NULL) {
		_g_object_unref0 (_tmp8_);
	}
	page_root = _tmp9_;
	_tmp14_ = page_root;
	if (_tmp14_ == NULL) {
		_tmp13_ = TRUE;
	} else {
		GtkWidget* _tmp15_;
		_tmp15_ = page_root;
		_tmp13_ = !gtk_widget_get_visible (_tmp15_);
	}
	if (_tmp13_) {
		_tmp12_ = TRUE;
	} else {
		GtkWidget* _tmp16_;
		_tmp16_ = page_root;
		_tmp12_ = !gtk_widget_get_mapped (_tmp16_);
	}
	if (_tmp12_) {
		_tmp11_ = TRUE;
	} else {
		GtkWidget* _tmp17_;
		_tmp17_ = page_root;
		_tmp11_ = gtk_widget_get_width (_tmp17_) <= 0;
	}
	if (_tmp11_) {
		_tmp10_ = TRUE;
	} else {
		GtkWidget* _tmp18_;
		_tmp18_ = page_root;
		_tmp10_ = gtk_widget_get_height (_tmp18_) <= 0;
	}
	if (_tmp10_) {
		if (_data78_->attempt < 8) {
			proton_plus_utils_controller_manager_schedule_page_focus_restore_attempt (self, _data78_->request, _data78_->attempt + 1, _data78_->prefer_initial);
		}
		result = G_SOURCE_REMOVE;
		_g_object_unref0 (page_root);
		_g_object_unref0 (host);
		return result;
	}
	_tmp19_ = self->priv->navigation_policy;
	_tmp20_ = proton_plus_utils_controller_focus_restore_request_get_page_id (_data78_->request);
	_tmp21_ = _tmp20_;
	_tmp22_ = proton_plus_utils_controller_navigation_policy_recall_focus (_tmp19_, _tmp21_);
	_tmp23_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp22_, gtk_widget_get_type ()) ? ((GtkWidget*) _tmp22_) : NULL;
	if (_tmp23_ == NULL) {
		_g_object_unref0 (_tmp22_);
	}
	remembered = _tmp23_;
	_tmp24_ = host;
	_tmp25_ = proton_plus_utils_controller_navigation_host_get_controller_initial_focus (_tmp24_);
	_tmp26_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp25_, gtk_widget_get_type ()) ? ((GtkWidget*) _tmp25_) : NULL;
	if (_tmp26_ == NULL) {
		_g_object_unref0 (_tmp25_);
	}
	initial = _tmp26_;
	_tmp27_ = remembered;
	_tmp28_ = page_root;
	_tmp29_ = initial;
	_tmp30_ = page_root;
	choice = proton_plus_utils_controller_navigation_policy_choose_focus_target (proton_plus_utils_controller_manager_is_valid_page_focus_target (self, _tmp27_, _tmp28_), proton_plus_utils_controller_manager_is_valid_page_focus_target (self, _tmp29_, _tmp30_), _data78_->prefer_initial);
	focused = FALSE;
	switch (choice) {
		case PROTON_PLUS_UTILS_CONTROLLER_FOCUS_TARGET_CHOICE_REMEMBERED:
		{
			GtkWidget* _tmp31_;
			_tmp31_ = remembered;
			focused = gtk_widget_grab_focus (G_TYPE_CHECK_INSTANCE_CAST (_tmp31_, gtk_widget_get_type (), GtkWidget));
			break;
		}
		case PROTON_PLUS_UTILS_CONTROLLER_FOCUS_TARGET_CHOICE_INITIAL:
		{
			GtkWidget* _tmp32_;
			_tmp32_ = initial;
			focused = gtk_widget_grab_focus (G_TYPE_CHECK_INSTANCE_CAST (_tmp32_, gtk_widget_get_type (), GtkWidget));
			break;
		}
		case PROTON_PLUS_UTILS_CONTROLLER_FOCUS_TARGET_CHOICE_TRAVERSE:
		{
			GtkWidget* _tmp33_;
			_tmp33_ = page_root;
			focused = gtk_widget_child_focus (_tmp33_, GTK_DIR_TAB_FORWARD);
			break;
		}
		default:
		break;
	}
	if (focused) {
		proton_plus_utils_controller_manager_save_current_page_focus (self);
		proton_plus_utils_controller_manager_schedule_scroll_to_focus (self);
		proton_plus_utils_controller_manager_sync_highlight (self);
		proton_plus_utils_controller_manager_refresh_presentation (self);
	}
	result = G_SOURCE_REMOVE;
	_g_object_unref0 (initial);
	_g_object_unref0 (remembered);
	_g_object_unref0 (page_root);
	_g_object_unref0 (host);
	return result;
}

static gboolean
___lambda375__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda375_ (self);
	return result;
}

static void
proton_plus_utils_controller_manager_schedule_page_focus_restore_attempt (ProtonPlusUtilsControllerManager* self,
                                                                          ProtonPlusUtilsControllerFocusRestoreRequest* request,
                                                                          gint attempt,
                                                                          gboolean prefer_initial)
{
	Block78Data* _data78_;
	ProtonPlusUtilsControllerFocusRestoreRequest* _tmp0_;
	gint _tmp1_ = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (request != NULL);
	_data78_ = g_slice_new0 (Block78Data);
	_data78_->_ref_count_ = 1;
	_data78_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (request);
	_g_object_unref0 (_data78_->request);
	_data78_->request = _tmp0_;
	_data78_->attempt = attempt;
	_data78_->prefer_initial = prefer_initial;
	if (_data78_->attempt == 0) {
		_tmp1_ = 1;
	} else {
		_tmp1_ = 16;
	}
	self->priv->navigation_focus_source_id = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) _tmp1_, ___lambda375__gsource_func, block78_data_ref (_data78_), block78_data_unref);
	block78_data_unref (_data78_);
	_data78_ = NULL;
}

static void
proton_plus_utils_controller_manager_cancel_navigation_focus_restore (ProtonPlusUtilsControllerManager* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->navigation_focus_source_id != ((guint) 0)) {
		g_source_remove (self->priv->navigation_focus_source_id);
		self->priv->navigation_focus_source_id = (guint) 0;
	}
}

static void
proton_plus_utils_controller_manager_invalidate_navigation_deferred (ProtonPlusUtilsControllerManager* self)
{
	guint64 _tmp0_;
	ProtonPlusUtilsControllerNavigationPolicy* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->surface_generation;
	self->priv->surface_generation = _tmp0_ + 1;
	_tmp1_ = self->priv->navigation_policy;
	proton_plus_utils_controller_navigation_policy_invalidate_restores (_tmp1_);
	proton_plus_utils_controller_manager_cancel_navigation_focus_restore (self);
	proton_plus_utils_controller_manager_cancel_scroll_to_focus (self);
}

static Block79Data*
block79_data_ref (Block79Data* _data79_)
{
	g_atomic_int_inc (&_data79_->_ref_count_);
	return _data79_;
}

static void
block79_data_unref (void * _userdata_)
{
	Block79Data* _data79_;
	_data79_ = (Block79Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data79_->_ref_count_)) {
		ProtonPlusUtilsControllerManager* self;
		self = _data79_->self;
		_g_object_unref0 (_data79_->request);
		_g_object_unref0 (self);
		g_slice_free (Block79Data, _data79_);
	}
}

static gboolean
__lambda48_ (Block79Data* _data79_)
{
	ProtonPlusUtilsControllerManager* self;
	ProtonPlusUtilsControllerManagerGtkFocusScrollRequest* _tmp0_;
	gboolean result;
	self = _data79_->self;
	self->priv->scroll_focus_source_id = (guint) 0;
	_tmp0_ = _data79_->request;
	proton_plus_utils_controller_manager_reveal_focused_widget (self, _tmp0_);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda48__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda48_ (self);
	return result;
}

static void
proton_plus_utils_controller_manager_schedule_scroll_to_focus (ProtonPlusUtilsControllerManager* self)
{
	Block79Data* _data79_;
	gchar* page_id = NULL;
	GtkWidget* page_root = NULL;
	gchar* _tmp0_ = NULL;
	GtkWidget* _tmp1_ = NULL;
	GtkWidget* focused = NULL;
	GtkWidget* _tmp2_;
	gboolean _tmp3_ = FALSE;
	GtkWidget* _tmp4_;
	GtkWidget* _tmp7_;
	GtkWidget* _tmp8_;
	const gchar* _tmp9_;
	ProtonPlusUtilsControllerManagerGtkFocusScrollRequest* _tmp10_;
	g_return_if_fail (self != NULL);
	_data79_ = g_slice_new0 (Block79Data);
	_data79_->_ref_count_ = 1;
	_data79_->self = g_object_ref (self);
	proton_plus_utils_controller_manager_cancel_scroll_to_focus (self);
	proton_plus_utils_controller_manager_get_active_page_context (self, &_tmp0_, &_tmp1_);
	_g_free0 (page_id);
	page_id = _tmp0_;
	_g_object_unref0 (page_root);
	page_root = _tmp1_;
	_tmp2_ = proton_plus_utils_controller_manager_get_focused_widget (self);
	focused = _tmp2_;
	_tmp4_ = page_root;
	if (_tmp4_ == NULL) {
		_tmp3_ = TRUE;
	} else {
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		_tmp5_ = focused;
		_tmp6_ = page_root;
		_tmp3_ = !proton_plus_utils_controller_manager_is_valid_page_focus_target (self, _tmp5_, _tmp6_);
	}
	if (_tmp3_) {
		_g_object_unref0 (focused);
		_g_object_unref0 (page_root);
		_g_free0 (page_id);
		block79_data_unref (_data79_);
		_data79_ = NULL;
		return;
	}
	_tmp7_ = focused;
	_tmp8_ = page_root;
	_tmp9_ = page_id;
	_tmp10_ = proton_plus_utils_controller_manager_gtk_focus_scroll_request_new (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, gtk_widget_get_type (), GtkWidget), _tmp8_, _tmp9_, self->priv->surface_generation);
	_data79_->request = _tmp10_;
	self->priv->scroll_focus_source_id = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 16, ___lambda48__gsource_func, block79_data_ref (_data79_), block79_data_unref);
	_g_object_unref0 (focused);
	_g_object_unref0 (page_root);
	_g_free0 (page_id);
	block79_data_unref (_data79_);
	_data79_ = NULL;
}

static void
proton_plus_utils_controller_manager_cancel_scroll_to_focus (ProtonPlusUtilsControllerManager* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->scroll_focus_source_id != ((guint) 0)) {
		g_source_remove (self->priv->scroll_focus_source_id);
		self->priv->scroll_focus_source_id = (guint) 0;
	}
}

static void
proton_plus_utils_controller_manager_reveal_focused_widget (ProtonPlusUtilsControllerManager* self,
                                                            ProtonPlusUtilsControllerManagerGtkFocusScrollRequest* request)
{
	GtkWidget* widget = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* requested_root = NULL;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp3_;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp5_ = FALSE;
	GtkWidget* _tmp6_;
	gchar* active_page_id = NULL;
	GtkWidget* active_page_root = NULL;
	gchar* _tmp8_ = NULL;
	GtkWidget* _tmp9_ = NULL;
	gboolean _tmp10_ = FALSE;
	gboolean _tmp11_ = FALSE;
	GtkWidget* _tmp12_;
	GtkWidget* _tmp13_;
	GtkScrolledWindow* scrolled = NULL;
	GtkWidget* _tmp18_;
	GtkWidget* _tmp19_;
	GtkScrolledWindow* _tmp20_;
	GtkWidget* _tmp21_ = NULL;
	GtkScrolledWindow* _tmp22_;
	GtkWidget* content = NULL;
	GtkWidget* _tmp25_;
	gboolean _tmp26_ = FALSE;
	gboolean _tmp27_ = FALSE;
	gboolean _tmp28_ = FALSE;
	GtkScrolledWindow* _tmp29_;
	graphene_rect_t bounds = {0};
	GtkWidget* _tmp34_;
	GtkWidget* _tmp35_;
	graphene_rect_t _tmp36_ = {0};
	gboolean _tmp37_;
	GtkScrolledWindow* _tmp38_;
	GtkAdjustment* _tmp39_;
	graphene_rect_t _tmp40_;
	graphene_point_t _tmp41_;
	graphene_rect_t _tmp42_;
	graphene_point_t _tmp43_;
	graphene_rect_t _tmp44_;
	graphene_size_t _tmp45_;
	GtkScrolledWindow* _tmp46_;
	GtkAdjustment* _tmp47_;
	graphene_rect_t _tmp48_;
	graphene_point_t _tmp49_;
	graphene_rect_t _tmp50_;
	graphene_point_t _tmp51_;
	graphene_rect_t _tmp52_;
	graphene_size_t _tmp53_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (request != NULL);
	_tmp0_ = request->widget;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	widget = _tmp1_;
	_tmp2_ = request->page_root;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	requested_root = _tmp3_;
	_tmp6_ = widget;
	if (_tmp6_ == NULL) {
		_tmp5_ = TRUE;
	} else {
		GtkWidget* _tmp7_;
		_tmp7_ = requested_root;
		_tmp5_ = _tmp7_ == NULL;
	}
	if (_tmp5_) {
		_tmp4_ = TRUE;
	} else {
		_tmp4_ = request->surface_generation != self->priv->surface_generation;
	}
	if (_tmp4_) {
		_g_object_unref0 (requested_root);
		_g_object_unref0 (widget);
		return;
	}
	proton_plus_utils_controller_manager_get_active_page_context (self, &_tmp8_, &_tmp9_);
	_g_free0 (active_page_id);
	active_page_id = _tmp8_;
	_g_object_unref0 (active_page_root);
	active_page_root = _tmp9_;
	_tmp12_ = active_page_root;
	_tmp13_ = requested_root;
	if (_tmp12_ != _tmp13_) {
		_tmp11_ = TRUE;
	} else {
		const gchar* _tmp14_;
		const gchar* _tmp15_;
		_tmp14_ = active_page_id;
		_tmp15_ = request->page_id;
		_tmp11_ = g_strcmp0 (_tmp14_, _tmp15_) != 0;
	}
	if (_tmp11_) {
		_tmp10_ = TRUE;
	} else {
		GtkWidget* _tmp16_;
		GtkWidget* _tmp17_;
		_tmp16_ = widget;
		_tmp17_ = requested_root;
		_tmp10_ = !proton_plus_utils_controller_manager_is_valid_page_focus_target (self, _tmp16_, _tmp17_);
	}
	if (_tmp10_) {
		_g_object_unref0 (active_page_root);
		_g_free0 (active_page_id);
		_g_object_unref0 (requested_root);
		_g_object_unref0 (widget);
		return;
	}
	_tmp18_ = widget;
	_tmp19_ = requested_root;
	_tmp20_ = proton_plus_utils_controller_manager_find_nearest_scrolled_ancestor (self, _tmp18_, _tmp19_);
	scrolled = _tmp20_;
	_tmp22_ = scrolled;
	if (_tmp22_ == NULL) {
		_g_object_unref0 (_tmp21_);
		_tmp21_ = NULL;
	} else {
		GtkScrolledWindow* _tmp23_;
		GtkWidget* _tmp24_;
		_tmp23_ = scrolled;
		_tmp24_ = proton_plus_utils_controller_manager_get_scrolled_content (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp23_, gtk_scrolled_window_get_type (), GtkScrolledWindow));
		_g_object_unref0 (_tmp21_);
		_tmp21_ = _tmp24_;
	}
	_tmp25_ = _tmp21_;
	_tmp21_ = NULL;
	content = _tmp25_;
	_tmp29_ = scrolled;
	if (_tmp29_ == NULL) {
		_tmp28_ = TRUE;
	} else {
		GtkWidget* _tmp30_;
		_tmp30_ = content;
		_tmp28_ = _tmp30_ == NULL;
	}
	if (_tmp28_) {
		_tmp27_ = TRUE;
	} else {
		GtkScrolledWindow* _tmp31_;
		_tmp31_ = scrolled;
		_tmp27_ = !gtk_widget_get_mapped ((GtkWidget*) _tmp31_);
	}
	if (_tmp27_) {
		_tmp26_ = TRUE;
	} else {
		GtkScrolledWindow* _tmp32_;
		GtkWidget* _tmp33_;
		_tmp32_ = scrolled;
		_tmp33_ = requested_root;
		_tmp26_ = !proton_plus_utils_controller_manager_widget_is_descendant_of (self, (GtkWidget*) _tmp32_, _tmp33_);
	}
	if (_tmp26_) {
		_g_object_unref0 (content);
		_g_object_unref0 (_tmp21_);
		_g_object_unref0 (scrolled);
		_g_object_unref0 (active_page_root);
		_g_free0 (active_page_id);
		_g_object_unref0 (requested_root);
		_g_object_unref0 (widget);
		return;
	}
	_tmp34_ = widget;
	_tmp35_ = content;
	_tmp37_ = gtk_widget_compute_bounds (_tmp34_, _tmp35_, &_tmp36_);
	bounds = _tmp36_;
	if (!_tmp37_) {
		_g_object_unref0 (content);
		_g_object_unref0 (_tmp21_);
		_g_object_unref0 (scrolled);
		_g_object_unref0 (active_page_root);
		_g_free0 (active_page_id);
		_g_object_unref0 (requested_root);
		_g_object_unref0 (widget);
		return;
	}
	_tmp38_ = scrolled;
	_tmp39_ = gtk_scrolled_window_get_hadjustment (_tmp38_);
	_tmp40_ = bounds;
	_tmp41_ = _tmp40_.origin;
	_tmp42_ = bounds;
	_tmp43_ = _tmp42_.origin;
	_tmp44_ = bounds;
	_tmp45_ = _tmp44_.size;
	proton_plus_utils_controller_manager_reveal_adjustment (self, _tmp39_, (gdouble) _tmp41_.x, (gdouble) (_tmp43_.x + _tmp45_.width));
	_tmp46_ = scrolled;
	_tmp47_ = gtk_scrolled_window_get_vadjustment (_tmp46_);
	_tmp48_ = bounds;
	_tmp49_ = _tmp48_.origin;
	_tmp50_ = bounds;
	_tmp51_ = _tmp50_.origin;
	_tmp52_ = bounds;
	_tmp53_ = _tmp52_.size;
	proton_plus_utils_controller_manager_reveal_adjustment (self, _tmp47_, (gdouble) _tmp49_.y, (gdouble) (_tmp51_.y + _tmp53_.height));
	_g_object_unref0 (content);
	_g_object_unref0 (_tmp21_);
	_g_object_unref0 (scrolled);
	_g_object_unref0 (active_page_root);
	_g_free0 (active_page_id);
	_g_object_unref0 (requested_root);
	_g_object_unref0 (widget);
}

static GtkScrolledWindow*
proton_plus_utils_controller_manager_find_nearest_scrolled_ancestor (ProtonPlusUtilsControllerManager* self,
                                                                     GtkWidget* widget,
                                                                     GtkWidget* page_root)
{
	GtkWidget* current = NULL;
	GtkWidget* _tmp0_;
	GtkScrolledWindow* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (widget != NULL, NULL);
	g_return_val_if_fail (page_root != NULL, NULL);
	_tmp0_ = _g_object_ref0 (widget);
	current = _tmp0_;
	while (TRUE) {
		GtkWidget* _tmp1_;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		GtkWidget* _tmp7_;
		GtkWidget* _tmp8_;
		_tmp1_ = current;
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = current;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, gtk_scrolled_window_get_type ())) {
			GtkWidget* _tmp3_;
			GtkScrolledWindow* _tmp4_;
			_tmp3_ = current;
			_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, gtk_scrolled_window_get_type (), GtkScrolledWindow));
			result = _tmp4_;
			_g_object_unref0 (current);
			return result;
		}
		_tmp5_ = current;
		if (_tmp5_ == page_root) {
			break;
		}
		_tmp6_ = current;
		_tmp7_ = gtk_widget_get_parent (_tmp6_);
		_tmp8_ = _g_object_ref0 (_tmp7_);
		_g_object_unref0 (current);
		current = _tmp8_;
	}
	result = NULL;
	_g_object_unref0 (current);
	return result;
}

static GtkWidget*
proton_plus_utils_controller_manager_get_scrolled_content (ProtonPlusUtilsControllerManager* self,
                                                           GtkScrolledWindow* scrolled)
{
	GtkWidget* content = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp3_;
	GtkWidget* _tmp4_;
	GtkWidget* _tmp5_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (scrolled != NULL, NULL);
	_tmp0_ = gtk_scrolled_window_get_child (scrolled);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	content = _tmp1_;
	_tmp2_ = content;
	if (!G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, gtk_viewport_get_type ())) {
		result = NULL;
		_g_object_unref0 (content);
		return result;
	}
	_tmp3_ = content;
	_tmp4_ = gtk_viewport_get_child (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, gtk_viewport_get_type (), GtkViewport));
	_tmp5_ = _g_object_ref0 (_tmp4_);
	result = _tmp5_;
	_g_object_unref0 (content);
	return result;
}

static void
proton_plus_utils_controller_manager_reveal_adjustment (ProtonPlusUtilsControllerManager* self,
                                                        GtkAdjustment* adjustment,
                                                        gdouble start,
                                                        gdouble end)
{
	static const gdouble MARGIN = 12.0;
	gdouble visible_start = 0.0;
	gdouble _tmp0_;
	gdouble _tmp1_;
	gdouble visible_end = 0.0;
	gdouble _tmp2_;
	gdouble _tmp3_;
	gdouble target = 0.0;
	gdouble maximum = 0.0;
	gdouble _tmp6_;
	gdouble _tmp7_;
	gdouble _tmp8_;
	gdouble _tmp9_;
	gdouble _tmp10_;
	gdouble _tmp11_;
	gdouble _tmp14_;
	gdouble _tmp15_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (adjustment != NULL);
	_tmp0_ = gtk_adjustment_get_value (adjustment);
	_tmp1_ = _tmp0_;
	visible_start = _tmp1_;
	_tmp2_ = gtk_adjustment_get_page_size (adjustment);
	_tmp3_ = _tmp2_;
	visible_end = visible_start + _tmp3_;
	target = visible_start;
	if ((start - MARGIN) < visible_start) {
		target = start - MARGIN;
	} else {
		if ((end + MARGIN) > visible_end) {
			gdouble _tmp4_;
			gdouble _tmp5_;
			_tmp4_ = gtk_adjustment_get_page_size (adjustment);
			_tmp5_ = _tmp4_;
			target = (end + MARGIN) - _tmp5_;
		} else {
			return;
		}
	}
	_tmp6_ = gtk_adjustment_get_upper (adjustment);
	_tmp7_ = _tmp6_;
	_tmp8_ = gtk_adjustment_get_page_size (adjustment);
	_tmp9_ = _tmp8_;
	maximum = _tmp7_ - _tmp9_;
	_tmp10_ = gtk_adjustment_get_lower (adjustment);
	_tmp11_ = _tmp10_;
	if (maximum < _tmp11_) {
		gdouble _tmp12_;
		gdouble _tmp13_;
		_tmp12_ = gtk_adjustment_get_lower (adjustment);
		_tmp13_ = _tmp12_;
		maximum = _tmp13_;
	}
	_tmp14_ = gtk_adjustment_get_lower (adjustment);
	_tmp15_ = _tmp14_;
	if (target < _tmp15_) {
		gdouble _tmp16_;
		gdouble _tmp17_;
		_tmp16_ = gtk_adjustment_get_lower (adjustment);
		_tmp17_ = _tmp16_;
		target = _tmp17_;
	}
	if (target > maximum) {
		target = maximum;
	}
	gtk_adjustment_set_value (adjustment, target);
}

ProtonPlusUtilsControllerPresentationState*
proton_plus_utils_controller_manager_get_presentation_state (ProtonPlusUtilsControllerManager* self)
{
	ProtonPlusUtilsControllerPresentationState* result;
	ProtonPlusUtilsControllerPresentationState* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_presentation_state;
	result = _tmp0_;
	return result;
}

static void
proton_plus_utils_controller_manager_set_presentation_state (ProtonPlusUtilsControllerManager* self,
                                                             ProtonPlusUtilsControllerPresentationState* value)
{
	ProtonPlusUtilsControllerPresentationState* old_value;
	g_return_if_fail (self != NULL);
	old_value = proton_plus_utils_controller_manager_get_presentation_state (self);
	if (old_value != value) {
		ProtonPlusUtilsControllerPresentationState* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_presentation_state);
		self->priv->_presentation_state = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, proton_plus_utils_controller_manager_properties[PROTON_PLUS_UTILS_CONTROLLER_MANAGER_PRESENTATION_STATE_PROPERTY]);
	}
}

static ProtonPlusUtilsControllerManagerGamepadState*
proton_plus_utils_controller_manager_gamepad_state_construct (GType object_type,
                                                              SDL_JoystickID id,
                                                              SDL_Gamepad* gamepad)
{
	ProtonPlusUtilsControllerManagerGamepadState * self = NULL;
	g_return_val_if_fail (gamepad != NULL, NULL);
	self = (ProtonPlusUtilsControllerManagerGamepadState*) g_object_new (object_type, NULL);
	self->id = id;
	self->gamepad = gamepad;
	return self;
}

static ProtonPlusUtilsControllerManagerGamepadState*
proton_plus_utils_controller_manager_gamepad_state_new (SDL_JoystickID id,
                                                        SDL_Gamepad* gamepad)
{
	return proton_plus_utils_controller_manager_gamepad_state_construct (PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GAMEPAD_STATE, id, gamepad);
}

static void
proton_plus_utils_controller_manager_gamepad_state_class_init (ProtonPlusUtilsControllerManagerGamepadStateClass * klass,
                                                               gpointer klass_data)
{
	proton_plus_utils_controller_manager_gamepad_state_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = proton_plus_utils_controller_manager_gamepad_state_finalize;
}

static void
proton_plus_utils_controller_manager_gamepad_state_instance_init (ProtonPlusUtilsControllerManagerGamepadState * self,
                                                                  gpointer klass)
{
}

static void
proton_plus_utils_controller_manager_gamepad_state_finalize (GObject * obj)
{
	ProtonPlusUtilsControllerManagerGamepadState * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GAMEPAD_STATE, ProtonPlusUtilsControllerManagerGamepadState);
	G_OBJECT_CLASS (proton_plus_utils_controller_manager_gamepad_state_parent_class)->finalize (obj);
}

static GType
proton_plus_utils_controller_manager_gamepad_state_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusUtilsControllerManagerGamepadStateClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_utils_controller_manager_gamepad_state_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusUtilsControllerManagerGamepadState), 0, (GInstanceInitFunc) proton_plus_utils_controller_manager_gamepad_state_instance_init, NULL };
	GType proton_plus_utils_controller_manager_gamepad_state_type_id;
	proton_plus_utils_controller_manager_gamepad_state_type_id = g_type_register_static (G_TYPE_OBJECT, "ProtonPlusUtilsControllerManagerGamepadState", &g_define_type_info, 0);
	return proton_plus_utils_controller_manager_gamepad_state_type_id;
}

static GType
proton_plus_utils_controller_manager_gamepad_state_get_type (void)
{
	static volatile gsize proton_plus_utils_controller_manager_gamepad_state_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_utils_controller_manager_gamepad_state_type_id__once)) {
		GType proton_plus_utils_controller_manager_gamepad_state_type_id;
		proton_plus_utils_controller_manager_gamepad_state_type_id = proton_plus_utils_controller_manager_gamepad_state_get_type_once ();
		g_once_init_leave (&proton_plus_utils_controller_manager_gamepad_state_type_id__once, proton_plus_utils_controller_manager_gamepad_state_type_id);
	}
	return proton_plus_utils_controller_manager_gamepad_state_type_id__once;
}

static ProtonPlusUtilsControllerManagerGtkSurface*
proton_plus_utils_controller_manager_gtk_surface_construct (GType object_type,
                                                            ProtonPlusUtilsControllerSurfaceKind kind,
                                                            GtkWidget* widget,
                                                            GtkWidget* opener,
                                                            GtkWidget* initial_focus)
{
	ProtonPlusUtilsControllerManagerGtkSurface * self = NULL;
	g_return_val_if_fail (widget != NULL, NULL);
	self = (ProtonPlusUtilsControllerManagerGtkSurface*) proton_plus_utils_controller_surface_construct (object_type, kind);
	self->widget = widget;
	self->opener = opener;
	self->initial_focus = initial_focus;
	return self;
}

static ProtonPlusUtilsControllerManagerGtkSurface*
proton_plus_utils_controller_manager_gtk_surface_new (ProtonPlusUtilsControllerSurfaceKind kind,
                                                      GtkWidget* widget,
                                                      GtkWidget* opener,
                                                      GtkWidget* initial_focus)
{
	return proton_plus_utils_controller_manager_gtk_surface_construct (PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_SURFACE, kind, widget, opener, initial_focus);
}

static void
proton_plus_utils_controller_manager_gtk_surface_class_init (ProtonPlusUtilsControllerManagerGtkSurfaceClass * klass,
                                                             gpointer klass_data)
{
	proton_plus_utils_controller_manager_gtk_surface_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = proton_plus_utils_controller_manager_gtk_surface_finalize;
}

static void
proton_plus_utils_controller_manager_gtk_surface_instance_init (ProtonPlusUtilsControllerManagerGtkSurface * self,
                                                                gpointer klass)
{
	self->state_handler = (gulong) 0;
	self->destroy_handler = (gulong) 0;
}

static void
proton_plus_utils_controller_manager_gtk_surface_finalize (GObject * obj)
{
	ProtonPlusUtilsControllerManagerGtkSurface * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_SURFACE, ProtonPlusUtilsControllerManagerGtkSurface);
	G_OBJECT_CLASS (proton_plus_utils_controller_manager_gtk_surface_parent_class)->finalize (obj);
}

static GType
proton_plus_utils_controller_manager_gtk_surface_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusUtilsControllerManagerGtkSurfaceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_utils_controller_manager_gtk_surface_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusUtilsControllerManagerGtkSurface), 0, (GInstanceInitFunc) proton_plus_utils_controller_manager_gtk_surface_instance_init, NULL };
	GType proton_plus_utils_controller_manager_gtk_surface_type_id;
	proton_plus_utils_controller_manager_gtk_surface_type_id = g_type_register_static (PROTON_PLUS_UTILS_TYPE_CONTROLLER_SURFACE, "ProtonPlusUtilsControllerManagerGtkSurface", &g_define_type_info, 0);
	return proton_plus_utils_controller_manager_gtk_surface_type_id;
}

static GType
proton_plus_utils_controller_manager_gtk_surface_get_type (void)
{
	static volatile gsize proton_plus_utils_controller_manager_gtk_surface_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_utils_controller_manager_gtk_surface_type_id__once)) {
		GType proton_plus_utils_controller_manager_gtk_surface_type_id;
		proton_plus_utils_controller_manager_gtk_surface_type_id = proton_plus_utils_controller_manager_gtk_surface_get_type_once ();
		g_once_init_leave (&proton_plus_utils_controller_manager_gtk_surface_type_id__once, proton_plus_utils_controller_manager_gtk_surface_type_id);
	}
	return proton_plus_utils_controller_manager_gtk_surface_type_id__once;
}

static ProtonPlusUtilsControllerManagerGtkFocusScrollRequest*
proton_plus_utils_controller_manager_gtk_focus_scroll_request_construct (GType object_type,
                                                                         GtkWidget* widget,
                                                                         GtkWidget* page_root,
                                                                         const gchar* page_id,
                                                                         guint64 surface_generation)
{
	ProtonPlusUtilsControllerManagerGtkFocusScrollRequest * self = NULL;
	gchar* _tmp0_;
	g_return_val_if_fail (widget != NULL, NULL);
	g_return_val_if_fail (page_root != NULL, NULL);
	g_return_val_if_fail (page_id != NULL, NULL);
	self = (ProtonPlusUtilsControllerManagerGtkFocusScrollRequest*) g_object_new (object_type, NULL);
	self->widget = widget;
	self->page_root = page_root;
	_tmp0_ = g_strdup (page_id);
	_g_free0 (self->page_id);
	self->page_id = _tmp0_;
	self->surface_generation = surface_generation;
	return self;
}

static ProtonPlusUtilsControllerManagerGtkFocusScrollRequest*
proton_plus_utils_controller_manager_gtk_focus_scroll_request_new (GtkWidget* widget,
                                                                   GtkWidget* page_root,
                                                                   const gchar* page_id,
                                                                   guint64 surface_generation)
{
	return proton_plus_utils_controller_manager_gtk_focus_scroll_request_construct (PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_FOCUS_SCROLL_REQUEST, widget, page_root, page_id, surface_generation);
}

static void
proton_plus_utils_controller_manager_gtk_focus_scroll_request_class_init (ProtonPlusUtilsControllerManagerGtkFocusScrollRequestClass * klass,
                                                                          gpointer klass_data)
{
	proton_plus_utils_controller_manager_gtk_focus_scroll_request_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = proton_plus_utils_controller_manager_gtk_focus_scroll_request_finalize;
}

static void
proton_plus_utils_controller_manager_gtk_focus_scroll_request_instance_init (ProtonPlusUtilsControllerManagerGtkFocusScrollRequest * self,
                                                                             gpointer klass)
{
}

static void
proton_plus_utils_controller_manager_gtk_focus_scroll_request_finalize (GObject * obj)
{
	ProtonPlusUtilsControllerManagerGtkFocusScrollRequest * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_FOCUS_SCROLL_REQUEST, ProtonPlusUtilsControllerManagerGtkFocusScrollRequest);
	_g_free0 (self->page_id);
	G_OBJECT_CLASS (proton_plus_utils_controller_manager_gtk_focus_scroll_request_parent_class)->finalize (obj);
}

static GType
proton_plus_utils_controller_manager_gtk_focus_scroll_request_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusUtilsControllerManagerGtkFocusScrollRequestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_utils_controller_manager_gtk_focus_scroll_request_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusUtilsControllerManagerGtkFocusScrollRequest), 0, (GInstanceInitFunc) proton_plus_utils_controller_manager_gtk_focus_scroll_request_instance_init, NULL };
	GType proton_plus_utils_controller_manager_gtk_focus_scroll_request_type_id;
	proton_plus_utils_controller_manager_gtk_focus_scroll_request_type_id = g_type_register_static (G_TYPE_OBJECT, "ProtonPlusUtilsControllerManagerGtkFocusScrollRequest", &g_define_type_info, 0);
	return proton_plus_utils_controller_manager_gtk_focus_scroll_request_type_id;
}

static GType
proton_plus_utils_controller_manager_gtk_focus_scroll_request_get_type (void)
{
	static volatile gsize proton_plus_utils_controller_manager_gtk_focus_scroll_request_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_utils_controller_manager_gtk_focus_scroll_request_type_id__once)) {
		GType proton_plus_utils_controller_manager_gtk_focus_scroll_request_type_id;
		proton_plus_utils_controller_manager_gtk_focus_scroll_request_type_id = proton_plus_utils_controller_manager_gtk_focus_scroll_request_get_type_once ();
		g_once_init_leave (&proton_plus_utils_controller_manager_gtk_focus_scroll_request_type_id__once, proton_plus_utils_controller_manager_gtk_focus_scroll_request_type_id);
	}
	return proton_plus_utils_controller_manager_gtk_focus_scroll_request_type_id__once;
}

static void
proton_plus_utils_controller_manager_class_init (ProtonPlusUtilsControllerManagerClass * klass,
                                                 gpointer klass_data)
{
	proton_plus_utils_controller_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ProtonPlusUtilsControllerManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_proton_plus_utils_controller_manager_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_proton_plus_utils_controller_manager_set_property;
	G_OBJECT_CLASS (klass)->finalize = proton_plus_utils_controller_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PROTON_PLUS_UTILS_CONTROLLER_MANAGER_PRESENTATION_STATE_PROPERTY, proton_plus_utils_controller_manager_properties[PROTON_PLUS_UTILS_CONTROLLER_MANAGER_PRESENTATION_STATE_PROPERTY] = g_param_spec_object ("presentation-state", "presentation-state", "presentation-state", PROTON_PLUS_UTILS_TYPE_CONTROLLER_PRESENTATION_STATE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	proton_plus_utils_controller_manager_signals[PROTON_PLUS_UTILS_CONTROLLER_MANAGER_PRESENTATION_CHANGED_SIGNAL] = g_signal_new ("presentation-changed", PROTON_PLUS_UTILS_TYPE_CONTROLLER_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, PROTON_PLUS_UTILS_TYPE_CONTROLLER_PRESENTATION_STATE);
}

static void
proton_plus_utils_controller_manager_instance_init (ProtonPlusUtilsControllerManager * self,
                                                    gpointer klass)
{
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	ProtonPlusUtilsControllerInputPolicy* _tmp2_;
	ProtonPlusUtilsControllerNavigationPolicy* _tmp3_;
	ProtonPlusUtilsSdlControllerHapticSink* _tmp4_;
	self->priv = proton_plus_utils_controller_manager_get_instance_private (self);
	self->priv->timeout_id = (guint) 0;
	self->priv->repeat_timeout_id = (guint) 0;
	self->priv->sdl_initialized = FALSE;
	self->priv->controller_active = FALSE;
	self->priv->highlighted = NULL;
	self->priv->motion = NULL;
	self->priv->press = NULL;
	self->priv->keys = NULL;
	self->priv->input_controllers_attached = FALSE;
	self->priv->window_active_handler = (gulong) 0;
	self->priv->window_focus_handler = (gulong) 0;
	self->priv->confirm_button_changed_handler = (gulong) 0;
	self->priv->haptics_enabled_changed_handler = (gulong) 0;
	self->priv->highlight_visible_handler = (gulong) 0;
	self->priv->highlight_unmap_handler = (gulong) 0;
	self->priv->highlight_destroy_handler = (gulong) 0;
	self->priv->focus_idle_id = (guint) 0;
	self->priv->window_inactive_timeout_id = (guint) 0;
	_tmp0_ = gee_array_list_new (PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GAMEPAD_STATE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->gamepads = _tmp0_;
	_tmp1_ = gee_array_list_new (PROTON_PLUS_UTILS_CONTROLLER_MANAGER_TYPE_GTK_SURFACE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->registered_surfaces = _tmp1_;
	_tmp2_ = proton_plus_utils_controller_input_policy_new ();
	self->priv->input_policy = _tmp2_;
	_tmp3_ = proton_plus_utils_controller_navigation_policy_new ();
	self->priv->navigation_policy = _tmp3_;
	_tmp4_ = proton_plus_utils_sdl_controller_haptic_sink_new ();
	self->priv->haptic_sink = _tmp4_;
	self->priv->surface_generation = (guint64) 0;
	self->priv->navigation_focus_source_id = (guint) 0;
	self->priv->scroll_focus_source_id = (guint) 0;
	self->priv->presentation_range = NULL;
	self->priv->presentation_range_orientation_handler = (gulong) 0;
}

static void
proton_plus_utils_controller_manager_finalize (GObject * obj)
{
	ProtonPlusUtilsControllerManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_UTILS_TYPE_CONTROLLER_MANAGER, ProtonPlusUtilsControllerManager);
	_g_object_unref0 (self->priv->window);
	_g_object_unref0 (self->priv->motion);
	_g_object_unref0 (self->priv->press);
	_g_object_unref0 (self->priv->keys);
	_g_object_unref0 (self->priv->gamepads);
	_g_object_unref0 (self->priv->registered_surfaces);
	_g_object_unref0 (self->priv->window_surface);
	_g_object_unref0 (self->priv->surface_policy);
	_g_object_unref0 (self->priv->input_policy);
	_g_object_unref0 (self->priv->navigation_policy);
	_g_object_unref0 (self->priv->haptic_sink);
	_g_object_unref0 (self->priv->haptic_feedback);
	_g_object_unref0 (self->priv->_presentation_state);
	G_OBJECT_CLASS (proton_plus_utils_controller_manager_parent_class)->finalize (obj);
}

static GType
proton_plus_utils_controller_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusUtilsControllerManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_utils_controller_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusUtilsControllerManager), 0, (GInstanceInitFunc) proton_plus_utils_controller_manager_instance_init, NULL };
	GType proton_plus_utils_controller_manager_type_id;
	proton_plus_utils_controller_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "ProtonPlusUtilsControllerManager", &g_define_type_info, 0);
	ProtonPlusUtilsControllerManager_private_offset = g_type_add_instance_private (proton_plus_utils_controller_manager_type_id, sizeof (ProtonPlusUtilsControllerManagerPrivate));
	return proton_plus_utils_controller_manager_type_id;
}

GType
proton_plus_utils_controller_manager_get_type (void)
{
	static volatile gsize proton_plus_utils_controller_manager_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_utils_controller_manager_type_id__once)) {
		GType proton_plus_utils_controller_manager_type_id;
		proton_plus_utils_controller_manager_type_id = proton_plus_utils_controller_manager_get_type_once ();
		g_once_init_leave (&proton_plus_utils_controller_manager_type_id__once, proton_plus_utils_controller_manager_type_id);
	}
	return proton_plus_utils_controller_manager_type_id__once;
}

static void
_vala_proton_plus_utils_controller_manager_get_property (GObject * object,
                                                         guint property_id,
                                                         GValue * value,
                                                         GParamSpec * pspec)
{
	ProtonPlusUtilsControllerManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PROTON_PLUS_UTILS_TYPE_CONTROLLER_MANAGER, ProtonPlusUtilsControllerManager);
	switch (property_id) {
		case PROTON_PLUS_UTILS_CONTROLLER_MANAGER_PRESENTATION_STATE_PROPERTY:
		g_value_set_object (value, proton_plus_utils_controller_manager_get_presentation_state (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_proton_plus_utils_controller_manager_set_property (GObject * object,
                                                         guint property_id,
                                                         const GValue * value,
                                                         GParamSpec * pspec)
{
	ProtonPlusUtilsControllerManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PROTON_PLUS_UTILS_TYPE_CONTROLLER_MANAGER, ProtonPlusUtilsControllerManager);
	switch (property_id) {
		case PROTON_PLUS_UTILS_CONTROLLER_MANAGER_PRESENTATION_STATE_PROPERTY:
		proton_plus_utils_controller_manager_set_presentation_state (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

