Skip to content

Commit

Permalink
repositions the window every time it is toggled (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
vutran committed Jan 5, 2017
1 parent f4d1d48 commit d1d969e
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions app/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,27 @@ const config = new Config();

const hideWindow = () => win && win.hide();

// toggles the main window visibility
/**
* Repositions the window based on the mouse's active screen
*/
const repositionWindow = () => {
const { screen } = electron;
const cursorPoint = screen.getCursorScreenPoint();
const currScreen = screen.getDisplayNearestPoint(cursorPoint);
const resultsHeight = WINDOW_MAX_HEIGHT;
const size = win.getSize();
const winPosition = [
((currScreen.size.width / 2) - (size[0] / 2)) + currScreen.bounds.x,
((currScreen.size.height / 2) - ((size[1] + resultsHeight) / 2)) + currScreen.bounds.y,
];
win.setPosition(winPosition[0], winPosition[1]);
};

/**
* Toggles the main window visibility
*/
const toggleMainWindow = () => {
repositionWindow();
if (win.isVisible()) {
hideWindow();
} else {
Expand All @@ -60,6 +79,8 @@ const toggleMainWindow = () => {
* Executes an action for a given message based on modifier priority.
*
* Priority: SuperKey, AltKey, None
*
* @param {Object} message
*/
const execute = (message) => {
// apply modifiers if necessary
Expand Down Expand Up @@ -92,19 +113,6 @@ const copyItem = () => {
win.webContents.send(IPC_COPY_CURRENT_ITEM_KEY);
};

const repositionWindow = () => {
const { screen } = electron;
const cursorPoint = screen.getCursorScreenPoint();
const currScreen = screen.getDisplayNearestPoint(cursorPoint);
const resultsHeight = WINDOW_MAX_HEIGHT;
const size = win.getSize();
const winPosition = [
((currScreen.size.width / 2) - (size[0] / 2)) + currScreen.bounds.x,
((currScreen.size.height / 2) - ((size[1] + resultsHeight) / 2)) + currScreen.bounds.y,
];
win.setPosition(winPosition[0], winPosition[1]);
};

// free the window object from memory
const handleWindowClose = () => {
win = null;
Expand Down Expand Up @@ -284,7 +292,7 @@ const debounceHandleItemDetailsRequest = debounce(handleItemDetailsRequest, 500)
const debounceHandleCopyItemToClipboard = debounce(handleCopyItemToClipboard, 500);

/**
* Creates a new Browser window and loads the renderer index
* Creates a new Browser window and loads the renderer index.
*/
const createWindow = () => {
win = new BrowserWindow({
Expand All @@ -298,10 +306,9 @@ const createWindow = () => {
maximizable: false,
hasShadow: true,
skipTaskbar: true,
transparent: true
transparent: true,
});

// re-position
repositionWindow();

const rendererPath = path.resolve(__dirname, '..', 'renderer');
Expand Down

0 comments on commit d1d969e

Please sign in to comment.