Fix vte padding calculations.
Sometimes we only care about left and top offsets. get_vte_padding is currently returning left + right and top + bottom, leading to check_match miscalculating its offsets. Closes #162
This commit is contained in:
		
							parent
							
								
									4e6a393d6c
								
							
						
					
					
						commit
						2bf484277b
					
				
							
								
								
									
										36
									
								
								termite.cc
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								termite.cc
									
									
									
									
									
								
							@ -121,7 +121,7 @@ static gboolean focus_cb(GtkWindow *window);
 | 
				
			|||||||
static GtkTreeModel *create_completion_model(VteTerminal *vte);
 | 
					static GtkTreeModel *create_completion_model(VteTerminal *vte);
 | 
				
			||||||
static void search(VteTerminal *vte, const char *pattern, bool reverse);
 | 
					static void search(VteTerminal *vte, const char *pattern, bool reverse);
 | 
				
			||||||
static void overlay_show(search_panel_info *info, overlay_mode mode, VteTerminal *vte);
 | 
					static void overlay_show(search_panel_info *info, overlay_mode mode, VteTerminal *vte);
 | 
				
			||||||
static void get_vte_padding(VteTerminal *vte, int *w, int *h);
 | 
					static void get_vte_padding(VteTerminal *vte, int *left, int *top, int *right, int *bottom);
 | 
				
			||||||
static char *check_match(VteTerminal *vte, int event_x, int event_y);
 | 
					static char *check_match(VteTerminal *vte, int event_x, int event_y);
 | 
				
			||||||
static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info,
 | 
					static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info,
 | 
				
			||||||
                        char **geometry);
 | 
					                        char **geometry);
 | 
				
			||||||
@ -1079,25 +1079,30 @@ void overlay_show(search_panel_info *info, overlay_mode mode, VteTerminal *vte)
 | 
				
			|||||||
    gtk_widget_grab_focus(info->entry);
 | 
					    gtk_widget_grab_focus(info->entry);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void get_vte_padding(VteTerminal *vte, int *w, int *h) {
 | 
					void get_vte_padding(VteTerminal *vte, int *left, int *top, int *right, int *bottom) {
 | 
				
			||||||
    GtkBorder *border = nullptr;
 | 
					    GtkBorder *border = nullptr;
 | 
				
			||||||
    gtk_widget_style_get(GTK_WIDGET(vte), "inner-border", &border, nullptr);
 | 
					    gtk_widget_style_get(GTK_WIDGET(vte), "inner-border", &border, nullptr);
 | 
				
			||||||
    if (!border) {
 | 
					    if (!border) {
 | 
				
			||||||
        g_warning("VTE's inner-border property unavailable");
 | 
					        g_warning("VTE's inner-border property unavailable");
 | 
				
			||||||
        *w = *h = 0;
 | 
					        *left = *top = *right = *bottom = 0;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        *w = border->left + border->right;
 | 
					        *left = border->left;
 | 
				
			||||||
        *h = border->top + border->bottom;
 | 
					        *right = border->right;
 | 
				
			||||||
 | 
					        *top = border->top;
 | 
				
			||||||
 | 
					        *bottom = border->bottom;
 | 
				
			||||||
        gtk_border_free(border);
 | 
					        gtk_border_free(border);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *check_match(VteTerminal *vte, int event_x, int event_y) {
 | 
					char *check_match(VteTerminal *vte, int event_x, int event_y) {
 | 
				
			||||||
    int xpad, ypad, tag;
 | 
					    int tag, padding_left, padding_top, padding_right, padding_bottom;
 | 
				
			||||||
    get_vte_padding(vte, &xpad, &ypad);
 | 
					    const long char_width = vte_terminal_get_char_width(vte);
 | 
				
			||||||
 | 
					    const long char_height = vte_terminal_get_char_height(vte);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    get_vte_padding(vte, &padding_left, &padding_top, &padding_right, &padding_bottom);
 | 
				
			||||||
    return vte_terminal_match_check(vte,
 | 
					    return vte_terminal_match_check(vte,
 | 
				
			||||||
                                    (event_x - ypad) / vte_terminal_get_char_width(vte),
 | 
					                                    (event_x - padding_left) / char_width,
 | 
				
			||||||
                                    (event_y - ypad) / vte_terminal_get_char_height(vte),
 | 
					                                    (event_y - padding_top) / char_height,
 | 
				
			||||||
                                    &tag);
 | 
					                                    &tag);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1540,14 +1545,15 @@ int main(int argc, char **argv) {
 | 
				
			|||||||
        return EXIT_FAILURE;
 | 
					        return EXIT_FAILURE;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int width, height, padding_w, padding_h;
 | 
					    int width, height, padding_left, padding_top, padding_right, padding_bottom;
 | 
				
			||||||
    long char_width = vte_terminal_get_char_width(vte);
 | 
					    const long char_width = vte_terminal_get_char_width(vte);
 | 
				
			||||||
    long char_height = vte_terminal_get_char_height(vte);
 | 
					    const long char_height = vte_terminal_get_char_height(vte);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    gtk_window_get_size(GTK_WINDOW(window), &width, &height);
 | 
					    gtk_window_get_size(GTK_WINDOW(window), &width, &height);
 | 
				
			||||||
    get_vte_padding(vte, &padding_w, &padding_h);
 | 
					    get_vte_padding(vte, &padding_left, &padding_top, &padding_right, &padding_bottom);
 | 
				
			||||||
    vte_terminal_set_size(vte, (width - padding_w) / char_width,
 | 
					    vte_terminal_set_size(vte,
 | 
				
			||||||
                          (height - padding_h) / char_height);
 | 
					                          (width - padding_left - padding_right) / char_width,
 | 
				
			||||||
 | 
					                          (height - padding_top - padding_bottom) / char_height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    g_strfreev(env);
 | 
					    g_strfreev(env);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user