Show Pen Buttons in penpal
Build and Test / build-linux (push) Has been cancelled
Build and Test / build-wayland (push) Has been cancelled
Build and Test / build-wayland-arm64 (push) Has been cancelled
Build and Test / build-macos (push) Has been cancelled
Build and Test / build-windows (push) Has been cancelled
Build and Test / build-windows-arm (push) Has been cancelled

This commit is contained in:
Matthias Melcher
2026-06-20 16:09:12 +02:00
parent 7fcd548e02
commit 9be57bd14a
3 changed files with 23 additions and 5 deletions
@@ -552,8 +552,8 @@ static void tool_cb_button(void *data, struct zwp_tablet_tool_v2 *,
// Map physical button codes to State bits.
State bit = (State)0;
switch (button) {
case BTN_STYLUS: bit = State::BUTTON0; break;
case BTN_STYLUS2: bit = State::BUTTON1; break;
case BTN_STYLUS: bit = State::BUTTON1; break; // upper barell button
case BTN_STYLUS2: bit = State::BUTTON0; break; // lower barrel button, closer to the pen tip
case BTN_STYLUS3: bit = State::BUTTON2; break;
default: break;
}
@@ -50,6 +50,7 @@
#include <errno.h>
#include <string.h> // for strerror()
#include <map>
extern "C" {
bool libdecor_get_cursor_settings(char **theme, int *size);
bool fl_is_surface_from_GTK_titlebar (struct wl_surface *surface, struct libdecor_frame *frame,
+20 -3
View File
@@ -1,7 +1,7 @@
//
// Penpal pen/stylus/tablet test program for the Fast Light Tool Kit (FLTK).
//
// Copyright 2025 by Bill Spitzak and others.
// Copyright 2025-2026 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -63,6 +63,7 @@ public:
}
int cv_handle(int event);
void cv_draw();
void cv_draw_buttons();
void cv_paint();
void cv_pen_paint();
};
@@ -83,6 +84,8 @@ int CanvasInterface::cv_handle(int event)
/* fall through */
case Fl::Pen::HOVER:
// Pen move over the surface without touching it.
if (Fl::event_state(FL_CTRL) || Fl::Pen::event_state(Fl::Pen::State::BUTTON1))
return popup_app_menu();
overlay_ = PEN_HOVER;
ov_x_ = Fl::event_x();
ov_y_ = Fl::event_y();
@@ -90,8 +93,6 @@ int CanvasInterface::cv_handle(int event)
return 1;
case Fl::Pen::TOUCH:
// Pen tip or eraser just touched the surface.
if (Fl::event_state(FL_CTRL) || Fl::Pen::event_state(Fl::Pen::State::BUTTON0))
return popup_app_menu();
/* fall through */
case Fl::Pen::DRAW:
// Pen is dragged over the surface, or hovers with a button pressed.
@@ -177,6 +178,7 @@ void CanvasInterface::cv_draw()
case NONE: break;
case PEN_HOVER:
fl_color(FL_RED);
cv_draw_buttons();
/* fall through */
case HOVER:
fl_xyline(ov_x_-10, ov_y_, ov_x_+10);
@@ -194,6 +196,7 @@ void CanvasInterface::cv_draw()
fl_line(ov_x_-r, ov_y_-r, ov_x_+r, ov_y_+r);
fl_line(ov_x_-r, ov_y_+r, ov_x_+r, ov_y_-r);
}
cv_draw_buttons();
/* fall through */
case DRAW:
// Draw a circle at the mouse or pan position
@@ -202,6 +205,20 @@ void CanvasInterface::cv_draw()
}
}
void CanvasInterface::cv_draw_buttons()
{
// Button indicators
fl_rect(ov_x_-16, ov_y_-20, 32, 10);
if (Fl::Pen::event_state(Fl::Pen::State::BUTTON0))
fl_rectf(ov_x_-16, ov_y_-20, 8, 10);
if (Fl::Pen::event_state(Fl::Pen::State::BUTTON1))
fl_rectf(ov_x_-8, ov_y_-20, 8, 10);
if (Fl::Pen::event_state(Fl::Pen::State::BUTTON2))
fl_rectf(ov_x_-0, ov_y_-20, 8, 10);
if (Fl::Pen::event_state(Fl::Pen::State::BUTTON3))
fl_rectf(ov_x_+8, ov_y_-20, 8, 10);
}
//
// Paint a circle with mouse events.
//