Skip to content

Commit

Permalink
Make the possibility to show Tilda on the mouse cursor screen
Browse files Browse the repository at this point in the history
configurable

A new feature allows Tilda to be shown on the monitor on which the
mouse cursor is. This commit enables this feature to be toggled
via the wizard.
This feature is disabled by default.
  • Loading branch information
weyfonk committed Aug 17, 2016
1 parent 47f2043 commit 1894fd0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 43 deletions.
1 change: 1 addition & 0 deletions src/configsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,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("show_on_mouse_monitor", FALSE, CFGF_NONE),

/* Config settings for VTE-2.90 features */
CFG_STR("image", NULL, CFGF_NODEFAULT),
Expand Down
68 changes: 36 additions & 32 deletions src/key_grabber.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,40 +150,44 @@ void tilda_window_set_active (tilda_window *tw)
DEBUG_FUNCTION ("tilda_window_set_active");
DEBUG_ASSERT (tw != NULL);

gint mouse_x, mouse_y;
GdkDisplay *disp = gdk_display_get_default ();
GdkDeviceManager *device_manager = gdk_display_get_device_manager (disp);
GdkDevice *device = gdk_device_manager_get_client_pointer (device_manager);

/* Get the number of the monitor the mouse cursor is currently on */
GdkScreen *screen = gtk_widget_get_screen (tw->window);
gdk_device_get_position (device, &screen, &mouse_x, &mouse_y);
gint mouse_monitor = gdk_screen_get_monitor_at_point (screen, mouse_x, mouse_y);

/* Get the monitor number on which the window is currently shown
* Idea: get the configured window position relatively to the configured
* monitor on which Tilda usually appears, and apply the same position
* on the monitor the mouse cursor is currently on */
int config_monitor = find_monitor_number (tw);
if (config_monitor != mouse_monitor) {
gint window_x, window_y;
GdkRectangle* config_monitor_rect = malloc (sizeof (GdkRectangle));
GdkRectangle* mouse_monitor_rect = malloc (sizeof (GdkRectangle));;
gdk_screen_get_monitor_workarea (screen, config_monitor, config_monitor_rect);
gdk_screen_get_monitor_workarea (screen, mouse_monitor, mouse_monitor_rect);

gint x_offset,y_offset;
x_offset = config_getint ("x_pos") - config_monitor_rect->x;
y_offset = config_getint ("y_pos") - config_monitor_rect->y;
window_x = mouse_monitor_rect->x + x_offset;
window_y = mouse_monitor_rect->y + y_offset;

free (config_monitor_rect);
free (mouse_monitor_rect);
gtk_window_move (GTK_WINDOW(tw->window), window_x, window_y);

gboolean show_on_nondefault_screen = FALSE;
if (config_getbool("show_on_mouse_monitor")) {
gint mouse_x, mouse_y;
GdkDisplay *disp = gdk_display_get_default ();
GdkDeviceManager *device_manager = gdk_display_get_device_manager (disp);
GdkDevice *device = gdk_device_manager_get_client_pointer (device_manager);

/* Get the number of the monitor the mouse cursor is currently on */
gdk_device_get_position (device, &screen, &mouse_x, &mouse_y);
gint mouse_monitor = gdk_screen_get_monitor_at_point (screen, mouse_x, mouse_y);

/* Get the monitor number on which the window is currently shown
* Idea: get the configured window position relatively to the configured
* monitor on which Tilda usually appears, and apply the same position
* on the monitor the mouse cursor is currently on */
int config_monitor = find_monitor_number (tw);
if (config_monitor != mouse_monitor) {
gint window_x, window_y;
GdkRectangle* config_monitor_rect = malloc (sizeof (GdkRectangle));
GdkRectangle* mouse_monitor_rect = malloc (sizeof (GdkRectangle));;
gdk_screen_get_monitor_workarea (screen, config_monitor, config_monitor_rect);
gdk_screen_get_monitor_workarea (screen, mouse_monitor, mouse_monitor_rect);

gint x_offset,y_offset;
x_offset = config_getint ("x_pos") - config_monitor_rect->x;
y_offset = config_getint ("y_pos") - config_monitor_rect->y;
window_x = mouse_monitor_rect->x + x_offset;
window_y = mouse_monitor_rect->y + y_offset;

free (config_monitor_rect);
free (mouse_monitor_rect);
gtk_window_move (GTK_WINDOW(tw->window), window_x, window_y);
show_on_nondefault_screen = TRUE;
}
}
else
{
if (!show_on_nondefault_screen) {
gtk_window_move (GTK_WINDOW(tw->window), config_getint ("x_pos"), config_getint ("y_pos"));
}

Expand Down
22 changes: 11 additions & 11 deletions src/tilda.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.19.0 -->
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkAdjustment" id="adjustment1">
Expand Down Expand Up @@ -1573,24 +1573,24 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="label30">
<object class="GtkCheckButton" id="check_show_on_mouse_monitor">
<property name="label" translatable="yes">Show on mouse monitor</property>
<property name="use_action_appearance">True</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="check_show_on_mouse_monitor_toggled_cb" swapped="no"/>
</object>
<packing>
<property name="left_attach">3</property>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label31">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
</packing>
<placeholder/>
</child>
</object>
</child>
Expand Down
12 changes: 12 additions & 0 deletions src/wizard.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,15 @@ static void wizard_hide_deprecated_options(void) {
}
#endif

static void check_show_on_mouse_monitor_toggled_cb(GtkWidget *w, tilda_window *tw) {
const gboolean show_on_mouse_monitor = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
const GtkWidget *combo_choose_monitor =
GTK_WIDGET (gtk_builder_get_object (xml, "combo_choose_monitor"));

config_setbool ("show_on_mouse_monitor", show_on_mouse_monitor);
gtk_widget_set_sensitive (GTK_WIDGET(combo_choose_monitor), !show_on_mouse_monitor);
}

/*
* Finds the coordinate that will center the tilda window in the screen.
*
Expand Down Expand Up @@ -2292,11 +2301,13 @@ static void set_wizard_state_from_config (tilda_window *tw) {


initialize_geometry_spinners(tw);
CHECK_BUTTON ("check_show_on_mouse_monitor", "show_on_mouse_monitor");
CHECK_BUTTON ("check_enable_transparency", "enable_transparency");
CHECK_BUTTON ("check_animated_pulldown", "animation");
SPIN_BUTTON ("spin_animation_delay", "slide_sleep_usec");
COMBO_BOX ("combo_animation_orientation", "animation_orientation");

SET_SENSITIVE_BY_CONFIG_NBOOL ("combo_choose_monitor", "show_on_mouse_monitor");
SET_SENSITIVE_BY_CONFIG_BOOL ("label_level_of_transparency","enable_transparency");
SET_SENSITIVE_BY_CONFIG_BOOL ("spin_level_of_transparency","enable_transparency");
SET_SENSITIVE_BY_CONFIG_BOOL ("label_animation_delay","animation");
Expand Down Expand Up @@ -2473,6 +2484,7 @@ static void connect_wizard_signals (tilda_window *tw)

/* Appearance Tab */
CONNECT_SIGNAL ("combo_choose_monitor", "changed", combo_monitor_selection_changed_cb, tw);
CONNECT_SIGNAL ("check_show_on_mouse_monitor", "toggled", check_show_on_mouse_monitor_toggled_cb, tw);
CONNECT_SIGNAL ("spin_height_percentage","value-changed",spin_height_percentage_value_changed_cb, tw);
CONNECT_SIGNAL ("spin_height_pixels","value-changed",spin_height_pixels_value_changed_cb, tw);
CONNECT_SIGNAL ("spin_width_percentage","value-changed",spin_width_percentage_value_changed_cb, tw);
Expand Down

0 comments on commit 1894fd0

Please sign in to comment.