0

I would like take screenshot of specific inactive or minimized desktop application using python in ubuntu 20.04. x11 system

It seems that in you could do this in window by using Windows API like win32gui in order to find list of windows and take screenshot of it. screenshot-of-inactive-window-printwindow-win32gui but i have not found a solution on ubuntu.

What i have tried is first of all i tried to find the list of applications that are running and get specific application using wnck

import gi
gi.require_version("Wnck", "3.0")
from gi.repository import Wnck

def get_opened_window_title():
    screen = Wnck.Screen.get_default()
    screen.force_update()

    window_list = screen.get_windows()
    for x in window_list:
        screen_t = Wnck.Screen.get_default()
        screen_t = x
        title = x.get_name()
        print(title)
    return window_list


def get_specific_window(name):
    screen = Wnck.Screen.get_default()
    screen.force_update()

    window_list = screen.get_windows()
    for x in window_list:
        screen = Wnck.Screen.get_default()
        screen = x
        title = screen.get_name()
        if title == name:
            return screen
    return screen


w2 = get_specific_window("League of Legends")

print(w2)
print(type(w2))
print(w2.get_screen())
print(type(w2.get_screen()))

and when i call the get_specific_window() function and print it i get

<Wnck.Window object at 0x7f8acf26bec0 (WnckWindow at 0x1b898e0)>
<class 'gi.repository.Wnck.Window'>
<Wnck.Screen object at 0x7f8acf26f200 (WnckScreen at 0x19bf2b0)>
<class 'gi.repository.Wnck.Screen'>

and now i could get the minimized application's wnck object but i do not know how i can take a screenshot of this minimized screen. I have tried using pillow, opencv but they do not take this wnck object as their parameter.

Is there any way of capturing the screenshot of minimized or inactive desktop application using python in ubuntu? and is my approach to this problem with wnck wrong?

Seungju
  • 101
  • 6

0 Answers0