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

[feature] Choose screen behavior #647

Closed
2 tasks done
emilioidk opened this issue Jan 11, 2023 · 4 comments · Fixed by #678
Closed
2 tasks done

[feature] Choose screen behavior #647

emilioidk opened this issue Jan 11, 2023 · 4 comments · Fixed by #678

Comments

@emilioidk
Copy link
Contributor

  • I am on the latest Cerebro.app version
  • I have searched the issues of this repo and believe that this is not a duplicate
  • OS version and name: Ubuntu 22.04
  • Cerebro.app version: 0.10.0
  • Relevant information from devtools (See above how to open it): N/A

Feature

Cerebro always opens in the middle of the first screen but for people using several screens (which I assume is quite common in the kind of people that would use Cerebro) it would be much more ergonomic to be able to set the screen behavior. By default Cerebro should open centered in the screen in which the mouse pointer is but the option to set a fixed screen to open Cerebro in could be very useful for many users.

@emilioidk
Copy link
Contributor Author

I was digging into how to make it possible and I was able to accomplish it with almost no effort. The video I attach shows my local dev version opening in the screen in which the mouse pointer is at.

Screencast.2023-01-13.20.59.02.mp4

There are some caveats with my solution based entirely in my lack of competence in Electron and my intention of doing a quick prototype to see how it would work. Without understanding much why, I would have expected the code for this functionality to live in the "renderer" side of the application however to make it work I needed to use Electron's screen (https://www.electronjs.org/docs/latest/api/screen) which is only available in the main process. The code in my prototype looks like this

app.whenReady().then(() => {
  // We cannot require the screen module until the app is ready.
  const { screen } = require('electron')

  ...

  mainWindow.on('show', (event) => {
    const cursorScreenPoint = screen.getCursorScreenPoint()
    const nearestDisplay = screen.getDisplayNearestPoint(cursorScreenPoint)

    const goalWidth = 650 // hardcoded now, should get from config or calculate accordingly
    const goalX = Math.floor(nearestDisplay.bounds.x + (nearestDisplay.size.width - goalWidth) / 2)
    const goalY = 200 // hardcoded now, should get from config or calculate accordingly

    config.set('winPosition', [goalX, goalY])
  })

I have only tested this example in Ubuntu 22.04 but the methods used from screen seem to be available for all platforms.

@ogustavo-pereira
Copy link
Member

Hi thanks @emilioidk for the feature suggestion, always wanted to improve rendering on multiple screens, feel free to upload a pr so we can review

emilioidk added a commit to emilioidk/cerebro that referenced this issue Oct 11, 2023
…osest to the mouse pointer

When displaying the main window for Cerebro so far the primary screen has been chosen. This is
inconvenient for workstations with more than 1 screen. After this commit is applied the main window
will be displayed in the screen containing the mouse pointer (or the screen closest to the pointer
if the pointer is in between screens).

fix cerebroapp#647
@emilioidk
Copy link
Contributor Author

@oguhpereira I'd forgotten about it, sorry about that. I have now created a PR, looking forward to getting feedback.

ogustavo-pereira pushed a commit that referenced this issue Nov 22, 2023
…osest to the mouse pointer (#678)

When displaying the main window for Cerebro so far the primary screen has been chosen. This is
inconvenient for workstations with more than 1 screen. After this commit is applied the main window
will be displayed in the screen containing the mouse pointer (or the screen closest to the pointer
if the pointer is in between screens).

fix #647
@ogustavo-pereira
Copy link
Member

Thanks @emilioidk

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