commit
d38382b99d
6 changed files with 2 additions and 177 deletions
@ -1,85 +0,0 @@ |
||||
#include "XInputUtils.h" |
||||
|
||||
#include <config-dev.h> |
||||
|
||||
#include <math.h> |
||||
|
||||
int XInputUtils::screenWidth = 0; |
||||
int XInputUtils::screenHeight = 0; |
||||
int XInputUtils::enableLeafEnterWorkaround = true; |
||||
|
||||
XInputUtils::XInputUtils() |
||||
{ |
||||
} |
||||
|
||||
XInputUtils::~XInputUtils() |
||||
{ |
||||
} |
||||
|
||||
void XInputUtils::initUtils(GtkWidget* win) |
||||
{ |
||||
GdkScreen* screen = gtk_widget_get_screen(win); |
||||
XInputUtils::screenWidth = gdk_screen_get_width(screen); |
||||
XInputUtils::screenHeight = gdk_screen_get_height(screen); |
||||
} |
||||
|
||||
void XInputUtils::setLeafEnterWorkaroundEnabled(bool enabled) |
||||
{ |
||||
if (XInputUtils::enableLeafEnterWorkaround == true && enabled == false) |
||||
{ |
||||
XInputUtils::onMouseEnterNotifyEvent(NULL, NULL); |
||||
} |
||||
|
||||
XInputUtils::enableLeafEnterWorkaround = enabled; |
||||
} |
||||
|
||||
#define EPSILON 1E-7 |
||||
|
||||
void XInputUtils::handleScrollEvent(GdkEventButton* event, GtkWidget* widget) |
||||
{ |
||||
GdkEvent scrollEvent; |
||||
/* with GTK+ 2.17 and later, the entire widget hierarchy is xinput-aware,
|
||||
so the core button event gets discarded and the scroll event never |
||||
gets processed by the main window. This is arguably a GTK+ bug. |
||||
We work around it. */ |
||||
|
||||
scrollEvent.scroll.type = GDK_SCROLL; |
||||
scrollEvent.scroll.window = event->window; |
||||
scrollEvent.scroll.send_event = event->send_event; |
||||
scrollEvent.scroll.time = event->time; |
||||
scrollEvent.scroll.x = event->x; |
||||
scrollEvent.scroll.y = event->y; |
||||
scrollEvent.scroll.state = event->state; |
||||
scrollEvent.scroll.device = event->device; |
||||
scrollEvent.scroll.x_root = event->x_root; |
||||
scrollEvent.scroll.y_root = event->y_root; |
||||
if (event->button == 4) |
||||
{ |
||||
scrollEvent.scroll.direction = GDK_SCROLL_UP; |
||||
} |
||||
else if (event->button == 5) |
||||
{ |
||||
scrollEvent.scroll.direction = GDK_SCROLL_DOWN; |
||||
} |
||||
else if (event->button == 6) |
||||
{ |
||||
scrollEvent.scroll.direction = GDK_SCROLL_LEFT; |
||||
} |
||||
else |
||||
{ |
||||
scrollEvent.scroll.direction = GDK_SCROLL_RIGHT; |
||||
} |
||||
gtk_widget_event(widget, &scrollEvent); |
||||
} |
||||
|
||||
// TODO Remove
|
||||
gboolean XInputUtils::onMouseEnterNotifyEvent(GtkWidget* widget, GdkEventCrossing* event) |
||||
{ |
||||
return FALSE; |
||||
} |
||||
|
||||
// TODO Remove
|
||||
gboolean XInputUtils::onMouseLeaveNotifyEvent(GtkWidget* widget, GdkEventCrossing* event) |
||||
{ |
||||
return FALSE; |
||||
} |
||||
@ -1,51 +0,0 @@ |
||||
/*
|
||||
* Xournal++ |
||||
* |
||||
* XInput util functions |
||||
* |
||||
* @author Xournal++ Team |
||||
* https://github.com/xournalpp/xournalpp
|
||||
* |
||||
* @license GNU GPLv2 or later |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <config-debug.h> |
||||
|
||||
#include <gtk/gtk.h> |
||||
|
||||
#ifdef DEBUG_INPUT |
||||
#define INPUTDBG(msg, ...) printf("INPUT:: " msg, __VA_ARGS__); printf(" on %s:%i\n", __FILE__, __LINE__) |
||||
#define INPUTDBG2(msg) printf("INPUT:: " msg " on %s:%i\n", __FILE__, __LINE__) |
||||
#else |
||||
#define INPUTDBG(msg, ...) |
||||
#define INPUTDBG2(msg) |
||||
#endif |
||||
|
||||
class XInputUtils |
||||
{ |
||||
private: |
||||
XInputUtils(); |
||||
virtual ~XInputUtils(); |
||||
|
||||
public: |
||||
static void handleScrollEvent(GdkEventButton* event, GtkWidget* widget); |
||||
|
||||
/**
|
||||
* Avoid crash if e.g. a mouse is plugged out... |
||||
*/ |
||||
static gboolean onMouseEnterNotifyEvent(GtkWidget* widget, GdkEventCrossing* event); |
||||
static gboolean onMouseLeaveNotifyEvent(GtkWidget* widget, GdkEventCrossing* event); |
||||
|
||||
static void initUtils(GtkWidget* win); |
||||
|
||||
static void setLeafEnterWorkaroundEnabled(bool enabled); |
||||
|
||||
private: |
||||
static int screenWidth; |
||||
static int screenHeight; |
||||
|
||||
static int enableLeafEnterWorkaround; |
||||
|
||||
}; |
||||
Loading…
Reference in new issue