window call back linux(gdk)

Share your advanced PureBasic knowledge/code with the community.
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

window call back linux(gdk)

Post by idle »

Gets mousewheel scroll direction

Code: Select all

 ;GdkEventTypes
#GDK_NOTHING		= -1
#GDK_DELETE		= 0
#GDK_DESTROY		= 1
#GDK_EXPOSE		= 2
#GDK_MOTION_NOTIFY = 3
#GDK_BUTTON_PRESS = 4
#GDK_2BUTTON_PRESS = 5
#GDK_3BUTTON_PRESS = 6
#GDK_BUTTON_RELEASE = 7
#GDK_KEY_PRESS		= 8
#GDK_KEY_RELEASE = 9
#GDK_ENTER_NOTIFY = 10
#GDK_LEAVE_NOTIFY = 11
#GDK_FOCUS_CHANGE = 12
#GDK_CONFIGURE		= 13
#GDK_MAP		= 14
#GDK_UNMAP		= 15
#GDK_PROPERTY_NOTIFY = 16
#GDK_SELECTION_CLEAR = 17
#GDK_SELECTION_REQUEST = 18
#GDK_SELECTION_NOTIFY = 19
#GDK_PROXIMITY_IN = 20
#GDK_PROXIMITY_OUT = 21
#GDK_DRAG_ENTER        = 22
#GDK_DRAG_LEAVE        = 23
#GDK_DRAG_MOTION       = 24
#GDK_DRAG_STATUS       = 25
#GDK_DROP_START        = 26
#GDK_DROP_FINISHED     = 27
#GDK_CLIENT_EVENT = 28
#GDK_VISIBILITY_NOTIFY = 29
#GDK_NO_EXPOSE		= 30
#GDK_SCROLL            = 31
#GDK_WINDOW_STATE      = 32
#GDK_SETTING           = 33
#GDK_OWNER_CHANGE      = 34
#GDK_GRAB_BROKEN       = 35
#GDK_DAMAGE            = 36

CompilerIf Defined(GdkEvent,#PB_Structure)=#False
      Structure GdkEvent
        gdktype.l
        StructureUnion
          any.GdkEventAny
          expose.GdkEventExpose   
          no_expose.GdkEventNoExpose   
          visibility.GdkEventVisibility   
          motion.GdkEventMotion
          button.GdkEventButton
          scroll.GdkEventScroll
          key.GdkEventKey
          crossing.GdkEventCrossing
          focus_change.GdkEventFocus           
          configure.GdkEventConfigure       
          property.GdkEventProperty   
          selection.GdkEventSelection   
          proximity.GdkEventProximity
          client.GdkEventClient       
          dnd.GdkEventDND               
          window_state.GdkEventWindowState       
          setting.GdkEventSetting           
        EndStructureUnion
      EndStructure
 CompilerEndIf
 
 ImportC  "/usr/lib/libgdk-x11-2.0.a"
   gtk_main_do_event( *event.gdkEvent)
   gdk_event_handler_set (*func,*mdata,*notify);
 EndImport 
   
 Macro SetWindowCallback(EventHandler)
      gdk_event_handler_set (EventHandler,0,0);
 EndMacro  
 
 Macro ProcessPureBasicEvents()
   gtk_main_do_event(*event);
 EndMacro   
 ;Our call back function 
   
 ProcedureC MyWindowCallBack( *event.gdkEvent,*mdata);
   
  If *event\gdktype = #GDK_SCROLL 
     If  *event\scroll\state  = #GDK_SCROLL_UP
       Debug "UP"
    ElseIf    *event\scroll\state  =  #GDK_SCROLL_DOWN
       Debug "Down" 
     EndIf  
  EndIf 
  
  ;Pass control back to pb so it can get events 
  ProcessPureBasicEvents()
  
EndProcedure  
 
OpenWindow(0,0,0,200,300,"test",#PB_Window_SystemMenu)
SetWindowCallback(@MyWindowCallBack())
ButtonGadget(0,10,10,60,20,"quit")
Repeat 
  
    Event = WaitWindowEvent()
   Select Event
        Case #PB_Event_Gadget
           Select EventGadget()
              Case  0 
                quit=1
           EndSelect     
   EndSelect 
  
Until  Event = #PB_Event_CloseWindow Or quit 


Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
bembulak
Enthusiast
Enthusiast
Posts: 575
Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria

Re: window call back linux(gdk)

Post by bembulak »

Interesting and useful!
Thanks a lot for sharing!
cheers,

bembulak
Post Reply