def get_size(self):
     """Return the window actual size as a tuple (width, height)."""
     flags, showCmd, ptMin, ptMax, rect = win32gui.GetWindowPlacement(
         self.base_handler_id)
     w = rect[2] - rect[0]
     h = rect[3] - rect[1]
     return (w, h)
    def set_position(self, pos, update=True):
        """Set the window position.
        :pos: list or tuple: the new position (x, y)."""
        if DEBUG_WM:
            print "Setting position to", pos
        if type(pos) in (list, tuple):
            self.first_pos = False
            x, y = pos
            if update:
                flags, showCmd, ptMin, ptMax, rect = win32gui.GetWindowPlacement(
                    self.base_handler_id)
                if DEBUG_WM:
                    print "set_position rect", rect, "ptMin", ptMin, "ptMax", ptMax
                realW = rect[2] - rect[0]
                realH = rect[3] - rect[1]
                if DEBUG_WM:
                    print 'rect[0]', rect[0], 'rect[1]', rect[1]
                    print 'realW', realW, 'realH', realH
                    print 'cursor pos', win32gui.GetCursorPos()

                rect = (x, y, x + realW, y + realH)

                win32gui.SetWindowPlacement(self.base_handler_id,
                                            (0, showCmd, ptMin, ptMax, rect))
        else:
            # Raise a Type error.
            raise TypeError, "%s is not a list or a tuple." % repr(pos)
    def set_size(self, size, update=True):
        """Set the window size.
        :size: list or tuple: the new size.
        :mode: bool: (re)set the pygame.display mode; self.mode must be a pygame display mode object.
        Raises a TypeError if something else than a list or a tuple is sent."""
        if type(size) in (list, tuple):
            w, h = size
            cx, cy = win32gui.GetCursorPos()
            if DEBUG_WM:
                print "Settin size to", size
                print "actual size", self.get_size()
                print "actual position", self.get_position()

                print 'cursor pos', cx, cy
            flags, showCmd, ptMin, ptMax, rect = win32gui.GetWindowPlacement(
                self.base_handler_id)
            if DEBUG_WM:
                print "set_size rect", rect, "ptMin", ptMin, "ptMax", ptMax, "flags", flags
            x = rect[0]
            y = rect[1]
            rect = (x, y, x + w, y + h)
            win32gui.SetWindowPlacement(self.base_handler_id,
                                        (0, showCmd, ptMin, ptMax, rect))
        else:
            # Raise a Type error.
            raise TypeError, "%s is not a list or a tuple." % repr(size)
Beispiel #4
0
 def isWindowMaximized(self, hWnd) -> bool:
     """ 判断窗口是否最大化 """
     # 返回指定窗口的显示状态以及被恢复的、最大化的和最小化的窗口位置,返回值为元组
     windowPlacement = win32gui.GetWindowPlacement(hWnd)
     if not windowPlacement:
         return False
     return windowPlacement[1] == win32con.SW_MAXIMIZE
Beispiel #5
0
def fgNotSoF():
    global sofId
    global cbuf_addText
    global origResDesktop
    global resizeDone
    while True:
        try:
            tup = win32gui.GetWindowPlacement(sofId)
            break
        except Exception as e:
            if e == KeyboardInterrupt:
                raise
            searchForSoFWindow()
    fgWindow = win32gui.GetForegroundWindow()
    if fgWindow != sofId:
        normal = 0
        minimized = 0
        if tup[1] == win32con.SW_SHOWMAXIMIZED:
            # print("mini false")
            minimized = 0
        elif tup[1] == win32con.SW_SHOWMINIMIZED:
            # print("mini true")
            minimized = 1
        elif tup[1] == win32con.SW_SHOWNORMAL:
            # print("normal true")
            normal = 1
        if not minimized or normal:
            win32gui.ShowWindow(sofId, win32con.SW_MINIMIZE)
        if origResDesktop != getLiveDesktop():
            #we know desktop res
            if not resizeDesktop(origResDesktop,0):
                print("Change res to original failed")
            else:
                cbuf_addText(b';s_nosound 1;')
                resizeDone = 0
Beispiel #6
0
    def _isWindowMaximized(self, hWnd) -> bool:
        """ Determine whether the window is maximized """
        windowPlacement = win32gui.GetWindowPlacement(hWnd)
        if not windowPlacement:
            return False

        return windowPlacement[1] == win32con.SW_MAXIMIZE
Beispiel #7
0
 def get_state(self):
     """Return wheter the window is maximized or not, or minimized or full screen."""
     flags, state, ptMin, ptMax, rect = win32gui.GetWindowPlacement(self.base_handler_id)
     if DEBUG_WM:
         print "state", state
     if state == win32con.SW_MAXIMIZE:
         return MAXIMIZED
     elif state == win32con.SW_MINIMIZE:
         return MINIMIZED
     return NORMAL
Beispiel #8
0
    def __update_window_state(self):
        # https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowplacement
        window_placement = win32gui.GetWindowPlacement(self.__hwnd)
        window_state = window_placement[1]

        state_normal = WINDOW_STATES['NORMAL']
        state_minimized = WINDOW_STATES['MINIMIZED']
        state_maximized = WINDOW_STATES['MAXIMIZED']
        state_unknown = WINDOW_STATES['UNKNOWN']

        if window_state == WINDOW_STATES_CONSTANTS[state_normal]:
            self.__state = state_normal
        elif window_state == WINDOW_STATES_CONSTANTS[state_minimized]:
            self.__state = state_minimized
        elif window_state == WINDOW_STATES_CONSTANTS[state_maximized]:
            self.__state = state_maximized
        else:
            self.__state = state_unknown

        return self.__state
 def get_position(self):
     """Return the window actual position as a tuple."""
     (flags, showCmd, ptMin, ptMax,
      rect) = win32gui.GetWindowPlacement(self.base_handler_id)
     x, y, r, b = rect
     return (x, y)
 def get_root_rect(self):
     """Return a four values tuple containing the position and size of the very first OS window object."""
     flags, showCmd, ptMin, ptMax, rect = win32gui.GetWindowPlacement(
         win32gui.GetDesktopWindow())
     return rect
def callback(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread,
             dwmsEventTime):
    try:
        global lastTime
        global sofId
        #minimise a minimised window = bad?
        global sofMini
        global sofFull
        global resizedDesktop
        global origResDesktop
        global origResSof


        if event == win32con.EVENT_OBJECT_FOCUS:

            normal = False
            #sof stuff
            fgWindow = win32gui.GetForegroundWindow()
            #print("SoFid = "+str(sofId)+"\n")
            #print("fgwindow"+str(fgWindow)+"\n")

            while True:
                try:
                    tup = win32gui.GetWindowPlacement(sofId)
                    break
                except Exception as e:
                    if e == KeyboardInterrupt:
                        raise
                    searchForSoFWindow()

            minimized = True
            if tup[1] == win32con.SW_SHOWMAXIMIZED:
                # print("mini false")
                minimized = False
            elif tup[1] == win32con.SW_SHOWMINIMIZED:
                # print("mini true")
                minimized = True
            elif tup[1] == win32con.SW_SHOWNORMAL:
                # print("normal true")
                normal = True

            if fgWindow != sofId:
                #focused window != sof
                #minimise sof just incase
                #account for vid_fullscreen 0 players
                # if minimized == False:

                # print("minimise sof")
                if normal or not minimized:
                    win32gui.ShowWindow(sofId, win32con.SW_MINIMIZE)

                #if we resized desktop already
                #lost focus of sof
                # print("Desktop Active.")
                # print(f"What it SHOULD be : {origResDesktop[0]} , {origResDesktop[1]}")
                # getDesktop()
                # print(f"What it IS : {resDesktop[0]} , {resDesktop[1]}")
                if origResDesktop != getDesktop():
                    if resizedDesktop == 0:
                        if ChangeDisplaySettings(None, 0) == win32con.DISP_CHANGE_SUCCESSFUL:
                            resizedDesktop = 1
                            print("Change res to original")
                        else:
                            print("Change res to original failed")

            else:
                #what if we fail these checks and 'origResSof is never set?'
                #shouldnt we wait while until set?
                while True:
                    if normal:
                        print("sof = normal")
                        origResSof = getSoFRes(sofId)
                        print(f"Getting Sof Resolution : {origResSof[0]} , {origResSof[1]}")
                        resizedDesktop = 0
                        break
                    else:
                        print("DEBUG**************not normal and minimised")         
                        while True:
                            try:
                                tup = win32gui.GetWindowPlacement(sofId)
                                print(tup[1])
                                if tup[1] == win32con.SW_SHOWNORMAL:
                                    # print("mini false")
                                    normal = True
                                    print("DEBUg- maximised")
                                break
                            except Exception as e:
                                if e == KeyboardInterrupt:
                                    raise
                                searchForSoFWindow()

                #we have focus of sof
                # print("Sof Active.")
                # print(f"What it SHOULD be : {origResSof[0]} , {origResSof[1]}")
                # getDesktop()
                # print(f"What it IS : {resDesktop[0]} , {resDesktop[1]}")
                #if the current res of desktop != current res of sof
                if getDesktop() != origResSof:
                        print("resize desktop to sof res")
                        if not setRes(origResSof[0],origResSof[1]):
                            print("failed setting sof resolution")
                        #mini then max seems to fix the LALT bug... hm
                        win32gui.ShowWindow(sofId, win32con.SW_MINIMIZE)
                        win32gui.ShowWindow(sofId, win32con.SW_MAXIMIZE)
                else:
                    print("desktop == sof apparently")
        elif event == win32con.EVENT_OBJECT_SHOW:
            # getSoFRes(sofId)
            # print(f"LOCRESX : {origResSof[0]} LOCRESY : {origResSof[1]}")
            pass
            
    except KeyboardInterrupt:
        sys.exit(1)