Skip to content
Open
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
39 changes: 36 additions & 3 deletions src/configsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <unistd.h> /* fsync */

#include "configsys.h"
#include "screen-size.h"
#include <vte/vte.h>

static cfg_t *tc;
Expand Down Expand Up @@ -168,6 +169,7 @@ static cfg_opt_t config_opts[] = {
CFG_BOOL("inherit_working_dir", TRUE, CFGF_NONE),
CFG_BOOL("command_login_shell", FALSE, CFGF_NONE),
CFG_BOOL("start_fullscreen", FALSE, CFGF_NONE),
CFG_BOOL("span_monitors", FALSE, CFGF_NONE),
/* Whether closing a tab shows a confirmation dialog. */
CFG_BOOL("confirm_close_tab", TRUE, CFGF_NONE),

Expand Down Expand Up @@ -469,15 +471,46 @@ static GdkMonitor *config_get_configured_monitor ()
y_pos);
}

void config_get_configured_geometry_bounds (GdkRectangle *rectangle)
{
if (!config_getbool ("span_monitors")) {
GdkMonitor *monitor = config_get_configured_monitor ();
gdk_monitor_get_workarea (monitor, rectangle);
return;
}

GdkDisplay *display = gdk_display_get_default ();
gint n_monitors = gdk_display_get_n_monitors (display);

if (n_monitors == 0) {
rectangle->x = 0;
rectangle->y = 0;
screen_size_get_dimensions (&rectangle->width, &rectangle->height);
return;
}

for (gint i = 0; i < n_monitors; i++) {
GdkRectangle workarea;
GdkMonitor *monitor = gdk_display_get_monitor (display, i);

gdk_monitor_get_workarea (monitor, &workarea);
if (i == 0) {
*rectangle = workarea;
} else {
GdkRectangle bounds;
gdk_rectangle_union (rectangle, &workarea, &bounds);
*rectangle = bounds;
}
}
}

void config_get_configured_window_size (GdkRectangle *rectangle)
{
gdouble relative_width = GLONG_TO_DOUBLE (config_getint ("width_percentage"));
gdouble relative_height = GLONG_TO_DOUBLE (config_getint ("height_percentage"));

GdkMonitor *monitor = config_get_configured_monitor ();

GdkRectangle workarea;
gdk_monitor_get_workarea (monitor, &workarea);
config_get_configured_geometry_bounds (&workarea);

rectangle->width = pixels_ratio_to_absolute (relative_width, workarea.width);
rectangle->height = pixels_ratio_to_absolute (relative_height, workarea.height);
Expand Down
7 changes: 6 additions & 1 deletion src/configsys.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,10 @@ glong config_getnint (const gchar *key, const guint idx);
*/
void config_get_configured_window_size (GdkRectangle *rectangle);

#endif /* CONFIGSYS_H */
/**
* Returns the workarea used as the origin and maximum size for Tilda's
* configured geometry.
*/
void config_get_configured_geometry_bounds (GdkRectangle *rectangle);

#endif /* CONFIGSYS_H */
44 changes: 32 additions & 12 deletions src/key_grabber.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,14 @@ void generate_animation_positions (struct tilda_window_ *tw)

gint last_width = rectangle.width;
gint last_height = rectangle.height;
gint screen_width;
gint screen_height;
screen_size_get_dimensions (&screen_width, &screen_height);
GdkRectangle geometry_bounds;
if (config_getbool ("span_monitors")) {
config_get_configured_geometry_bounds (&geometry_bounds);
} else {
screen_size_get_dimensions (&geometry_bounds.width, &geometry_bounds.height);
geometry_bounds.x = 0;
geometry_bounds.y = 0;
}

for (i=0; i<32; i++)
{
Expand All @@ -98,34 +103,50 @@ void generate_animation_positions (struct tilda_window_ *tw)
case 3: /* right->left RIGHT */
animation_coordinates[ANIMATION_UP][ANIMATION_Y][i] = last_pos_y;
animation_coordinates[ANIMATION_UP][ANIMATION_X][i] =
(gint)(screen_width + (last_pos_x - screen_width) * animation_ease_function_up(i, 32));
(gint)(geometry_bounds.x + geometry_bounds.width
+ (last_pos_x - geometry_bounds.x - geometry_bounds.width)
* animation_ease_function_up(i, 32));
animation_coordinates[ANIMATION_DOWN][ANIMATION_Y][i] = last_pos_y;
animation_coordinates[ANIMATION_DOWN][ANIMATION_X][i] =
(gint)(screen_width + (last_pos_x - screen_width) * animation_ease_function_down(i, 32));
(gint)(geometry_bounds.x + geometry_bounds.width
+ (last_pos_x - geometry_bounds.x - geometry_bounds.width)
* animation_ease_function_down(i, 32));
break;
case 2: /* left->right LEFT */
animation_coordinates[ANIMATION_UP][ANIMATION_Y][i] = last_pos_y;
animation_coordinates[ANIMATION_UP][ANIMATION_X][i] =
(gint)(-last_width + (last_pos_x - -last_width) * animation_ease_function_up(i, 32));
(gint)(geometry_bounds.x - last_width
+ (last_pos_x - geometry_bounds.x + last_width)
* animation_ease_function_up(i, 32));
animation_coordinates[ANIMATION_DOWN][ANIMATION_Y][i] = last_pos_y;
animation_coordinates[ANIMATION_DOWN][ANIMATION_X][i] =
(gint)(-last_width + (last_pos_x - -last_width) * animation_ease_function_down(i, 32));
(gint)(geometry_bounds.x - last_width
+ (last_pos_x - geometry_bounds.x + last_width)
* animation_ease_function_down(i, 32));
break;
case 1: /* bottom->top BOTTOM */
animation_coordinates[ANIMATION_UP][ANIMATION_Y][i] =
(gint)(screen_height + (last_pos_y - screen_height) * animation_ease_function_up(i, 32));
(gint)(geometry_bounds.y + geometry_bounds.height
+ (last_pos_y - geometry_bounds.y - geometry_bounds.height)
* animation_ease_function_up(i, 32));
animation_coordinates[ANIMATION_UP][ANIMATION_X][i] = last_pos_x;
animation_coordinates[ANIMATION_DOWN][ANIMATION_Y][i] =
(gint)(screen_height + (last_pos_y - screen_height) * animation_ease_function_down(i, 32));
(gint)(geometry_bounds.y + geometry_bounds.height
+ (last_pos_y - geometry_bounds.y - geometry_bounds.height)
* animation_ease_function_down(i, 32));
animation_coordinates[ANIMATION_DOWN][ANIMATION_X][i] = last_pos_x;
break;
case 0: /* top->bottom TOP */
default:
animation_coordinates[ANIMATION_UP][ANIMATION_Y][i] =
(gint)(-last_height + (last_pos_y - -last_height) * animation_ease_function_up(i, 32));
(gint)(geometry_bounds.y - last_height
+ (last_pos_y - geometry_bounds.y + last_height)
* animation_ease_function_up(i, 32));
animation_coordinates[ANIMATION_UP][ANIMATION_X][i] = last_pos_x;
animation_coordinates[ANIMATION_DOWN][ANIMATION_Y][i] =
(gint)(-last_height + (last_pos_y - -last_height) * animation_ease_function_down(i, 32));
(gint)(geometry_bounds.y - last_height
+ (last_pos_y - geometry_bounds.y + last_height)
* animation_ease_function_down(i, 32));
animation_coordinates[ANIMATION_DOWN][ANIMATION_X][i] = last_pos_x;
break;
}
Expand Down Expand Up @@ -434,4 +455,3 @@ void tilda_keygrabber_unbind (const gchar *keystr)


/* vim: set ts=4 sts=4 sw=4 expandtab: */

33 changes: 24 additions & 9 deletions src/tilda_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -1285,12 +1285,12 @@ gint tilda_window_find_centering_coordinate (tilda_window *tw,
enum dimensions dimension)
{
DEBUG_FUNCTION ("tilda_window_find_centering_coordinate");
DEBUG_ASSERT (tw != NULL);

gdouble monitor_dimension = 0;
gdouble tilda_dimension = 0;
GdkMonitor *monitor = tilda_window_find_monitor_number (tw);
GdkRectangle rectangle;
gdk_monitor_get_workarea (monitor, &rectangle);
config_get_configured_geometry_bounds (&rectangle);

GdkRectangle tilda_rectangle;
config_get_configured_window_size (&tilda_rectangle);
Expand Down Expand Up @@ -1352,26 +1352,41 @@ static gboolean update_tilda_window_size (gpointer user_data)
int windowHeight = gtk_widget_get_allocated_height (GTK_WIDGET (tw->window));
int windowWidth = gtk_widget_get_allocated_width (GTK_WIDGET (tw->window));

gint newWidth = windowWidth;
gint newHeight = windowHeight;

/* 2. Get the desired size and update the tilda window size if necessary. */
GdkRectangle configured_geometry;
config_get_configured_window_size (&configured_geometry);

if (configured_geometry.width - windowWidth >= 1) {
newWidth = configured_geometry.width;
}
gint newWidth = windowWidth;
gint newHeight = windowHeight;
if (config_getbool ("span_monitors")) {
GdkRectangle geometry_bounds;

if (configured_geometry.height - windowHeight >= 1) {
config_get_configured_geometry_bounds (&geometry_bounds);
config_setint ("x_pos", geometry_bounds.x);
config_setint ("y_pos", geometry_bounds.y);
newWidth = configured_geometry.width;
newHeight = configured_geometry.height;
} else {
if (configured_geometry.width - windowWidth >= 1) {
newWidth = configured_geometry.width;
}

if (configured_geometry.height - windowHeight >= 1) {
newHeight = configured_geometry.height;
}
}

gtk_window_resize (GTK_WINDOW (tw->window),
newWidth,
newHeight);

tilda_window_update_window_position (tw);
if (config_getbool ("span_monitors")) {
gtk_window_move (GTK_WINDOW (tw->window),
config_getint ("x_pos"),
config_getint ("y_pos"));
}
generate_animation_positions (tw);

/* 3. Returning G_SOURCE_REMOVE below will clear the event source in Gtk.
* Thus, we need to reset the ID such that a new event source can be
Expand Down
92 changes: 35 additions & 57 deletions src/wizard.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,6 @@ combo_monitor_selection_changed_cb (GtkWidget* widget, tilda_window *tw)
{
DEBUG_FUNCTION ("combo_monitor_selection_changed_cb");

GdkDisplay *display = gdk_display_get_default ();
GdkMonitor *original_monitor = tilda_window_find_monitor_number (tw);
GdkMonitor *new_monitor;

GdkRectangle original_monitor_rectangle;
GdkRectangle selected_monitor_rectangle;

gdk_monitor_get_workarea (original_monitor, &original_monitor_rectangle);

GtkTreeIter active_iter;

GtkComboBox* combo_choose_monitor = GTK_COMBO_BOX(widget);
Expand All @@ -298,61 +289,40 @@ combo_monitor_selection_changed_cb (GtkWidget* widget, tilda_window *tw)
return FALSE;
}

gchar* new_monitor_name = NULL;
gchar *new_monitor_name = NULL;
gint new_monitor_number;

gtk_tree_model_get(gtk_combo_box_get_model(combo_choose_monitor), &active_iter,
0, &new_monitor_name,
1, &new_monitor_number,
-1);

new_monitor = gdk_display_get_monitor (display, new_monitor_number);
gdk_monitor_get_workarea (new_monitor, &selected_monitor_rectangle);

//Save the new monitor value
config_setstr("show_on_monitor", new_monitor_name);

/* The dimensions of the monitor might have changed,
* so we need to update the spinner widgets for height,
* width, and their percentages as well as their ranges.
* Keep in mind that we use the max range of the pixel spinners
* to store the size of the screen.
*/
GdkRectangle rectangle;
config_get_configured_window_size (&rectangle);

if(selected_monitor_rectangle.width != original_monitor_rectangle.width)
{
gint new_max_width = selected_monitor_rectangle.width;

SPIN_BUTTON_SET_RANGE ("spin_width_pixels", 0, new_max_width);
SPIN_BUTTON_SET_VALUE ("spin_width_pixels", rectangle.width);
config_setbool ("span_monitors", new_monitor_number < 0);
if (new_monitor_number >= 0) {
GdkDisplay *display = gdk_display_get_default ();
GdkMonitor *monitor = gdk_display_get_monitor (display, new_monitor_number);
GdkRectangle monitor_workarea;

gtk_window_resize (GTK_WINDOW(tw->window),
rectangle.width,
rectangle.height);
config_setstr ("show_on_monitor", new_monitor_name);
gdk_monitor_get_workarea (monitor, &monitor_workarea);
config_setint ("x_pos", monitor_workarea.x);
config_setint ("y_pos", monitor_workarea.y);
}

if(selected_monitor_rectangle.height != original_monitor_rectangle.height)
{
int new_max_height = selected_monitor_rectangle.height;

SPIN_BUTTON_SET_RANGE ("spin_height_pixels", 0, new_max_height);
SPIN_BUTTON_SET_VALUE ("spin_height_pixels", rectangle.height);

gtk_window_resize (GTK_WINDOW(tw->window),
rectangle.width,
rectangle.height);
GdkRectangle geometry_bounds;
config_get_configured_geometry_bounds (&geometry_bounds);
if (new_monitor_number < 0) {
config_setint ("x_pos", geometry_bounds.x);
config_setint ("y_pos", geometry_bounds.y);
}
initialize_geometry_spinners (tw);

gint screen_width, screen_height;
screen_size_get_dimensions (&screen_width, &screen_height);
SPIN_BUTTON_SET_RANGE ("spin_x_position", 0, screen_width);
SPIN_BUTTON_SET_VALUE("spin_x_position", selected_monitor_rectangle.x);
SPIN_BUTTON_SET_RANGE ("spin_y_position", 0, screen_height);
SPIN_BUTTON_SET_VALUE("spin_y_position", selected_monitor_rectangle.y);
GdkRectangle rectangle;
config_get_configured_window_size (&rectangle);
gtk_window_resize (GTK_WINDOW (tw->window), rectangle.width, rectangle.height);

tilda_window_update_window_position (tw);
g_free (new_monitor_name);

return GDK_EVENT_STOP;
}
Expand Down Expand Up @@ -1752,6 +1722,15 @@ initialize_combo_choose_monitor(tilda_window *tw)

gtk_list_store_clear(monitor_model);

gtk_list_store_append(monitor_model, &iter);
gtk_list_store_set(monitor_model, &iter,
0, "",
1, -1,
2, _("All monitors"),
-1);
if (config_getbool ("span_monitors"))
gtk_combo_box_set_active_iter(combo_choose_monitor, &iter);

for (i = 0; i < num_monitors; i++) {
GdkMonitor *monitor;

Expand All @@ -1767,7 +1746,7 @@ initialize_combo_choose_monitor(tilda_window *tw)
2, display_name,
-1);

if(monitor == active_monitor) {
if(!config_getbool ("span_monitors") && monitor == active_monitor) {
gtk_combo_box_set_active_iter(combo_choose_monitor, &iter);
}

Expand All @@ -1785,12 +1764,11 @@ initialize_combo_choose_monitor(tilda_window *tw)
static void initialize_geometry_spinners(tilda_window *tw) {
DEBUG_FUNCTION ("initialize_geometry_spinners");

GdkMonitor *monitor = tilda_window_find_monitor_number(tw);
GdkRectangle rectangle;

gdk_monitor_get_workarea (monitor, &rectangle);
int monitor_height = rectangle.height;
int monitor_width = rectangle.width;
config_get_configured_geometry_bounds (&rectangle);
int geometry_height = rectangle.height;
int geometry_width = rectangle.width;

/* Update range and value of height spinners */
GdkRectangle tilda_rectangle;
Expand All @@ -1807,13 +1785,13 @@ static void initialize_geometry_spinners(tilda_window *tw) {

SPIN_BUTTON_SET_RANGE("spin_height_percentage", 0, 100);
SPIN_BUTTON_SET_VALUE ("spin_height_percentage", height_percentage);
SPIN_BUTTON_SET_RANGE("spin_height_pixels", 0, monitor_height);
SPIN_BUTTON_SET_RANGE("spin_height_pixels", 0, geometry_height);
SPIN_BUTTON_SET_VALUE("spin_height_pixels", height);

/* Update range and value of width spinners */
SPIN_BUTTON_SET_RANGE("spin_width_percentage", 0, 100);
SPIN_BUTTON_SET_VALUE ("spin_width_percentage", width_percentage);
SPIN_BUTTON_SET_RANGE("spin_width_pixels", 0, monitor_width);
SPIN_BUTTON_SET_RANGE("spin_width_pixels", 0, geometry_width);
SPIN_BUTTON_SET_VALUE("spin_width_pixels", width);

CHECK_BUTTON("check_centered_horizontally", "centered_horizontally");
Expand Down