Skip to content

Commit 7884a23

Browse files
committed
osx: Make draggable region work for window with hidden titlebar
1 parent 6f944ad commit 7884a23

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

atom/browser/native_window.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ NativeWindow::NativeWindow(
6868
const mate::Dictionary& options)
6969
: content::WebContentsObserver(inspectable_web_contents->GetWebContents()),
7070
has_frame_(true),
71+
force_using_draggable_region_(false),
7172
transparent_(false),
7273
enable_larger_than_screen_(false),
7374
is_closed_(false),
@@ -473,7 +474,7 @@ bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
473474
void NativeWindow::UpdateDraggableRegions(
474475
const std::vector<DraggableRegion>& regions) {
475476
// Draggable region is not supported for non-frameless window.
476-
if (has_frame_)
477+
if (has_frame_ && !force_using_draggable_region_)
477478
return;
478479
draggable_region_ = DraggableRegionsToSkRegion(regions);
479480
}

atom/browser/native_window.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ class NativeWindow : public content::WebContentsObserver,
219219
bool enable_larger_than_screen() const { return enable_larger_than_screen_; }
220220
gfx::ImageSkia icon() const { return icon_; }
221221

222+
bool force_using_draggable_region() const {
223+
return force_using_draggable_region_;
224+
}
225+
void set_force_using_draggable_region(bool force) {
226+
force_using_draggable_region_ = true;
227+
}
228+
222229
void set_has_dialog_attached(bool has_dialog_attached) {
223230
has_dialog_attached_ = has_dialog_attached;
224231
}
@@ -257,6 +264,9 @@ class NativeWindow : public content::WebContentsObserver,
257264
// Whether window has standard frame.
258265
bool has_frame_;
259266

267+
// Force the window to be aware of draggable regions.
268+
bool force_using_draggable_region_;
269+
260270
// Whether window is transparent.
261271
bool transparent_;
262272

atom/browser/native_window_mac.mm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ - (void)drawRect:(NSRect)dirtyRect {
391391
// We will manage window's lifetime ourselves.
392392
[window_ setReleasedWhenClosed:NO];
393393

394-
// Configure title bar look on Yosemite or newer
394+
// Hide the title bar.
395395
if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
396396
[window_ setTitlebarAppearsTransparent:YES];
397397
[window_ setTitleVisibility:NSWindowTitleHidden];
@@ -401,6 +401,8 @@ - (void)drawRect:(NSRect)dirtyRect {
401401
[toolbar setShowsBaselineSeparator:NO];
402402
[window_ setToolbar:toolbar];
403403
}
404+
// We should be aware of draggable regions when using hidden titlebar.
405+
set_force_using_draggable_region(true);
404406
}
405407

406408
// On OS X the initial window size doesn't include window frame.
@@ -432,6 +434,11 @@ - (void)drawRect:(NSRect)dirtyRect {
432434
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
433435

434436
InstallView();
437+
438+
// Install the DraggableRegionView if it is forced to use draggable regions
439+
// for normal window.
440+
if (has_frame() && force_using_draggable_region())
441+
InstallDraggableRegionView();
435442
}
436443

437444
NativeWindowMac::~NativeWindowMac() {

0 commit comments

Comments
 (0)