Linux: Make an invisible xwindow visible - x11

When running (many many versions) of Zoom on arch linux, the annotation toolbar does not appear.
I am using Gnome.
I have submitted many bug reports, but I have a feeling the problem is very specific to my setup and I am trying to find a workaround.
Using the code below I have found a window with the promising name "annotate_toolbar".
How can I make it visible using python-xlib or any other tool?
from pprint import pprint
from Xlib import display
from Xlib.protocol.request import QueryTree
d = display.Display()
root = d.screen().root
query: QueryTree = root.query_tree()
for c in query.children: # type: display.Window
name = c.get_wm_name()
if name != "annotate_toolbar":
continue
print(c, name)
pprint(c.get_geometry()._data)
pprint(c.get_attributes()._data)
Output:
<class 'Xlib.display.Window'>(0x04401b09) annotate_toolbar
{'border_width': 0,
'depth': 32,
'height': 43,
'root': <<class 'Xlib.display.Window'> 0x00000174>,
'sequence_number': 129,
'width': 678,
'x': 621,
'y': 107}
{'all_event_masks': 6463615,
'backing_bit_planes': 4294967295,
'backing_pixel': 0,
'backing_store': 0,
'bit_gravity': 1,
'colormap': <<class 'Xlib.xobject.colormap.Colormap'> 0x04401b08>,
'do_not_propagate_mask': 0,
'map_is_installed': 0,
'map_state': 2,
'override_redirect': 1,
'save_under': 1,
'sequence_number': 130,
'visual': 173,
'win_class': 1,
'win_gravity': 1,
'your_event_mask': 0}

Unless you specifically want an Xlib programming solution, you could try xdotool on the command line.
I don't have or want Zoom on my box, so I can't test it directly but if I use Calculator as a stand-in:
xdotool search --name "Calculator" getwindowname windowactivate
brings up the Calculator, if it's running.
There are many other options available to you via xdotool, along with command chaining.
Usage: xdotool <cmd> <args>
Available commands:
getactivewindow
getwindowfocus
getwindowname
getwindowpid
getwindowgeometry
getdisplaygeometry
search
selectwindow
help
version
behave
behave_screen_edge
click
getmouselocation
key
keydown
keyup
mousedown
mousemove
mousemove_relative
mouseup
set_window
type
windowactivate
windowfocus
windowkill
windowclose
windowmap
windowminimize
windowmove
windowraise
windowreparent
windowsize
windowunmap
set_num_desktops
get_num_desktops
set_desktop
get_desktop
set_desktop_for_window
get_desktop_for_window
get_desktop_viewport
set_desktop_viewport
exec
sleep

Related

Ruby: TouchAction:move_to

I am trying to implement below move_to action
https://www.rubydoc.info/gems/appium_lib/9.3.8/Appium%2FTouchAction:move_to
Appium::TouchAction.new.press(x: 176, y: 200).move_to(50).perform
but it is giving error
NoMethodError:
undefined method `key?' for 100:Integer
I want to move/swipe screen on iOS Simulator from one co-ordinates to other co-ordinates.
The link you posted clearly states that move_to expects a hash with :x and :y as parameters, just like you passed to press.
Appium::TouchAction.new.press(x: 176, y: 200).move_to(x: 176, y: 200).perform
The syntax for TouchAction is as follows (in python):
touch = TouchAction(driver)
touch.press(x=473, y=1396).move_to(x=468, y=705).release().perform()
The syntax remains the same for ruby with paramenters for press and move_to class

How to create a KeyEvent for control characters un upercase Ctlr+A and lowercase Ctlr+a

I am developing a custom keyboard using xamarin form and I need to create KeyEvent on my custom renderer for the the Ctrl keys, however I could not find any documentation on how to do it.
I have tried different combination of constructor with the KeyEvent class with no success. For example:
webView.DispatchKeyEvent(new KeyEvent(0, 0, KeyEventActions.Down, KeyEvent.KeyCodeFromString(digit), 0, MetaKeyStates .ShiftLeftOn & MetaKeyStates.CtrlLeftOn));
webView.DispatchKeyEvent(new KeyEvent(0, 0, KeyEventActions.Up, KeyEvent.KeyCodeFromString(digit), 0, MetaKeyStates.ShiftLeftOn & MetaKeyStates.CtrlLeftOn));
I also tried the following for lowercase with no success
webView.DispatchKeyEvent(new KeyEvent(0, 0, KeyEventActions.Down, KeyEvent.KeyCodeFromString(digit), 0, MetaKeyStates.CtrlLeftOn));
webView.DispatchKeyEvent(new KeyEvent(0, 0, KeyEventActions.Up, KeyEvent.KeyCodeFromString(digit), 0, MetaKeyStates.CtrlLeftOn));
This does not provide the control character I am expecting like Ctrl+C or Ctrl+c. I am only getting the event for the actual character like c or C but not the control. I am using this code for a WebView and verifying the the output with JavaScript. The java script reports correctly the character pressed but not the Ctrl, even when checking the ctrlKey property of the javaScript event the flag is set to false.

How can I create a static title/border on a Python cmd line application

I'm using the Python cmd module to create a CLI application. Everything works great! However, I'm attempting to tailor the app to a certain type of presence: text colors, title, using alpha-numeric characters as borders, etc.
Is there a standard way to create a screen overrun of sorts: the top of the screen where I have set a border and color title remain static? And from the middle of the screen, or thereabouts, down to the bottom of the screen, any text or commands entered at the prompt will stop being visible as they reach the title/border. Basically, what I'm after is for a user to always see the title/border unless they exit the CLI app. If they type help, of course, they will see the commands below the title/border. But, as they enter commands, ideally, the command menu will disappear behind the screen title/border.
Any direction on the best way I can achieve this is appreciated.
Check curses
You should be able to decorate CLI/Terminal with colors and static borders.
I have extended example taken from HERE:
import curses
from multiprocessing import Process
p = None
def display(stdscr):
stdscr.clear()
stdscr.timeout(500)
maxy, maxx = stdscr.getmaxyx()
curses.newwin(2,maxx,3,1)
# invisible cursor
curses.curs_set(0)
if (curses.has_colors()):
# Start colors in curses
curses.start_color()
curses.use_default_colors()
curses.init_pair(1, curses.COLOR_RED, -1)
stdscr.refresh()
curses.init_pair(1, 0, -1)
curses.init_pair(2, 1, -1)
curses.init_pair(3, 2, -1)
curses.init_pair(4, 3, -1)
bottomBox = curses.newwin(8,maxx-2,maxy-8,1)
bottomBox.box()
bottomBox.addstr("BottomBox")
bottomBox.refresh()
bottomwindow = curses.newwin(6,maxx-4,maxy-7,2)
bottomwindow.addstr("This is my bottom view", curses.A_UNDERLINE)
bottomwindow.refresh()
stdscr.addstr("{:20s}".format("Hello world !"), curses.color_pair(4))
stdscr.refresh()
while True:
event = stdscr.getch()
if event == ord("q"):
break
def hang():
while True:
temp = 1 + 1
if __name__ == '__main__':
p = Process(target = hang)
curses.wrapper(display)

Canvas.scale output renders not always the same

I do a first simple tkinter tool. It connects via FTP to a server and uploads a file (it's for a restaurant's menucard to go on their server).
All this is working fine.
I'm trying to make an animation indicating the upload. And there is a problem.
The main-class inherits from Tk
inits menu, buttons and such, relevant: self.anim = Canvas(self, width=500, height=300) # Canvas for Animation
self.anim.grid(column=0, row=5)
eventually, when uploading it calls self.animation()
There I draw a little PC via create_... methods and then what should be the card, zooming out the screen and going up. Running I see like maybe 4 of 5 runs how it is supposed to show up (so far) but sometimes it looks like it renders that animations two times (second double in factor) and these are overlapping, zooming twice as big and going far out of intended stop...
That's not a good sign, same input, different output. Anyone can explain why this happens?
x0, y0, x1, y1 = (185, 100, 190, 110) # menucard
ix0, iy0, ix1, iy1 = (187, 102, 189, 104) # menucard's "image"
self.speisekarte = self.anim.create_rectangle(x0, y0, x1, y1, # menucard
outline='#bbb', fill='#fef',
stipple='gray75', tag='karte')
self.karteimg = self.anim.create_rectangle(ix0, iy0, ix1, iy1, # menucard's "image"
outline='#f77', fill='#f57',
stipple='gray50', tag='karte')
self.anim.create_line(185, 100, 185, 109, tag='karte')
self.anim.update()
for z in range(13):
self.anim.after(100, self.zoom())
for z in range(50):
self.anim.after(50, self.move())
self.anim.create_text(350, 50, text='O N L I N E !', fill='#f57')
def zoom(self):
self.anim.scale('karte', 185, 110, 1.09, 1.06)
self.anim.update()
def move(self):
self.anim.move('karte', 2, -1)
self.anim.update()
#furas helped me to my solution. From there I had to find a way to exit the function. I found nowwhere an example, so here how it works for me now:
def animdrawUpload(self):
while self.move():
pass
return True
def move(self):
if self.anim.coords('karte')[0] > 300:
return False
self.anim.move('karte', 2, -1)
self.anim.update()
self.anim.after(100, self.move)
return True
Eventually I just have to hope I will get the same result on windows10 ;)

AutoIt Wait until browser window is visible not working as expected

Consider that I have the handle ($browser_handle) of a web browser window ('firefox') available in my AutoIt script.
I would like perform some keystrokes after I know that the firefox browser window is open and visible on my display so that I can bring it to focus using -
WinActivate($browser_handle)
or
WinWaitActive($browser_handle)
To make sure that the window is visible before I try to bring it into focus I have a while loop which waits till the state of the window handle is visible (2).
While (Not BitAND(WinGetState($browser_handle), 2)) WEnd //until window visible
If I use a Sleep(5000) function before the while loop then I do not face any issues.
If I do not use an arbitrary Sleep function in my script, the Whileloop condition never becomes true and turns into an infinite loop.
When I tried to check what the return value of WinGetState($browser_handle) is when there is no Sleep function,
It remains 5 even if the browser is visible and becomes 0 after the browser window is closed.
I'm unable to understand why the WinGetStatereturn value never becomes 2(visible) even if the browser is visible when there is no Sleep function.
This is a test code which can reproduce the issue -
#include <Constants.au3>
Local $browser_name = 'C:\Program Files (x86)\Internet Explorer\iexplore.exe'
Run($browser_name)
ProcessWait('iexplore.exe')
Local $browsers = ProcessList('iexplore.exe')
Local $pid = $browsers[1][1];
_WinActiveByPID($pid)
Local $sText = WinGetTitle("[ACTIVE]")
; Display the window title.
MsgBox($MB_SYSTEMMODAL, "", $sText)
Func _WinActiveByPID($pid) ;False to WinActivate, True to just see if it's active
Local $aWL = WinList()
For $iCC = 1 To $aWL[0][0]
If ($aWL[$iCC][0] <> '') And _
(WinGetProcess($aWL[$iCC][1]) = $pid) Then
While (Not BitAND(WinGetState($aWL[$iCC][1]), 2))
MsgBox($MB_SYSTEMMODAL, "", WinGetState($aWL[$iCC][1]))
WEnd
WinWait($aWL[$iCC][1])
WinActivate($aWL[$iCC][1])
WinWaitActive($aWL[$iCC][1])
Return 1
EndIf
Next
Return SetError(2, 0, 0)
EndFunc
Note:
WinWait does not work in this situation, If you see the example in the link there is a Sleep after WinWait, this function returns even if the window is hidden.
The browser window in my original script is not launched using Run, it is a Java program which opens the browser. I know that the Run method returns the PID of the browser which I can use to resolve this issue but since it starts from Java I have to use ProcessList to obtain the PID of the browser.
Please let me know how I can get this to work.
Thanks
You got thing too complicated for no reason there. Let me show you.
Local $browser_name = 'C:\Program Files (x86)\Internet Explorer\iexplore.exe'
Run($browser_name)
ProcessWait('iexplore.exe')
Sleep(500) ; because ProcessWait will exit when the process is created not when the window is visible. If your computer is slow you will have an problem
Local $BrowsersHWND = WinList()
Local $hBrowserHandle[2]
For $i = 0 To $BrowsersHWND[0][0] -1
If StringInStr($BrowsersHWND[$i][0], "Internet Explorer") Then
$hBrowserHandle[0] = $BrowsersHWND[$i][0] ;title
$hBrowserHandle[1] = $BrowsersHWND[$i][1] ;handle
ExitLoop
EndIf
Next
If $hBrowserHandle[0] = "" Or $hBrowserHandle[1] = "" Then Exit MsgBox(0, 0, "Internet Explorer not found")
Local $hState = WinGetState($hBrowserHandle[0])
Local $sVisibleStates[24] = [2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 34, 35, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47] ;visible states
Local $hCheck = False
For $j = 0 To UBound($sVisibleStates) -1
If $hState = $sVisibleStates[$j] Then
ConsoleWrite("Window state(visisble): " & $hState & #LF)
$hCheck = True
ExitLoop
EndIf
Next
If $hCheck = False Then
ConsoleWrite("Activating: " & $hBrowserHandle[0] & #LF)
WinActivate($hBrowserHandle[0])
EndIf
I have added all the cases of states where your window would be visible.
WinWait will not activate any window and I recommend you never use it. It could freeze a script for ever without reason. I will not explain why because it would take pages but avoid it. Also avoid using WinWaitActive. For similar reasons.
You have too many issues in your code that's why I completely changed it. Not worth explaining it.
I think the problem is not necessarily with the code, but possibly with the logic. I could be way off base here, but maybe we should not be looking for a state of 2, but something closer to 15.
A sample with notepad:
$WIN_STATE_EXISTS (1) = Window exists
$WIN_STATE_VISIBLE (2) = Window is visible
$WIN_STATE_ENABLED (4) = Window is enabled
$WIN_STATE_ACTIVE (8) = Window is active
A window that is active (8), enabled (4), visible(2), and exists(1) will have a windows state of 15.
; Look for notepad and display WindowState number
if WinExists("[Class:Notepad]") Then
MsgBox($MB_SYSTEMMODAL, "", "Found")
WinActivate("[Class:Notepad]")
$WinState = WinGetState("[Class:Notepad]")
MsgBox($MB_SYSTEMMODAL, "", $WinState)
EndIf

Resources