Skip to content
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

feat: custom positioning for traffic light buttons #21781

Merged
merged 4 commits into from Jan 23, 2020
Merged

feat: custom positioning for traffic light buttons #21781

merged 4 commits into from Jan 23, 2020

Conversation

TonyWuu
Copy link
Contributor

@TonyWuu TonyWuu commented Jan 15, 2020

Description of Change

There seems to be a high demand for custom inset traffic light buttons in Electron.

  • I added a new option in BrowserWindow, trafficLightPosition which sets the (x,y) position of the traffic light buttons.
  • It needs to be used in conjunction with titleBarStyle: 'hidden' to work.
  • Default to a value of (0, 0), which results in the standard default position, identical to the regular placement in titleBarStyle: 'hidden'.

e.g.

titleBarStyle: 'hidden'
trafficLightPosition: {x: 12, y: 42}

image

Checklist

Release Notes

Notes: add trafficLightPosition option in BrowserWindow API to allow custom positioning of traffic lights

@welcome
Copy link

welcome bot commented Jan 15, 2020

💖 Thanks for opening this pull request! 💖

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jan 15, 2020
@TonyWuu TonyWuu mentioned this pull request Jan 15, 2020
3 tasks
shell/browser/native_window_mac.mm Outdated Show resolved Hide resolved
shell/browser/native_window_mac.mm Outdated Show resolved Hide resolved
@zcbenz
Copy link
Member

zcbenz commented Jan 15, 2020

/cc @electron/wg-api for more inputs.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Jan 16, 2020
Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of API I'd prefer

trafficLightPosition: {
  x: number;
  y: number;
}

Then it is just a Point object

@@ -509,6 +511,45 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
[NSEvent removeMonitor:wheel_event_monitor_];
}

void NativeWindowMac::RepositionTrafficLights() {
if (!traffic_light_offsetX_ && !traffic_light_offsetY_) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not allow offsets set to 0 which someone may want

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that an offset of 0 should result in the default position of the traffic lights (in titleBarStyle: 'hidden' mode). Are you suggesting there's a use case where someone might want an offset smaller than that default position? In that case, negative numbers would work here.

IMO (x: 0, y: 0) should have a frame of reference relative to the default position, and not the absolute (0, 0) position of the frame

Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit 👍

@MarshallOfSound MarshallOfSound merged commit 5781850 into electron:master Jan 23, 2020
@welcome
Copy link

welcome bot commented Jan 23, 2020

Congrats on merging your first pull request! 🎉🎉🎉

@release-clerk
Copy link

release-clerk bot commented Jan 23, 2020

Release Notes Persisted

add trafficLightPosition option in BrowserWindow API to allow custom positioning of traffic lights

MarshallOfSound pushed a commit that referenced this pull request Jan 31, 2020
* feat: custom positioning for traffic light buttons

* remove NSLog and unnecessary call-site in IsVisible()

* no longer need to check if entering fullscreen

* change API to take a point object

Co-authored-by: tonyfwoo <55114329+tonyfwoo@users.noreply.github.com>
@trop
Copy link
Contributor

trop bot commented Jan 31, 2020

@MarshallOfSound has manually backported this PR to "8-x-y", please check out #21990

MarshallOfSound added a commit that referenced this pull request Jan 31, 2020
* feat: custom positioning for traffic light buttons (#21781)

* feat: custom positioning for traffic light buttons

* remove NSLog and unnecessary call-site in IsVisible()

* no longer need to check if entering fullscreen

* change API to take a point object

Co-authored-by: tonyfwoo <55114329+tonyfwoo@users.noreply.github.com>

* chore: add safety checks to RepositionTrafficLights

Co-authored-by: Tony <TonyWuu@users.noreply.github.com>
Co-authored-by: tonyfwoo <55114329+tonyfwoo@users.noreply.github.com>
@jameskerr
Copy link

I'm excited for this! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants