Checking which monitor, display an object is being shown on (SWT, Java)

Last edited on

Here is an example that shows how to check which monitor/display a GUI object is being shown on:

def get_monitor_index_swt(swt_widget):
    m = swt_widget.monitor
    monitors = swt_widget.display.getMonitors()
    for i in range(monitors.length):
        if m ==
            return i
    return -1

def main():

    o = waitForObject({"isvisible": True, "type": "org.eclipse.swt.widgets.Table"})
    idx = get_monitor_index_swt(o)
    test.log("Widget is on monitor/display #%s" % idx)