Page 1 of 1
LeftButtonDown, LeftButtonUp, get separated controle.
Posted: Sat Jan 29, 2022 4:10 pm
by Joris
How can I get controle over these LeftButtonDown, LeftButtonUp, on as many different gadgets, under linux ?
I would like to get these events used separated.
Code: Select all
Procedure Event_Window_Main(EventID)
Select EventType(): ; (on a listview)
Case #PB_EventType_LeftClick : this gives two signals one Down and one Up
.....
EndProcedure
Repeat
EventID.i = WaitWindowEvent()
Select EventWindow()
Case Window_0 : Event_Window_Main(EventID)
Case Window_1 : Event_Window_Voice(EventID)
EndSelect
ForEver
P.s. Trying things to get there : ExamineMouse() gives a linker Error : id returned 1 exit status ???
Thanks
Re: LeftButtonDown, LeftButtonUp, get separated controle.
Posted: Sat Jan 29, 2022 6:19 pm
by mk-soft
No whole code to test
But I missed Select EventGadget()
Code: Select all
Procedure Event_Window_Main(EventID)
Select EventID
Case #PB_Event_Gadget
Select EventGadget()
Case Listview_0
Select EventType(): ; (on a listview)
Case #PB_EventType_LeftClick
;TODO
EndSelect
EndSelect
EndSelect
EndProcedure
Re: LeftButtonDown, LeftButtonUp, get separated controle.
Posted: Sat Jan 29, 2022 8:54 pm
by Shardik
Joris wrote: Sat Jan 29, 2022 4:10 pm
How can I get controle over these LeftButtonDown, LeftButtonUp, on as many different gadgets, under linux ?
The following example demonstrates how to detect a mouse button press or release in a StringGadget and in an EditorGadget. The mouse button action is displayed in a StatusBar. I have tested the example successfully on Linux Mint 19.3 'Tricia' x64 with Cinnamon and PB 5.73 x64.
Code: Select all
EnableExplicit
Enumeration
#StringGadget
#EditorGadget
EndEnumeration
Define ButtonAction.S
Define LastButtonAction.S
ProcedureC MouseButtonCallback(*Widget.GtkWidget, *Event.GdkEventKey, *UserData)
Shared ButtonAction.S
If *Event\type = #GDK_BUTTON_PRESS
ButtonAction = "button pressed"
ElseIf *Event\type = #GDK_BUTTON_RELEASE
ButtonAction = "button released"
EndIf
EndProcedure
OpenWindow(0, 100, 100, 300, 140, "Detect mouse button down & up")
StringGadget(#StringGadget, 10, 10, 280, 25, "")
EditorGadget(#EditorGadget, 10, 45, 280, 60)
g_signal_connect_(GadgetID(#StringGadget), "button_press_event",
@MouseButtonCallback(), 0)
g_signal_connect_(GadgetID(#StringGadget), "button_release_event",
@MouseButtonCallback(), 0)
g_signal_connect_(GadgetID(#EditorGadget), "button_press_event",
@MouseButtonCallback(), 0)
g_signal_connect_(GadgetID(#EditorGadget), "button_release_event",
@MouseButtonCallback(), 0)
CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
SetActiveGadget(#StringGadget)
Repeat
If ButtonAction <> LastButtonAction
StatusBarText(0, 0, "GagdetID " + Str(GetActiveGadget()) +
": " + ButtonAction, #PB_StatusBar_Center)
LastButtonAction = ButtonAction
EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: LeftButtonDown, LeftButtonUp, get separated controle.
Posted: Sun Jan 30, 2022 1:18 pm
by Shardik
This is another similar example which uses PostEvent() in the callback to generate a custom event for the main event loop. And the press and release event is connected in a For..Next loop for all Gadgets contained in "Enumeration Gadgets":
Code: Select all
EnableExplicit
Enumeration CustomEvents
#Event_MouseLeftButtonDown = #PB_Event_FirstCustomValue
#Event_MouseLeftButtonUp
EndEnumeration
Enumeration Gadgets
#StringGadget
#EditorGadget
EndEnumeration
Define GadgetCount.I = #PB_Compiler_EnumerationValue
Define i.I
ProcedureC MouseButtonCallback(*Widget.GtkWidget, *Event.GdkEventButton,
*UserData)
If *Event\type = #GDK_BUTTON_PRESS And *Event\button = 1
PostEvent(#Event_MouseLeftButtonDown)
ElseIf *Event\type = #GDK_BUTTON_RELEASE And *Event\button = 1
PostEvent(#Event_MouseLeftButtonUp)
EndIf
EndProcedure
OpenWindow(0, 100, 100, 300, 140, "Detect left mouse button down & up")
StringGadget(#StringGadget, 10, 10, 280, 25, "")
EditorGadget(#EditorGadget, 10, 45, 280, 60)
; ----- Connect press and release event to each gadget in "Enumeration Gadgets"
For i = 1 To GadgetCount
g_signal_connect_(GadgetID(i - 1), "button_press_event",
@MouseButtonCallback(), 0)
g_signal_connect_(GadgetID(i - 1), "button_release_event",
@MouseButtonCallback(), 0)
Next i
CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
SetActiveGadget(#StringGadget)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #Event_MouseLeftButtonDown
StatusBarText(0, 0, "GagdetID " + Str(GetActiveGadget()) +
": Left mouse button down", #PB_StatusBar_Center)
Case #Event_MouseLeftButtonUp
StatusBarText(0, 0, "GagdetID " + Str(GetActiveGadget()) +
": Left mouse button up", #PB_StatusBar_Center)
EndSelect
ForEver
Re: LeftButtonDown, LeftButtonUp, get separated controle.
Posted: Sun Jan 30, 2022 2:02 pm
by mk-soft
@Shardik,
Very nice
but you can the gadget number send with PostEvent, therefore get pb_id with
Code: Select all
gadget = g_object_get_data_(*Widget, "pb_id" ) - 1
@Joris
If you bind a signal with a ProcedureC callback, you must pay attention to the parameters number and type. Otherwise the entire Linux GUI may hang up.
Link:
https://docs.gtk.org/gtk3/
Update
Code: Select all
EnableExplicit
Enumeration CustomEvents
#Event_MouseLeftButtonDown = #PB_Event_FirstCustomValue
#Event_MouseLeftButtonUp
EndEnumeration
Enumeration Gadgets
#StringGadget
#EditorGadget
EndEnumeration
Define GadgetCount.I = #PB_Compiler_EnumerationValue
Define i.I
ProcedureC MouseButtonCallback(*Widget.GtkWidget, *Event.GdkEventButton, *UserData)
Protected gadget
gadget = g_object_get_data_(*Widget, "pb_id" ) - 1
If *Event\type = #GDK_BUTTON_PRESS And *Event\button = 1
PostEvent(#Event_MouseLeftButtonDown, GetActiveWindow(), gadget)
ElseIf *Event\type = #GDK_BUTTON_RELEASE And *Event\button = 1
PostEvent(#Event_MouseLeftButtonUp, GetActiveWindow(), gadget)
EndIf
EndProcedure
OpenWindow(0, 100, 100, 300, 140, "Detect left mouse button down & up")
StringGadget(#StringGadget, 10, 10, 280, 25, "")
EditorGadget(#EditorGadget, 10, 45, 280, 60)
; ----- Connect press and release event to each gadget in "Enumeration Gadgets"
For i = 1 To GadgetCount
g_signal_connect_(GadgetID(i - 1), "button_press_event",
@MouseButtonCallback(), 0)
g_signal_connect_(GadgetID(i - 1), "button_release_event",
@MouseButtonCallback(), 0)
Next i
CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
SetActiveGadget(#StringGadget)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #Event_MouseLeftButtonDown
StatusBarText(0, 0, "GagdetID " + Str(EventGadget()) +
": Left mouse button down", #PB_StatusBar_Center)
Case #Event_MouseLeftButtonUp
StatusBarText(0, 0, "GagdetID " + Str(EventGadget()) +
": Left mouse button up", #PB_StatusBar_Center)
EndSelect
ForEver
Re: LeftButtonDown, LeftButtonUp, get separated controle.
Posted: Mon Jan 31, 2022 10:43 am
by Joris
Shardik, mk-soft , that does the task.
I needed it on listview item selection, but that works too.
So nice made.
Thanks guys