Skip to content

Commit

Permalink
Added EvMouse.modifiers. Fix EvKey.modifiers.
Browse files Browse the repository at this point in the history
  • Loading branch information
frang75 committed Jan 23, 2024
1 parent 16bae6f commit 68a59be
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 95 deletions.
8 changes: 7 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@

* `popup_get_text()`. [Commit](https://github.com/frang75/nappgui_src/commit/8177e951cdb5a0d9670e7a499491d209a8dfbc9c).

* `modifiers` field in `EvMouse`.

### Fixed

* macOS Sonoma OSView clipping. [Commit](https://github.com/frang75/nappgui_src/commit/ac038f90e555f8751e4dab1889e0448b47c900ae). [Doc](https://developer.apple.com/documentation/macos-release-notes/appkit-release-notes-for-macos-14#NSView).

* Windows XP THEME issue. [Commit](https://github.com/frang75/nappgui_src/commit/7f4d10bbd53a26c3e6719c859ab585bb53d6888f).

* Compiler warning in `dlib_proc`. [Commit](https://github.com/frang75/nappgui_src/commit/357960f16e80b9ac72d06c9fb10c9b17fcc4b520).
* `modifiers` field in `EvKey` issue. [Issue](https://github.com/frang75/nappgui_src/issues/95).

### Build system

* Fix Multi-config install issue [Commit](https://github.com/frang75/nappgui_src/commit/5eb39e984bbebed023bc4846dc5e99e318ab89f8).

* Compiler warning in `dlib_proc`. [Commit](https://github.com/frang75/nappgui_src/commit/357960f16e80b9ac72d06c9fb10c9b17fcc4b520).

* GCC Warnings. [Commit](https://github.com/frang75/nappgui_src/commit/16bae6f9c0540e54282a30b1ead3bbf9604b0e7f).

## v1.4.0 - Dec 31, 2023 (r4772)

### Added
Expand Down
4 changes: 1 addition & 3 deletions demo/hello/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ struct _app_t

static void i_OnButton(App *app, Event *e)
{
String *msg = str_printf("Button click (%d)\n", app->clicks);
textview_writef(app->text, tc(msg));
str_destroy(&msg);
textview_printf(app->text, "Button click (%d)\n", app->clicks);
app->clicks += 1;
unref(e);
}
Expand Down
2 changes: 1 addition & 1 deletion prj/build.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4808
4832
1 change: 1 addition & 0 deletions src/draw2d/guictx.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ struct _evmouse_t
real32_t ly;
gui_mouse_t button;
uint32_t count;
uint32_t modifiers;
};

struct _evwheel_t
Expand Down
35 changes: 20 additions & 15 deletions src/osgui/gtk3/osgui_gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,12 @@ uint32_t _osgui_underline_gtk_text(const char_t *text, char_t *buff, const uint3

/*---------------------------------------------------------------------------*/

vkey_t _osgui_vkey(GdkEventKey *event, uint32_t *modifiers)
vkey_t _osgui_vkey(guint kval)
{
vkey_t key = ENUM_MAX(vkey_t);
uint32_t i, n = kNUM_VKEYS;
const guint *keys = kVIRTUAL_KEY;
guint kval = 0;
cassert_no_null(event);
kval = event->keyval;

/* Letter events as uppercase */
if (kval >= 97 && kval <= 122)
{
Expand Down Expand Up @@ -450,21 +448,28 @@ vkey_t _osgui_vkey(GdkEventKey *event, uint32_t *modifiers)
}
}

if (modifiers != NULL)
{
*modifiers = 0;
return key;
}

if (event->state & GDK_SHIFT_MASK)
*modifiers |= ekMKEY_SHIFT;
/*---------------------------------------------------------------------------*/

if (event->state & GDK_CONTROL_MASK)
*modifiers |= ekMKEY_CONTROL;
uint32_t _osgui_modifiers(const guint state)
{
uint32_t modifiers = 0;

if (event->state & GDK_MOD1_MASK)
*modifiers |= ekMKEY_ALT;
}
if (state & GDK_SHIFT_MASK)
modifiers |= ekMKEY_SHIFT;

return key;
if (state & GDK_CONTROL_MASK)
modifiers |= ekMKEY_CONTROL;

if (state & GDK_MOD1_MASK)
modifiers |= ekMKEY_ALT;

if (state & GDK_MOD4_MASK)
modifiers |= ekMKEY_COMMAND;

return modifiers;
}

/*---------------------------------------------------------------------------*/
Expand Down
4 changes: 3 additions & 1 deletion src/osgui/gtk3/osgui_gtk.inl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ void _osgui_default_cursor(GtkWidget *widget);

uint32_t _osgui_underline_gtk_text(const char_t *text, char_t *buff, const uint32_t size);

vkey_t _osgui_vkey(GdkEventKey *event, uint32_t *modifiers);
vkey_t _osgui_vkey(const guint keyval);

uint32_t _osgui_modifiers(const guint state);

extern const guint kVIRTUAL_KEY[];

Expand Down
14 changes: 12 additions & 2 deletions src/osgui/gtk3/oslistener.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ void _oslistener_redraw(OSControl *sender, EvDraw *params, ViewListeners *listen
void _oslistener_mouse_enter(OSControl *sender, GdkEventCrossing *event, const real32_t scroll_x, const real32_t scroll_y, ViewListeners *listeners)
{
cassert_no_null(listeners);
cassert_no_null(event);
if (listeners->OnEnter != NULL)
{
EvMouse params;
Expand All @@ -143,6 +144,7 @@ void _oslistener_mouse_enter(OSControl *sender, GdkEventCrossing *event, const r
params.y = params.ly + scroll_y;
params.button = ENUM_MAX(gui_mouse_t);
params.count = 0;
params.modifiers = _osgui_modifiers(event->state);
listener_event(listeners->OnEnter, ekGUI_EVENT_ENTER, sender, &params, NULL, OSControl, EvMouse, void);
}
}
Expand All @@ -163,6 +165,7 @@ void _oslistener_mouse_moved(OSControl *sender, GdkEventMotion *event, const rea
{
cassert_no_null(listeners);
cassert_no_null(sender);
cassert_no_null(event);
if (listeners->is_enabled == TRUE)
{
if (listeners->button != ENUM_MAX(gui_mouse_t))
Expand All @@ -176,6 +179,7 @@ void _oslistener_mouse_moved(OSControl *sender, GdkEventMotion *event, const rea
params.y = params.ly + scroll_y;
params.button = listeners->button;
params.count = 0;
params.modifiers = _osgui_modifiers(event->state);
listener_event(listeners->OnDrag, ekGUI_EVENT_DRAG, sender, &params, NULL, OSControl, EvMouse, void);
}
}
Expand All @@ -190,6 +194,7 @@ void _oslistener_mouse_moved(OSControl *sender, GdkEventMotion *event, const rea
params.y = params.ly + scroll_y;
params.button = ENUM_MAX(gui_mouse_t);
params.count = 0;
params.modifiers = _osgui_modifiers(event->state);
listener_event(listeners->OnMoved, ekGUI_EVENT_MOVED, sender, &params, NULL, OSControl, EvMouse, void);
}
}
Expand All @@ -201,6 +206,7 @@ void _oslistener_mouse_moved(OSControl *sender, GdkEventMotion *event, const rea
void _oslistener_mouse_down(OSControl *sender, GdkEventButton *event, const real32_t scroll_x, const real32_t scroll_y, ViewListeners *listeners)
{
cassert_no_null(listeners);
cassert_no_null(event);
if (listeners->is_enabled == TRUE)
{
switch (event->button)
Expand Down Expand Up @@ -228,6 +234,7 @@ void _oslistener_mouse_down(OSControl *sender, GdkEventButton *event, const real
params.y = params.ly + scroll_y;
params.button = listeners->button;
params.count = 0;
params.modifiers = _osgui_modifiers(event->state);
listener_event(listeners->OnDown, ekGUI_EVENT_DOWN, sender, &params, NULL, OSControl, EvMouse, void);
}
}
Expand All @@ -239,6 +246,7 @@ void _oslistener_mouse_up(OSControl *sender, GdkEventButton *event, const real32
{
cassert_no_null(listeners);
cassert_no_null(sender);
cassert_no_null(event);
if (listeners->is_enabled == TRUE && listeners->button != ENUM_MAX(gui_mouse_t))
{
if (listeners->OnUp != NULL)
Expand All @@ -250,6 +258,7 @@ void _oslistener_mouse_up(OSControl *sender, GdkEventButton *event, const real32
params.y = params.ly + scroll_y;
params.button = listeners->button;
params.count = 0;
params.modifiers = _osgui_modifiers(event->state);
listener_event(listeners->OnUp, ekGUI_EVENT_UP, sender, &params, NULL, OSControl, EvMouse, void);
}

Expand All @@ -261,6 +270,7 @@ void _oslistener_mouse_up(OSControl *sender, GdkEventButton *event, const real32
params.x = params.lx + scroll_x;
params.y = params.ly + scroll_y;
params.button = listeners->button;
params.modifiers = _osgui_modifiers(event->state);

switch (event->type)
{
Expand Down Expand Up @@ -314,8 +324,8 @@ static bool_t i_key_event(OSControl *sender, const uint32_t type, GdkEventKey *e
cassert_unref(sender->type == ekGUI_TYPE_CUSTOMVIEW, sender);
if (listener != NULL)
{
uint32_t modifiers = 0;
vkey_t key = _osgui_vkey(event, &modifiers);
vkey_t key = _osgui_vkey(event->keyval);
uint32_t modifiers = _osgui_modifiers(event->state);
if (key != ENUM_MAX(vkey_t))
{
EvKey params;
Expand Down
4 changes: 2 additions & 2 deletions src/osgui/gtk3/oswindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ static gboolean i_OnKeyPress(GtkWidget *widget, GdkEventKey *event, OSWindow *wi
/* Check hotkeys */
if (window->hotkeys != NULL)
{
uint32_t modifiers = 0;
vkey_t key = _osgui_vkey(event, &modifiers);
vkey_t key = _osgui_vkey(event->keyval);
uint32_t modifiers = _osgui_modifiers(event->state);
if (oswindow_hotkey_process(window, window->hotkeys, key, modifiers) == TRUE)
return TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/osgui/osx/osgui_osx.inl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern NSMutableParagraphStyle *kLEFT_PARAGRAPH_STYLE;
extern NSMutableParagraphStyle *kCENTER_PARAGRAPH_STYLE;
extern NSMutableParagraphStyle *kRIGHT_PARAGRAPH_STYLE;

vkey_t osgui_vkey(NSEvent *event);
vkey_t osgui_vkey(unsigned short keycode);

void osgui_modifier_flags(
NSUInteger flags,
Expand Down
46 changes: 30 additions & 16 deletions src/osgui/osx/osgui_osx.m
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,10 @@ void osgui_pre_initialize_imp(void)

/*---------------------------------------------------------------------------*/

vkey_t osgui_vkey(NSEvent *event)
vkey_t osgui_vkey(unsigned short keycode)
{
vkey_t vkey = ENUM_MAX(vkey_t);
unsigned short keycode = 0;
uint32_t i, n = sizeof(i_kVIRTUAL_KEY) / sizeof(unsigned short);
cassert_no_null(event);
keycode = [event keyCode];

for (i = 0; i < n; ++i)
{
Expand All @@ -278,19 +275,36 @@ vkey_t osgui_vkey(NSEvent *event)

/*---------------------------------------------------------------------------*/

/*
Review BITS v1 = mouse events, v2 = key events
? BIT for key
? BIT for left/right
? BIT for event source
*/
static __INLINE bool_t i_modif(NSUInteger flags, uint32_t v1, uint32_t v2)
{
if ((flags & v1) == v1)
return TRUE;
if ((flags & v2) == v2)
return TRUE;
return FALSE;
}

/*---------------------------------------------------------------------------*/

void osgui_modifier_flags(
NSUInteger flags,
bool_t *rshift, bool_t *rctrl, bool_t *rcommand, bool_t *ralt,
bool_t *lshift, bool_t *lctrl, bool_t *lcommand, bool_t *lalt)
{
*rshift = ((flags & 131332) == 131332) ? TRUE : FALSE;
*rctrl = ((flags & 270592) == 270592) ? TRUE : FALSE;
*rcommand = ((flags & 1048848) == 1048848) ? TRUE : FALSE;
*ralt = ((flags & 524608) == 524608) ? TRUE : FALSE;
*lshift = ((flags & 131330) == 131330) ? TRUE : FALSE;
*lctrl = ((flags & 262401) == 262401) ? TRUE : FALSE;
*lcommand = ((flags & 1048840) == 1048840) ? TRUE : FALSE;
*lalt = ((flags & 524576) == 524576) ? TRUE : FALSE;
*rshift = i_modif(flags, 131076, 131332);
*rctrl = i_modif(flags, 270336, 270592);
*rcommand = i_modif(flags, 1048592, 1048848);
*ralt = i_modif(flags, 524352, 524608);
*lshift = i_modif(flags, 131074, 131330);
*lctrl = i_modif(flags, 262145, 262401);
*lcommand = i_modif(flags, 1048584, 1048840);
*lalt = i_modif(flags, 524320, 524576);
}

/*---------------------------------------------------------------------------*/
Expand All @@ -301,13 +315,13 @@ uint32_t osgui_modifiers(NSUInteger flags)
bool_t rshift, rctrl, rcommand, ralt;
bool_t lshift, lctrl, lcommand, lalt;
osgui_modifier_flags(flags, &rshift, &rctrl, &rcommand, &ralt, &lshift, &lctrl, &lcommand, &lalt);
if (rshift | lshift)
if (rshift || lshift)
modifiers |= ekMKEY_SHIFT;
if (rctrl | lctrl)
if (rctrl || lctrl)
modifiers |= ekMKEY_CONTROL;
if (rcommand | lcommand)
if (rcommand || lcommand)
modifiers |= ekMKEY_COMMAND;
if (ralt | lalt)
if (ralt || lalt)
modifiers |= ekMKEY_ALT;
return modifiers;
}
Expand Down
Loading

0 comments on commit 68a59be

Please sign in to comment.