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

Always reposition window #120

Merged
merged 1 commit into from
Nov 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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