; Module/File: Window_ListOnScreenWTitle.pb ; Function: Get data from all windows on screen, w. size, XId, Monitor, desktop, title (needs wmctrl) - Linux gtk3 ; Author: Omi ; Date: Oct. 03, 2016 ; Version: 0.1 ; Target Compiler: PureBasic 5.22/5.31/5.4x ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- EnableExplicit ImportC "" gdk_screen_get_window_stack(*screen.GdkScreen) gdk_x11_window_get_desktop(*window) gdk_x11_window_get_xid(*window) EndImport ; Object constants #Win_Main = 0 Global.i gEvent, gEventWin, gQuit Structure SCREENWINDOWS gdkwindow.i xid.i title.s x.i y.i width.i height.i type.i decoration.i state.i monitor.i desktop.i EndStructure Global NewList ScreenWindowList.SCREENWINDOWS() Procedure WmCtrl_GetWinTitles() Protected.s ProgOutput, Line Protected.i I, O Protected.i ProgrammId = RunProgram("wmctrl", "-l", "", #PB_Program_Open | #PB_Program_Read) If ProgrammId While ProgramRunning(ProgrammId) If AvailableProgramOutput(ProgrammId) ProgOutput + ReadProgramString(ProgrammId) + #LF$ EndIf Wend CloseProgram(ProgrammId) While FindString(ProgOutput, " ") ProgOutput= ReplaceString(ProgOutput, " ", " ") Wend ClearList(ScreenWindowList()) For I= 1 To CountString(ProgOutput, #LF$) Line= StringField(ProgOutput, I, #LF$) AddElement(ScreenWindowList()) ScreenWindowList()\xid= Val("$"+ UCase(Mid(StringField(Line, 1, " "), 3))) For O= 4 To 13 ScreenWindowList()\title+ StringField(Line, O, " ")+ " " Next O Next I Else Debug "wmctrl must be installed !!!" Debug "install: sudo apt-get install wmctrl" EndIf EndProcedure Procedure Screen_GetWindowStack() Protected *gList0.GList = gdk_screen_get_window_stack(gdk_display_get_default_screen_(gdk_display_get_default_())) Protected *gList.GList = *gList0 Protected *window, *decorations Protected.i rect.GdkRectangle, xid If *gList Repeat *window= *glist\data gdk_window_get_frame_extents_(*window, @rect) gdk_window_get_decorations_(*window, @*decorations) xid= gdk_x11_window_get_xid(*window) ForEach ScreenWindowList() If ScreenWindowList()\xid = xid ScreenWindowList()\gdkwindow = *window ScreenWindowList()\x = rect\x ScreenWindowList()\y = rect\y ScreenWindowList()\width = rect\width ScreenWindowList()\height = rect\height ScreenWindowList()\type = gdk_window_get_window_type_(*window) ScreenWindowList()\decoration= *decorations ScreenWindowList()\state = gdk_window_get_state_(*window) ScreenWindowList()\monitor = gdk_screen_get_monitor_at_window_(gdk_screen_get_default_(), *window) ScreenWindowList()\desktop = gdk_x11_window_get_desktop(*window) Break EndIf Next ScreenWindowList() *gList= *gList\next g_object_unref_(*window) Until *gList = 0 EndIf g_list_free_(*gList0); free list EndProcedure Procedure ListWindowsOnScreen() ForEach ScreenWindowList() Debug "Window title: " + ScreenWindowList()\title Debug "XID : " + Str(ScreenWindowList()\xid) Debug "GdkWindow : " + Str(ScreenWindowList()\gdkwindow) Debug "outer-size : " + Str(ScreenWindowList()\x) + ", " + Str(ScreenWindowList()\y) + ", " + Str(ScreenWindowList()\width) + ", " + Str(ScreenWindowList()\height) Debug "type : " + Str(ScreenWindowList()\type)+ " (0=root, 1=toplevel, 2=child, 3=temp, 4=foreign, 5=offscreen)" Debug "decorations : " + Str(ScreenWindowList()\decoration)+ " (1=all, 2=border, 4=resize, 8=title, 16=menu, 32=min, 64=max)" Debug "state : " + Str(ScreenWindowList()\state)+ " (1=withdrawn, 2=iconified, 4=maxed, 8=sticky, 16=full, 32=above, 64=below, 128=focused, 256=tiled)" Debug "on monitor : " + Str(ScreenWindowList()\monitor) Debug "on desktop : " + Str(ScreenWindowList()\desktop)+ " (-1=all)" Debug " ---" Next ScreenWindowList() EndProcedure Procedure Create_WinMain() If OpenWindow(#Win_Main, 300, 200, 400, 100, "GdkWindow list w. titles", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) ButtonGadget(0, 5, 5, 390, 26, "List windows on screen w. titles & some infos ...") EndIf EndProcedure Create_WinMain() Repeat gEvent= WaitWindowEvent() gEventWin= EventWindow() If gEventWin = #Win_Main Select gEvent Case #PB_Event_CloseWindow gQuit= #True Case #PB_Event_Gadget If EventGadget() = 0 WmCtrl_GetWinTitles() Screen_GetWindowStack() ListWindowsOnScreen() EndIf EndSelect EndIf Until gQuit ; IDE Options = PureBasic 5.45 LTS (Linux - x86) ; CursorPosition = 3 ; Folding = - ; EnableUnicode ; EnableXP