Skip to content

Commit

Permalink
load the NSNib once for each screen, centering the window near the me…
Browse files Browse the repository at this point in the history
…nubar

re: #63

Doesn't fully fix the issue since we still need a controller object for things
to talk to, but it mostly does the trick

This commit was sponsored by Matt Campbell, Derek Veit, Jason Walker,
and my other patrons.  If you want to join them, you can support my
work at https://glyph.im/patrons/.
  • Loading branch information
glyph committed Jun 21, 2024
1 parent 785f21e commit 36a312d
Showing 1 changed file with 47 additions and 16 deletions.
63 changes: 47 additions & 16 deletions src/pomodouroboros/macos/hudmulti.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from typing import Self
from Foundation import NSMakePoint
from AppKit import (
NSNib,
NSObject,
NSScreen,
NSWindow,
NSWorkspace,
NSWorkspaceActiveSpaceDidChangeNotification,
)
from objc import IBOutlet
from objc import IBOutlet, object_property, super

from .progress_hud import PieTimer

Expand All @@ -23,34 +26,62 @@ class HUDMultipleProgress(NSObject):
right = IBOutlet()
win: NSWindow
win = IBOutlet()
screen: NSScreen = object_property()

def initWithScreen_(self, screen: NSScreen) -> Self:
super().init()
self.screen = screen
return self

def someSpaceActivated_(self, theSpace) -> None:
print("IOAS", self.win.isOnActiveSpace())
self.win.setIsVisible_(False)
self.win.setIsVisible_(True)
print("IOAS", self.win.isOnActiveSpace())

def retain(self) -> Self:
return super().retain() # type:ignore[no-any-return]

def repositionWindow(self) -> None:

screenFrame = self.screen.frame()
w = self.win.frame().size.width
h = self.win.frame().size.height
sw = screenFrame.size.width / 2
sh = screenFrame.size.height * (5 / 6)
winOrigin = NSMakePoint(
screenFrame.origin.x + (sw - (w / 2)),
screenFrame.origin.y + (sh - (h / 2)),
)
print(f"screenOrigin: {screenFrame.origin} winOrigin: {winOrigin}")
self.win.setFrameOrigin_(winOrigin)


def debugMultiHud() -> None:
print("multiHudDebug")
nibInstance = NSNib.alloc().initWithNibNamed_bundle_(
"ProgressHUD.nib", None
)
owner = HUDMultipleProgress.alloc().init().retain()
loaded, tlos = nibInstance.instantiateWithOwner_topLevelObjects_(
owner, None
)

owner.left.setPercentage_(0.1)
owner.middle.setPercentage_(0.2)
owner.right.setPercentage_(0.3)
for screen in NSScreen.screens():
owner = HUDMultipleProgress.alloc().initWithScreen_(screen).retain()

wsnc = NSWorkspace.sharedWorkspace().notificationCenter()
wsnc.addObserver_selector_name_object_(
owner,
"someSpaceActivated:",
NSWorkspaceActiveSpaceDidChangeNotification,
None,
)
loaded, tlos = nibInstance.instantiateWithOwner_topLevelObjects_(
owner, None
)

owner.repositionWindow()

owner.left.setPercentage_(0.1)
owner.middle.setPercentage_(0.2)
owner.right.setPercentage_(0.3)

wsnc = NSWorkspace.sharedWorkspace().notificationCenter()
wsnc.addObserver_selector_name_object_(
owner,
"someSpaceActivated:",
NSWorkspaceActiveSpaceDidChangeNotification,
None,
)

print("OK")
print("OK")

0 comments on commit 36a312d

Please sign in to comment.