Different event results on Linux and Windows.

Just starting out? Need help? Post your questions and find answers here.
jph
New User
New User
Posts: 7
Joined: Tue Jul 19, 2022 3:55 am

Different event results on Linux and Windows.

Post by jph »

Hello,

I'm trying to understand why, under Linux, when I click on an item in a ListView I get two results. One when I press the left mouse button and another when I release it. It doesn't on Windows where I only get one result. Can anyone tell me where it comes from?

Here is my code:

Code: Select all

Procedure MyEventGadget_ListView_selected_actions()
  
   Select EventType()
     Case #PB_EventType_LeftClick
       Result$ = GetGadgetText(#ListView_selected_actions)
       Result = GetGadgetState(#ListView_selected_actions)
       Debug Result$
       Debug Result
   EndSelect
  
EndProcedure
I get for example:

Gadget text
0
Gadget text
0

and under Windows only one
Gadget text
0
Thanks in advance.
User avatar
mk-soft
Always Here
Always Here
Posts: 6301
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Different event results on Linux and Windows.

Post by mk-soft »

The OS all work differently internally. This sometimes leads to different behaviour of the events that PB passes to you.
In Linux GtkTreeView signal "row-activated" is bound to the double-click by default.

PB-Help: ListViewGadget
The following events are supported through EventType():
#PB_EventType_LeftClick (also fired when the selection change)
#PB_EventType_LeftDoubleClick
#PB_EventType_RightClick
You can also bind your own signals for adaptation.

Code: Select all

;-TOP

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  ; Linux signal callback
  ProcedureC signal_treeview_button_press_event_cb(*GtkWidget, *Event.GdkEventButton, user_data)
    Protected gadget
    If *Event\button = 1
      gadget = g_object_get_data_(*GtkWidget, "pb_id" ) - 1
      PostEvent(#PB_Event_Gadget, GetActiveWindow(), gadget, #PB_EventType_StatusChange)
    EndIf
  EndProcedure
CompilerEndIf

; ****

EnableExplicit

;- Constant
Enumeration Windows
  #Main
EndEnumeration

Enumeration Menus
  #Menu
EndEnumeration

Enumeration MenuItems
  #MenuExitApplication
EndEnumeration
  
Enumeration Gadgets
  #List
EndEnumeration

Enumeration Statusbar
  #Status
EndEnumeration

Enumeration Images
  
EndEnumeration

;- Global Variable
Global ExitApplication

;- Functions
Procedure UpdateWindow()
  
  Protected x, y, dx, dy, menu, status
  
  menu = MenuHeight()
  If IsStatusBar(#Status)
    status = StatusBarHeight(#Status)
  Else
    status = 0
  EndIf
  x = 0
  y = 0
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - menu - status
  ResizeGadget(#List, x, y, dx, dy)
  
EndProcedure

;- Main
Procedure Main()
  
  Protected event, dx, dy
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
  dx = 800
  dy = 600
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, dx, dy, "Main Window", #WinStyle)
    
    ; Menu
    CreateMenu(#Menu, WindowID(#Main))
    MenuTitle("File")
    MenuItem(#MenuExitApplication, "E&xit")
    ; Gadgets
    ListViewGadget(#List, 0, 0, dx, dy)
    
    ; Statusbar
    CreateStatusBar(#Status, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Init
    UpdateWindow()
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    ; Test
    Define i
    For i = 1 To 10
      AddGadgetItem(#List, -1, "Text Number " + i)
    Next
    
    CompilerIf #PB_Compiler_OS = #PB_OS_Linux
      ; Bind Linux Event
      g_signal_connect_(GadgetID(#List), "button-press-event", @signal_treeview_button_press_event_cb(), 0)
    CompilerEndIf
    
    ; Main Loop
    Repeat
      event = WaitWindowEvent()
      Select event
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                ExitApplication = #True
                
            CompilerEndIf
              
            Case #MenuExitApplication
              ExitApplication = #True
              
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #List
              Select EventType()
                Case #PB_EventType_LeftClick
                  Debug "LeftClick" + GetGadgetText(#List)
                  
                Case #PB_EventType_StatusChange
                  Debug "Signal: " + GetGadgetText(#List)
                  
              EndSelect
              
          EndSelect
          
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              ExitApplication = #True
              
          EndSelect
          
      EndSelect
      
    Until ExitApplication
    
  EndIf
  
EndProcedure : Main()

End
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
jph
New User
New User
Posts: 7
Joined: Tue Jul 19, 2022 3:55 am

Re: Different event results on Linux and Windows.

Post by jph »

I'm going to study your code and trying to understand it. Thank you very much.
User avatar
mk-soft
Always Here
Always Here
Posts: 6301
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Different event results on Linux and Windows.

Post by mk-soft »

I have a small extension if a row is below the mouse

Code: Select all

;-TOP

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  ; Linux signal callback
  ProcedureC signal_treeview_button_press_event_cb(*GtkTreeView, *Event.GdkEventButton, user_data)
    Protected r1, gadget
    If *Event\button = 1
      r1 = gtk_tree_view_get_path_at_pos_(*GtkTreeView , *Event\x, *Event\y, 0, 0, 0, 0)
      If r1
        gadget = g_object_get_data_(*GtkTreeView, "pb_id" ) - 1
        PostEvent(#PB_Event_Gadget, GetActiveWindow(), gadget, #PB_EventType_StatusChange)
      EndIf
    EndIf
  EndProcedure
CompilerEndIf

; ****

EnableExplicit

;- Constant
Enumeration Windows
  #Main
EndEnumeration

Enumeration Menus
  #Menu
EndEnumeration

Enumeration MenuItems
  #MenuExitApplication
EndEnumeration
  
Enumeration Gadgets
  #List
EndEnumeration

Enumeration Statusbar
  #Status
EndEnumeration

Enumeration Images
  
EndEnumeration

;- Global Variable
Global ExitApplication

;- Functions
Procedure UpdateWindow()
  
  Protected x, y, dx, dy, menu, status
  
  menu = MenuHeight()
  If IsStatusBar(#Status)
    status = StatusBarHeight(#Status)
  Else
    status = 0
  EndIf
  x = 0
  y = 0
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - menu - status
  ResizeGadget(#List, x, y, dx, dy)
  
EndProcedure

;- Main
Procedure Main()
  
  Protected event, dx, dy
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
  dx = 800
  dy = 600
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, dx, dy, "Main Window", #WinStyle)
    
    ; Menu
    CreateMenu(#Menu, WindowID(#Main))
    MenuTitle("File")
    MenuItem(#MenuExitApplication, "E&xit")
    ; Gadgets
    ListViewGadget(#List, 0, 0, dx, dy)
    
    ; Statusbar
    CreateStatusBar(#Status, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Init
    UpdateWindow()
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    ; Test
    Define i
    For i = 1 To 10
      AddGadgetItem(#List, -1, "Text Number " + i)
    Next
    
    CompilerIf #PB_Compiler_OS = #PB_OS_Linux
      ; Bind Linux Event
      g_signal_connect_(GadgetID(#List), "button-press-event", @signal_treeview_button_press_event_cb(), 0)
    CompilerEndIf
    
    ; Main Loop
    Repeat
      event = WaitWindowEvent()
      Select event
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                ExitApplication = #True
                
            CompilerEndIf
              
            Case #MenuExitApplication
              ExitApplication = #True
              
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #List
              Select EventType()
                Case #PB_EventType_LeftClick
                  ;Debug "LeftClick" + GetGadgetText(#List)
                  
                Case #PB_EventType_StatusChange
                  Debug "StatusChange: " + GetGadgetText(#List)
                  
              EndSelect
              
          EndSelect
          
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              ExitApplication = #True
              
          EndSelect
          
      EndSelect
      
    Until ExitApplication
    
  EndIf
  
EndProcedure : Main()

End
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply