Skip to content

Commit

Permalink
Merge pull request #3780 from pqrs-org/improve-notification-window-mu…
Browse files Browse the repository at this point in the history
…ltiline-support

Improve notification window multiline support
  • Loading branch information
tekezo committed Apr 13, 2024
2 parents 894d8b4 + 00182ec commit 6494c02
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
27 changes: 19 additions & 8 deletions src/apps/NotificationWindow/src/NotificationWindowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private func callback(
}
}

public class NotificationWindowManager {
public class NotificationWindowManager: NSObject {
static let shared = NotificationWindowManager()

private struct ScreenWindow {
Expand All @@ -28,7 +28,9 @@ public class NotificationWindowManager {

private var screenWindows: [ScreenWindow] = []

init() {
override public init() {
super.init()

NotificationCenter.default.addObserver(
forName: NSApplication.didChangeScreenParametersNotification,
object: nil,
Expand Down Expand Up @@ -89,6 +91,7 @@ public class NotificationWindowManager {
screenWindow.mainWindow.ignoresMouseEvents = true
screenWindow.mainWindow.collectionBehavior.insert(.canJoinAllSpaces)
screenWindow.mainWindow.collectionBehavior.insert(.ignoresCycle)
screenWindow.mainWindow.delegate = self
// screenWindow.mainWindow.collectionBehavior.insert(.stationary)

//
Expand All @@ -110,9 +113,12 @@ public class NotificationWindowManager {
screenWindows.append(screenWindow)
}

//
// Update window frame
//
updateWindowsFrameOrigin()
updateWindowsVisibility()
}

func updateWindowsFrameOrigin() {
let screens = NSScreen.screens

for (i, screenWindow) in screenWindows.enumerated() {
var screenFrame = NSRect.zero
Expand All @@ -128,14 +134,13 @@ public class NotificationWindowManager {
screenWindow.closeButtonWindow.setFrame(
NSRect(
x: screenWindow.mainWindow.frame.origin.x - 8,
y: screenWindow.mainWindow.frame.origin.y + 36,
y: screenWindow.mainWindow.frame.origin.y + screenWindow.mainWindow.frame.size.height
- 16,
width: CGFloat(24.0),
height: CGFloat(24.0)),
display: false)
}
}

updateWindowsVisibility()
}

func updateWindowsVisibility() {
Expand All @@ -153,3 +158,9 @@ public class NotificationWindowManager {
}
}
}

extension NotificationWindowManager: NSWindowDelegate {
public func windowDidResize(_ notification: Notification) {
updateWindowsFrameOrigin()
}
}
6 changes: 4 additions & 2 deletions src/apps/NotificationWindow/src/Views/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ struct MainView: View {
@State var opacity = 1.0

var body: some View {
HStack(alignment: .center) {
HStack(alignment: .top) {
Image(decorative: "app")
.resizable()
.frame(width: 48.0, height: 48.0)
.padding(.leading, 2.0)
Text(notificationMessage.text)
.font(.body)
.multilineTextAlignment(.leading)
.frame(width: 340.0, height: 52.0, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)
.padding(4.0)
.frame(width: 340.0, alignment: .leading)
}
.background(
RoundedRectangle(cornerRadius: 12)
Expand Down
6 changes: 4 additions & 2 deletions src/core/grabber/include/grabber/device_grabber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,8 +922,10 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {
if (notification_message_manager_) {
notification_message_manager_->async_set_device_ungrabbable_temporarily_message(
entry->get_device_id(),
fmt::format("Probable stuck key detected! "
"{0} is ignored temporarily until {1} is pressed again.",
fmt::format("Probable stuck key detected!\n\n"
"{0} is ignored temporarily until {1} is pressed again.\n\n"
"Key may have been held when keyboard was grabbed. "
"Is the keyboard reconnecting while in use?",
entry->get_device_short_name(),
nlohmann::json(*event).dump()));
}
Expand Down

0 comments on commit 6494c02

Please sign in to comment.