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

Add mainwindow_position = topleft etc #42

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Code and stuff:
* Unit 193
* yauhen-l
* dionisiovj
* Kent Friis

Bugs and ideas:
* Sergei Sarbash <sarbash.s@gmail.com>
Expand Down
9 changes: 9 additions & 0 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void Config::setDefaults()
mainwindow_sticky = false;
mainwindow_skip_taskbar = true;
mainwindow_position = GTK_WIN_POS_MOUSE;
mainwindow_gravity = GdkGravity(0);
mainwindow_xoffset = 0;
mainwindow_yoffset = 0;
mark_today = true;
Expand Down Expand Up @@ -163,6 +164,14 @@ void Config::addOption(string var, string val)
mainwindow_position = GTK_WIN_POS_CENTER;
} else if (val == "mouse") {
mainwindow_position = GTK_WIN_POS_MOUSE;
} else if (val == "topleft") {
mainwindow_gravity = GDK_GRAVITY_NORTH_WEST;
} else if (val == "topright") {
mainwindow_gravity = GDK_GRAVITY_NORTH_EAST;
} else if (val == "bottomleft") {
mainwindow_gravity = GDK_GRAVITY_SOUTH_WEST;
} else if (val == "bottomright") {
mainwindow_gravity = GDK_GRAVITY_SOUTH_EAST;
} else {
mainwindow_position = GTK_WIN_POS_NONE;
}
Expand Down
1 change: 1 addition & 0 deletions src/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Config
bool mainwindow_sticky;
bool mainwindow_skip_taskbar;
bool mainwindow_resizable;
GdkGravity mainwindow_gravity;
GtkWindowPosition mainwindow_position;
int mainwindow_xoffset;
int mainwindow_yoffset;
Expand Down
34 changes: 31 additions & 3 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ MainWindow::MainWindow()

gtk_window_set_title(GTK_WINDOW(widget), "gsimplecal");
gtk_window_set_decorated(GTK_WINDOW(widget), config->mainwindow_decorated);
gtk_window_set_position(GTK_WINDOW(widget), config->mainwindow_position);
gtk_window_get_position(GTK_WINDOW(widget), &xpos, &ypos);
gtk_window_move(GTK_WINDOW(widget), config->mainwindow_xoffset + xpos, config->mainwindow_yoffset + ypos);
gtk_window_set_resizable(GTK_WINDOW(widget), config->mainwindow_resizable);
gtk_window_set_keep_above(GTK_WINDOW(widget),
config->mainwindow_keep_above);
Expand Down Expand Up @@ -131,6 +128,37 @@ MainWindow::MainWindow()

gtk_container_add(GTK_CONTAINER(widget), children_box);
gtk_widget_show(children_box);

if (config->mainwindow_gravity) {
gtk_window_get_size(GTK_WINDOW(widget), &xpos, &ypos);
switch(config->mainwindow_gravity) {
case GDK_GRAVITY_NORTH_WEST:
xpos = config->mainwindow_xoffset;
ypos = config->mainwindow_yoffset;
break;
case GDK_GRAVITY_NORTH_EAST:
xpos = gdk_screen_width() - xpos - config->mainwindow_xoffset;
ypos = config->mainwindow_yoffset;
break;
case GDK_GRAVITY_SOUTH_WEST:
xpos = config->mainwindow_xoffset;
ypos = gdk_screen_height() - ypos - config->mainwindow_yoffset;
break;
case GDK_GRAVITY_SOUTH_EAST:
xpos = gdk_screen_width() - xpos - config->mainwindow_xoffset;
ypos = gdk_screen_height() - ypos - config->mainwindow_yoffset;
break;
}
gtk_window_set_gravity(GTK_WINDOW(widget), config->mainwindow_gravity);
gtk_window_move(GTK_WINDOW(widget), xpos, ypos);
} else {
gtk_window_set_position(GTK_WINDOW(widget), config->mainwindow_position);
gtk_window_get_position(GTK_WINDOW(widget), &xpos, &ypos);
gtk_window_move(GTK_WINDOW(widget),
config->mainwindow_xoffset + xpos,
config->mainwindow_yoffset + ypos);
}

gtk_widget_show(widget);

// Connect keyboard accelerators
Expand Down