Looking for custom switch control

Good afternoon (o;

Looking for an alternative switch control for a touchscreen application on Linux and stumbled upon the einhugur collection:

But those controls can’t be resized nor do they react on touch events at all…so totally useless for touchscreen applications.

Anyone knows of other control plugins?

OTOH I probably have to go the PyQt6 way with all those touchscreen problems on Linux…

You could ping @Björn_Eiríksson to inquire about Linux touch screen support.

Last time I checked Xojo has no touch events at all ?

If you check canvas then there are no touch events.

I think this is something that is missing in the core of Xojo’s controls more or less.

(there is still chance it might be possible to wire it though, am not 100% sure how it could be tested though without touch device ?)

How does touch differ from MouseDown?

4 Likes

You might try GraffitiSwitch, which is not only resizable but it is pure Xojo code so you can implement the touch events yourself if they don’t work out of the box.

There are several styles, this one is “Dark”:

2024-08-13_06-00-33

1 Like

you could subclass a canvas and see behavior context menu to enable own properties in the inspector if the control is used in a window.
mouse down event should be same as touch click.
in sub classed canvas you can define any event and raise this from mouse event.
OnOffSwitchTest.zip (2.2 MB)
grafik

1 Like

Subclassing Canvas is not going to help him if the problem is that Xojo does not deliver Touch events at all.

Canvas will just have same problem no touch event. It does not come as MouseDown.

Touch is different event on Linux.

And its somewhat complicated its split in 4 as far as I can see to be able to handle all sorts of magic I suppose.

So for simple touch handling you can get the following:

GDK_TOUCH_BEGIN
A new touch event sequence has just started. This event type was added in 3.4.

Value: 37
Available since: 3.0
GDK_TOUCH_UPDATE
A touch event sequence has been updated. This event type was added in 3.4.

Value: 38
Available since: 3.0
GDK_TOUCH_END
A touch event sequence has finished. This event type was added in 3.4.

Value: 39
Available since: 3.0
GDK_TOUCH_CANCEL
A touch event sequence has been canceled. This event type was added in 3.4.

Value: 40
Available since: 3.0

While for more complex touch handling you can use whole gesture system.

1 Like

no button click by touch work in linux?

Regular buttons work with touchscreen with the “pressed” event…

Tried a similar thing where I wanted an settings icon to popup a settings window…
even with the DesktopBevelButton class with the pressed event doesn’t trigger with touchscreen.

I assume Xojo put the the past years effort more into mobile apps…

Though I believe that Arm64 embedded systems with touchscreens would benefit much for HMI applications with Xojo…as Kivy isn’t that fancy anymore. This leaves only one choice then: PyQt6.

Like Richard says then regular ones will work since the OS Buttons implement the events.

But Xojo base controls such as Canvas and Plugin control do not implement them that is the issue at hand.

this inherited DesktopUIControl is somehow inconsistent at “linux” …

In attempt to research the problem then I updated Linux Bridge Plugin a bit so I could test.

This is how I launch the app:

My understanding is that you can set touch screen emulator like that to test

image

On Canvas Opening event I got

Sub Opening() Handles Opening
  using EinhugurLinuxBridgeGtk
  
  can = me
  
  var widget as GtkWidget = GtkWidget.FromIntegerPtr(Integer(me.Handle))
  
  widget.EventMask = (widget.EventMask or 4194304)  // Adding  GDK_TOUCH_MASK
  
  
  widget.SignalConnect(GtkWidget.signal_touch_event, addressof OnTouch, nil)
End Sub

And on the callback I got:

Private Shared Sub OnTouch(widget as Ptr, evnt as Ptr, user_data as Ptr)
  using EinhugurLinuxBridgeGtk
  
  var theEvent as GdkEvent = GdkEvent.FromIntegerPtr(Integer(evnt))
  
  select case theEvent.Type
  case GdkEventType.TOUCH_BEGIN
    Window1(can.Window).ListBox1.AddRow("Touch begin")
  case GdkEventType.TOUCH_UPDATE
    Window1(can.Window).ListBox1.AddRow("Touch update")
  case GdkEventType.TOUCH_END
    Window1(can.Window).ListBox1.AddRow("Touch end")
  case GdkEventType.TOUCH_CANCEL
    Window1(can.Window).ListBox1.AddRow("Touch cancel")
    
  case else
    MessageBox "Something else !!"
  end select
End Sub

Problem is I am not getting anything…and I dont know if its because I am doing something wrong or need to do something more or if this is incorrect way to do touch emulation ?

If anyone know then any info is apreciated.

I have many Xojo Windows apps which seem to treat treat touch events as MouseDown or Action. Buttons, Canvases, ContainerControls all work fine on Dell touch-screen PCs.

Usually Windows treats touch devices to Mouse events.

The issue above is Linux where the devices use specific touch event unless its device that intentionally just sends mouse events.

Yes, but you said “Last time I checked Xojo has no touch events at all?” without mentioning any platform, which is what I was responding to.

Because on Windows they are not “touch” events their Mouse events.

Win32 dont got Touch events but WinFx will have decent touch events. (But Xojo is Win32 for now)

1 Like

Ah, I see, thanks.

Good morning

Found this project for turning touch events into mouse events:

Problem is though that the mouse pointer is visible then…

Can I turn the mouse pointer completely off?

System.Cursors.Hide in the main window open event works on macOS, but not on Linux.

This is a nice slide switch which can be scaled to your needs:

https://thezaz.com/code/zirconswitch/

I ran across similar touch screen issues as I am working on a Rasp Pi5 project using a 7" Touch Screen. Check this thread " Pi Official 7” Touch Screen - some problems" for work around solutions.

I needed to add a driver and then after experimenting I made extensive use of DesktopLabel (Mouse Down returns true then Mouse UP to do whatever) and SubClass DesktopCanvas used for color changes.

Thanks to Pawel Soltysinski for sharing his experience and keyboard solution which I have modified several times for differnent keyboard needs. His solution actually presents some good ideas on how to implement touch screen on Rasp Pi and for that matter should work with comparable Linux platforms.