-
-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Frameless windows (macOS implementation) #177
Changes from 3 commits
c9e838f
bf14753
d5a05eb
1f3686f
da9cb1a
30f40e5
a793339
76a53ee
841ca88
83cd92b
3e11619
e76b3f9
d4dfb98
c109c8a
2037a3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,42 @@ | |
info['NSAppTransportSecurity'] = {'NSAllowsArbitraryLoads': Foundation.YES} | ||
|
||
|
||
class DragBar(AppKit.NSView): | ||
def mouseDragged_(self, theEvent): | ||
screenFrame = AppKit.NSScreen.mainScreen().frame() | ||
if screenFrame is None: | ||
sys.stderr.write('failed to obtain screen\n') | ||
raise RuntimeError | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to raise a |
||
|
||
window = self.window() | ||
windowFrame = window.frame() | ||
if windowFrame is None: | ||
sys.stderr.write('failed to obtain frame\n') | ||
raise RuntimeError | ||
|
||
currentLocation = window.convertBaseToScreen_(window.mouseLocationOutsideOfEventStream()) | ||
newOrigin = AppKit.NSMakePoint((currentLocation.x - self.initialLocation.x), | ||
(currentLocation.y - self.initialLocation.y)) | ||
if (newOrigin.y + windowFrame.size.height) > \ | ||
(screenFrame.origin.y + screenFrame.size.height): | ||
newOrigin.y = screenFrame.origin.y + \ | ||
(screenFrame.size.height + windowFrame.size.height) | ||
window.setFrameOrigin_(newOrigin) | ||
|
||
def mouseDown_(self, theEvent): | ||
window = self.window() | ||
|
||
windowFrame = window.frame() | ||
if windowFrame is None: | ||
sys.stderr.write('failed to obtain frame\n') | ||
raise RuntimeError | ||
|
||
self.initialLocation = \ | ||
window.convertBaseToScreen_(theEvent.locationInWindow()) | ||
self.initialLocation.x -= windowFrame.origin.x | ||
self.initialLocation.y -= windowFrame.origin.y | ||
|
||
|
||
class BrowserView: | ||
instance = None | ||
app = AppKit.NSApplication.sharedApplication() | ||
|
@@ -146,7 +182,7 @@ def printView(frameview): | |
def webView_decidePolicyForNavigationAction_request_frame_decisionListener_(self, webview, action, request, frame, listener): | ||
# The event that might have triggered the navigation | ||
event = AppKit.NSApp.currentEvent() | ||
action_type = action['WebActionNavigationTypeKey'] | ||
action_type = action['WebActionNavigationTypeKey'] | ||
|
||
""" Disable back navigation on pressing the Delete key: """ | ||
# Check if the requested navigation action is Back/Forward | ||
|
@@ -166,7 +202,18 @@ def webView_didFinishLoadForFrame_(self, webview, frame): | |
if not webview.window(): | ||
BrowserView.instance.window.setContentView_(webview) | ||
BrowserView.instance.window.makeFirstResponder_(webview) | ||
|
||
|
||
frame_size = BrowserView.instance.window.frame().size | ||
drag_bar_height = 24 | ||
|
||
# Flip the webview so our bar is position from the top, not bottom | ||
webview.setFlipped_(True) | ||
|
||
rect = AppKit.NSMakeRect(0, 0, frame_size.width, drag_bar_height) | ||
drag_bar = DragBar.alloc().initWithFrame_(rect) | ||
drag_bar.setAutoresizingMask_(AppKit.NSViewWidthSizable) | ||
BrowserView.instance.window.contentView().addSubview_(drag_bar) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason this code (line 204 to 215) is put here? Do we need to update the drag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I managed to move it to init in 841ca88 (new to pyobjc!). |
||
BrowserView.load_event.set() | ||
if BrowserView.instance.js_bridge: | ||
BrowserView.instance._set_js_api() | ||
|
@@ -224,7 +271,7 @@ def performKeyEquivalent_(self, theEvent): | |
|
||
return handled | ||
|
||
def __init__(self, title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready): | ||
def __init__(self, title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready, frameless): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please place |
||
BrowserView.instance = self | ||
BrowserView.debug = debug | ||
|
||
|
@@ -244,15 +291,25 @@ def __init__(self, title, url, width, height, resizable, fullscreen, min_size, b | |
if resizable: | ||
window_mask = window_mask | AppKit.NSResizableWindowMask | ||
|
||
if frameless is True: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
window_mask = window_mask | AppKit.NSFullSizeContentViewWindowMask | AppKit.NSTexturedBackgroundWindowMask | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Edit: |
||
|
||
self.window = AppKit.NSWindow.alloc().\ | ||
initWithContentRect_styleMask_backing_defer_(rect, window_mask, AppKit.NSBackingStoreBuffered, False) | ||
self.window.setTitle_(title) | ||
self.window.setBackgroundColor_(BrowserView.nscolor_from_hex(background_color)) | ||
self.window.setMinSize_(AppKit.NSSize(min_size[0], min_size[1])) | ||
# Set the titlebar color (so that it does not change with the window color) | ||
self.window.contentView().superview().subviews().lastObject().setBackgroundColor_(AppKit.NSColor.windowBackgroundColor()) | ||
|
||
self.webkit = BrowserView.WebKitHost.alloc().initWithFrame_(rect) | ||
if frameless is True: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.window.setTitlebarAppearsTransparent_(True) | ||
self.window.setTitleVisibility_(AppKit.NSWindowTitleHidden) | ||
webkit_rect = AppKit.NSMakeRect(0, -12, width, height - 12) | ||
else: | ||
# Set the titlebar color (so that it does not change with the window color) | ||
self.window.contentView().superview().subviews().lastObject().setBackgroundColor_(AppKit.NSColor.windowBackgroundColor()) | ||
webkit_rect = rect | ||
|
||
self.webkit = BrowserView.WebKitHost.alloc().initWithFrame_(webkit_rect) | ||
|
||
self._browserDelegate = BrowserView.BrowserDelegate.alloc().init() | ||
self._windowDelegate = BrowserView.WindowDelegate.alloc().init() | ||
|
@@ -535,11 +592,11 @@ def _set_debugging(): | |
|
||
|
||
def create_window(title, url, width, height, resizable, fullscreen, min_size, | ||
confirm_quit, background_color, debug, js_api, webview_ready): | ||
confirm_quit, background_color, debug, js_api, webview_ready, frameless): | ||
global _confirm_quit | ||
_confirm_quit = confirm_quit | ||
|
||
browser = BrowserView(title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready) | ||
browser = BrowserView(title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready, frameless) | ||
browser.show() | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
havea typo