From d1f315751d960f003317713a65cc480b3d0ee726 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 18 Apr 2022 09:21:45 +0800 Subject: [PATCH] Minor cleanups to PGTK code * src/gtkutil.c (xg_set_geometry): (xg_frame_set_char_size): (x_wm_set_size_hint): Rename to `xg_wm_set_size_hint'. All callers changed. * src/gtkutil.h: Update prototypes. * src/pgtkfns.c (unwind_create_frame): (Fx_create_frame): (compute_tip_xy): * src/pgtkterm.c (x_free_frame_resources): (x_destroy_window): (x_calc_absolute_position): (x_set_offset): (pgtk_set_window_size): (x_display_pixel_height): (x_display_pixel_width): (x_set_parent_frame): Rename `x_foo' functions to `pgtk_foo'. Get rid of some copy-pasted code from various places. (pgtk_create_terminal): Clean up coding style. * src/pgtkterm.h: Update prototypes. --- src/gtkutil.c | 14 ++++++++++++-- src/gtkutil.h | 4 +++- src/pgtkfns.c | 8 ++++---- src/pgtkterm.c | 42 +++++++++++++++++++++--------------------- src/pgtkterm.h | 14 ++++++-------- src/xterm.c | 6 ++++-- 6 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/gtkutil.c b/src/gtkutil.c index 718da171f49..a2ab01d02c5 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1061,6 +1061,7 @@ xg_set_geometry (struct frame *f) /* Handle negative positions without consulting gtk_window_parse_geometry (Bug#25851). The position will be off by scrollbar width + window manager decorations. */ +#ifndef HAVE_PGTK if (f->size_hint_flags & XNegative) f->left_pos = (x_display_pixel_width (FRAME_DISPLAY_INFO (f)) - FRAME_PIXEL_WIDTH (f) + f->left_pos); @@ -1068,6 +1069,15 @@ xg_set_geometry (struct frame *f) if (f->size_hint_flags & YNegative) f->top_pos = (x_display_pixel_height (FRAME_DISPLAY_INFO (f)) - FRAME_PIXEL_HEIGHT (f) + f->top_pos); +#else + if (f->size_hint_flags & XNegative) + f->left_pos = (pgtk_display_pixel_width (FRAME_DISPLAY_INFO (f)) + - FRAME_PIXEL_WIDTH (f) + f->left_pos); + + if (f->size_hint_flags & YNegative) + f->top_pos = (pgtk_display_pixel_height (FRAME_DISPLAY_INFO (f)) + - FRAME_PIXEL_HEIGHT (f) + f->top_pos); +#endif /* GTK works in scaled pixels, so convert from X pixels. */ gtk_window_move (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), @@ -1182,7 +1192,7 @@ xg_frame_set_char_size (struct frame *f, int width, int height) outer_height /= xg_get_scale (f); outer_width /= xg_get_scale (f); - x_wm_set_size_hint (f, 0, 0); + xg_wm_set_size_hint (f, 0, 0); /* Resize the top level widget so rows and columns remain constant. @@ -1898,7 +1908,7 @@ xg_free_frame_widgets (struct frame *f) flag (this is useful when FLAGS is 0). */ void -x_wm_set_size_hint (struct frame *f, long int flags, bool user_position) +xg_wm_set_size_hint (struct frame *f, long int flags, bool user_position) { /* Must use GTK routines here, otherwise GTK resets the size hints to its own defaults. */ diff --git a/src/gtkutil.h b/src/gtkutil.h index 63ecac07907..190d6628314 100644 --- a/src/gtkutil.h +++ b/src/gtkutil.h @@ -153,6 +153,8 @@ extern bool xg_event_is_for_scrollbar (struct frame *, const EVENT *, extern int xg_get_default_scrollbar_width (struct frame *f); extern int xg_get_default_scrollbar_height (struct frame *f); +extern void xg_wm_set_size_hint (struct frame *, long int, bool); + extern void update_frame_tool_bar (struct frame *f); extern void free_frame_tool_bar (struct frame *f); extern void xg_change_toolbar_position (struct frame *f, Lisp_Object pos); @@ -222,7 +224,7 @@ extern bool xg_is_menu_window (Display *dpy, Window); extern bool xg_filter_key (struct frame *frame, XEvent *xkey); #endif -/* Mark all callback data that are Lisp_object:s during GC. */ +/* Mark all callback data that are Lisp_Objects during GC. */ extern void xg_mark_data (void); /* Initialize GTK specific parts. */ diff --git a/src/pgtkfns.c b/src/pgtkfns.c index e677f046299..1cab954a076 100644 --- a/src/pgtkfns.c +++ b/src/pgtkfns.c @@ -1053,7 +1053,7 @@ unwind_create_frame (Lisp_Object frame) && FRAME_IMAGE_CACHE (f)->refcount == image_cache_refcount) FRAME_IMAGE_CACHE (f)->refcount++; - x_free_frame_resources (f); + pgtk_free_frame_resources (f); free_glyphs (f); return Qt; } @@ -1692,7 +1692,7 @@ This function is an internal primitive--use `make-frame' instead. */ ) badly we want them. This should be done after we have the menu bar so that its size can be taken into account. */ block_input (); - x_wm_set_size_hint (f, window_prompting, false); + xg_wm_set_size_hint (f, window_prompting, false); unblock_input (); adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), @@ -3026,8 +3026,8 @@ compute_tip_xy (struct frame *f, Lisp_Object parms, Lisp_Object dx, { min_x = 0; min_y = 0; - max_x = x_display_pixel_width (FRAME_DISPLAY_INFO (f)); - max_y = x_display_pixel_height (FRAME_DISPLAY_INFO (f)); + max_x = pgtk_display_pixel_width (FRAME_DISPLAY_INFO (f)); + max_y = pgtk_display_pixel_height (FRAME_DISPLAY_INFO (f)); } if (INTEGERP (top)) diff --git a/src/pgtkterm.c b/src/pgtkterm.c index a59abba625a..2b04699fb32 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -410,7 +410,7 @@ pgtk_frame_raise_lower (struct frame *f, bool raise_flag) /* Free X resources of frame F. */ void -x_free_frame_resources (struct frame *f) +pgtk_free_frame_resources (struct frame *f) { struct pgtk_display_info *dpyinfo; Mouse_HLInfo *hlinfo; @@ -511,7 +511,7 @@ x_free_frame_resources (struct frame *f) } void -x_destroy_window (struct frame *f) +pgtk_destroy_window (struct frame *f) /* -------------------------------------------------------------------------- External: Delete the window -------------------------------------------------------------------------- */ @@ -520,7 +520,7 @@ x_destroy_window (struct frame *f) check_window_system (f); if (dpyinfo->gdpy != NULL) - x_free_frame_resources (f); + pgtk_free_frame_resources (f); dpyinfo->reference_count--; } @@ -529,7 +529,7 @@ x_destroy_window (struct frame *f) from its current recorded position values and gravity. */ static void -x_calc_absolute_position (struct frame *f) +pgtk_calc_absolute_position (struct frame *f) { int flags = f->size_hint_flags; struct frame *p = FRAME_PARENT_FRAME (f); @@ -563,7 +563,7 @@ x_calc_absolute_position (struct frame *f) f->left_pos = (FRAME_PIXEL_WIDTH (p) - width - 2 * f->border_width + f->left_pos); else - f->left_pos = (x_display_pixel_width (FRAME_DISPLAY_INFO (f)) + f->left_pos = (pgtk_display_pixel_width (FRAME_DISPLAY_INFO (f)) - width + f->left_pos); } @@ -589,7 +589,7 @@ x_calc_absolute_position (struct frame *f) f->top_pos = (FRAME_PIXEL_HEIGHT (p) - height - 2 * f->border_width + f->top_pos); else - f->top_pos = (x_display_pixel_height (FRAME_DISPLAY_INFO (f)) + f->top_pos = (pgtk_display_pixel_height (FRAME_DISPLAY_INFO (f)) - height + f->top_pos); } @@ -620,18 +620,16 @@ pgtk_set_offset (struct frame *f, int xoff, int yoff, int change_gravity) f->win_gravity = NorthWestGravity; } - x_calc_absolute_position (f); + pgtk_calc_absolute_position (f); block_input (); - x_wm_set_size_hint (f, 0, false); + xg_wm_set_size_hint (f, 0, false); if (change_gravity != 0) { if (FRAME_GTK_OUTER_WIDGET (f)) - { - gtk_window_move (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - f->left_pos, f->top_pos); - } + gtk_window_move (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), + f->left_pos, f->top_pos); else { GtkWidget *fixed = FRAME_GTK_WIDGET (f); @@ -672,7 +670,7 @@ pgtk_set_window_size (struct frame *f, bool change_gravity, f->output_data.pgtk->preferred_width = pixelwidth; f->output_data.pgtk->preferred_height = pixelheight; - x_wm_set_size_hint (f, 0, 0); + xg_wm_set_size_hint (f, 0, 0); xg_frame_set_char_size (f, pixelwidth, pixelheight); gtk_widget_queue_resize (FRAME_WIDGET (f)); @@ -881,18 +879,20 @@ pgtk_new_font (struct frame *f, Lisp_Object font_object, int fontset) } int -x_display_pixel_height (struct pgtk_display_info *dpyinfo) +pgtk_display_pixel_height (struct pgtk_display_info *dpyinfo) { GdkDisplay *gdpy = dpyinfo->gdpy; GdkScreen *gscr = gdk_display_get_default_screen (gdpy); + return gdk_screen_get_height (gscr); } int -x_display_pixel_width (struct pgtk_display_info *dpyinfo) +pgtk_display_pixel_width (struct pgtk_display_info *dpyinfo) { GdkDisplay *gdpy = dpyinfo->gdpy; GdkScreen *gscr = gdk_display_get_default_screen (gdpy); + return gdk_screen_get_width (gscr); } @@ -962,7 +962,7 @@ pgtk_set_parent_frame (struct frame *f, Lisp_Object new_value, gtk_box_pack_start (GTK_BOX (f->output_data.pgtk->hbox_widget), fixed, TRUE, TRUE, 0); f->output_data.pgtk->preferred_width = alloc.width; f->output_data.pgtk->preferred_height = alloc.height; - x_wm_set_size_hint (f, 0, 0); + xg_wm_set_size_hint (f, 0, 0); xg_frame_set_char_size (f, FRAME_PIXEL_TO_TEXT_WIDTH (f, alloc.width), FRAME_PIXEL_TO_TEXT_HEIGHT (f, alloc.height)); gtk_widget_queue_resize (FRAME_WIDGET (f)); @@ -4860,7 +4860,7 @@ pgtk_create_terminal (struct pgtk_display_info *dpyinfo) terminal->redeem_scroll_bar_hook = pgtk_redeem_scroll_bar; terminal->judge_scroll_bars_hook = pgtk_judge_scroll_bars; terminal->get_string_resource_hook = pgtk_get_string_resource; - terminal->delete_frame_hook = x_destroy_window; + terminal->delete_frame_hook = pgtk_destroy_window; terminal->delete_terminal_hook = pgtk_delete_terminal; terminal->query_frame_background_color = pgtk_query_frame_background_color; terminal->defined_color_hook = pgtk_defined_color; @@ -4868,10 +4868,10 @@ pgtk_create_terminal (struct pgtk_display_info *dpyinfo) terminal->set_bitmap_icon_hook = pgtk_bitmap_icon; terminal->implicit_set_name_hook = pgtk_implicitly_set_name; terminal->iconify_frame_hook = pgtk_iconify_frame; - terminal->set_scroll_bar_default_width_hook = - pgtk_set_scroll_bar_default_width; - terminal->set_scroll_bar_default_height_hook = - pgtk_set_scroll_bar_default_height; + terminal->set_scroll_bar_default_width_hook + = pgtk_set_scroll_bar_default_width; + terminal->set_scroll_bar_default_height_hook + = pgtk_set_scroll_bar_default_height; terminal->set_window_size_hook = pgtk_set_window_size; terminal->query_colors = pgtk_query_colors; terminal->get_focus_frame = x_get_focus_frame; diff --git a/src/pgtkterm.h b/src/pgtkterm.h index cc763f00f0c..16fd688288e 100644 --- a/src/pgtkterm.h +++ b/src/pgtkterm.h @@ -62,9 +62,9 @@ struct pgtk_device_t #define ARGB_TO_ULONG(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) #define ALPHA_FROM_ULONG(color) ((color) >> 24) -#define RED_FROM_ULONG(color) (((color) >> 16) & 0xff) +#define RED_FROM_ULONG(color) (((color) >> 16) & 0xff) #define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff) -#define BLUE_FROM_ULONG(color) ((color) & 0xff) +#define BLUE_FROM_ULONG(color) ((color) & 0xff) struct scroll_bar { @@ -518,11 +518,10 @@ extern void pgtk_clear_under_internal_border (struct frame *f); extern void pgtk_set_event_handler (struct frame *f); /* Implemented in pgtkterm.c */ -extern int x_display_pixel_height (struct pgtk_display_info *); -extern int x_display_pixel_width (struct pgtk_display_info *); +extern int pgtk_display_pixel_height (struct pgtk_display_info *); +extern int pgtk_display_pixel_width (struct pgtk_display_info *); -/* Implemented in pgtkterm.c */ -extern void x_destroy_window (struct frame *f); +extern void pgtk_destroy_window (struct frame *f); extern void pgtk_set_parent_frame (struct frame *f, Lisp_Object, Lisp_Object); extern void pgtk_set_no_focus_on_map (struct frame *, Lisp_Object, Lisp_Object); extern void pgtk_set_no_accept_focus (struct frame *, Lisp_Object, Lisp_Object); @@ -562,8 +561,7 @@ extern void pgtk_delete_terminal (struct terminal *terminal); extern void pgtk_make_frame_visible (struct frame *f); extern void pgtk_make_frame_invisible (struct frame *f); -extern void x_wm_set_size_hint (struct frame *, long, bool); -extern void x_free_frame_resources (struct frame *); +extern void pgtk_free_frame_resources (struct frame *); extern void pgtk_iconify_frame (struct frame *f); extern void pgtk_focus_frame (struct frame *f, bool noactivate); extern void pgtk_set_scroll_bar_default_width (struct frame *f); diff --git a/src/xterm.c b/src/xterm.c index e00b38a6817..2e905b57990 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -22000,10 +22000,10 @@ x_destroy_window (struct frame *f) flag (this is useful when FLAGS is 0). The GTK version is in gtkutils.c. */ -#ifndef USE_GTK void x_wm_set_size_hint (struct frame *f, long flags, bool user_position) { +#ifndef USE_GTK XSizeHints size_hints; Window window = FRAME_OUTER_WINDOW (f); #ifdef USE_X_TOOLKIT @@ -22160,8 +22160,10 @@ x_wm_set_size_hint (struct frame *f, long flags, bool user_position) #endif /* PWinGravity */ XSetWMNormalHints (FRAME_X_DISPLAY (f), window, &size_hints); +#else + xg_wm_set_size_size_hint (f, flags, user_position); +#endif /* USE_GTK */ } -#endif /* not USE_GTK */ /* Used for IconicState or NormalState */ -- 2.39.2