summaryrefslogtreecommitdiff
path: root/src/gtkutil.c
diff options
context:
space:
mode:
authorYuuki Harano <masm@masm11.ddo.jp>2017-10-28 16:16:29 +0900
committerJeff Walsh <fejfighter@gmail.com>2020-11-22 14:46:55 +1100
commitf6d8c5939bff5b5baf46578718999e06061e26ff (patch)
tree74b69d2afb55da82c4edcfbcfd8ce31ea5af7f18 /src/gtkutil.c
parent2c7687738d0b7da60014a7af05ab199936617d71 (diff)
downloademacs-f6d8c5939bff5b5baf46578718999e06061e26ff.tar.gz
Introduce Pure GTK3 port
* src/xsettings.h: * src/xsettings.c: (dpyinfo_valid, store_tool_bar_style_changed) (XSETTINGS_FONT_NAME, get_prop_window, read_settings) (apply_xft_settings, read_and_apply_settings) (xft_settings_event, init_xsettings, xsettings_initialize): * src/xfaces.c: (x_create_gc, x_free_gc): * src/xdisp.c (redisplay_tool_bar, redisplay_internal) (draw_glyphs_debug, draw_glyphs, mouse_face_from_buffer_pos) (note_mouse_highlight): * src/terminal.c (Fterminal_live_p): * src/termhooks.h (enum output_method, GCALIGNED_STRUCT) (TERMINAL_FONT_CACHE): * src/process.c (wait_reading_process_output): * src/pgtkterm.h: * src/pgtkterm.c: * src/pgtkselect.h: * src/pgtkselect.c: * src/pgtkgui.h: * src/pgtkfns.c: * src/image.c: (XGetPixel, XPutPixel, image_create_bitmap_from_data) (image_create_bitmap_from_file, free_bitmap_record) (image_destroy_x_image, gui_put_x_image, image_get_x_image) (Create_Pixmap_From_Bitmap_Data, xbm_load_image, ) (xpm_load_image, lookup_rgb_color, image_disable_image) (image_build_heuristic_mask, imagemagick_load_image): * src/gtkutil.h: * src/gtkutil.c (PGTK_TRACE, xg_set_screen, xg_display_open) (xg_display_close, xg_create_default_cursor) (xg_get_pixbuf_from_pix_and_mask, xg_check_special_colors) (qttip_cb, hierarchy_ch_cb, xg_prepare_tooltip, ) (xg_show_tooltip, xg_hide_tooltip, xg_frame_resized) (xg_frame_set_char_size, xg_height_or_width_changed) (xg_set_widget_bg, style_changed_cb, xg_create_frame_widgets) (xg_free_frame_widgets, x_wm_set_size_hint, xg_frame_restack) (xg_mark_data, xg_update_frame_menubar, free_frame_menubar) (xg_update_submenu, xg_finish_scroll_bar_creation) (xg_update_scrollbar_pos, xg_update_horizontal_scrollbar_pos) (xg_set_toolkit_scroll_bar_thumb, xg_event_is_for_scrollbar) (draw_page, xg_pack_tool_bar, xg_create_tool_bar) (xg_update_tool_bar_sizes, update_frame_tool_bar) (free_frame_tool_bar, xg_change_toolbar_position): * src/ftcrfont.c: (ftcrfont_draw): * src/fringe.c: (init_fringe_bitmap): * src/frame.h (GCALIGNED_STRUCT, FRAME_WINDOW_P): * src/frame.c (Fframep): * src/font.h: * src/font.c (syms_of_font): * src/emacsgtkfixed.c: (emacs_fixed_get_preferred_width) (emacs_fixed_get_preferred_height, XSetWMSizeHints): * src/emacs.c (main): * src/dispnew.c (init_display_interactive): * src/dispextern.h: * src/alloc.c: (garbage_collect): * src/Makefile.in (PGTK_OBJ, PGTK_LIBS, base_obj, LIBES): * src/.gdbinit: * lisp/url/url-privacy.el (url-setup-privacy-info): * lisp/term/pgtk-win.el (featurep): * lisp/startup.el (command-line, fancy-splash-frame): * lisp/net/eww.el (eww-form-submit, eww-form-file) (eww-form-checkbox, eww-form-select): * lisp/mwheel.el (mouse-wheel-down-event, mouse-wheel-up-event): * lisp/loadup.el (featurep): * lisp/international/mule-cmds.el (set-coding-system-map): * lisp/frame.el (pgtk-frame-geometry, frame-geometry) (w32-frame-edges, frame-edges) (pgtk-mouse-absolute-pixel-position) (mouse-absolute-pixel-position) (pgtk-set-mouse-absolute-pixel-position) (pgtk-frame-list-z-order, frame-list-z-order) (pgtk-frame-restack, frame-restack, display-mouse-p) (display-graphic-p, display-symbol-keys-p, ) (display-pixel-height, display-mm-height, display-mm-width) (display-backing-store, display-save-under, display-color-cells) (display-planes, display-visual-class) (pgtk-display-monitor-attributes-list) (display-monitor-attributes-list): * lisp/faces.el (face-spec-set-match-display, tool-bar): * lisp/cus-edit.el (custom-button, custom-button-mouse) (custom-button-pressed, custom-display): * configure.ac (AUTO_DEPEND, XARGS_LIMIT, XWIDGETS_OBJ):
Diffstat (limited to 'src/gtkutil.c')
-rw-r--r--src/gtkutil.c327
1 files changed, 280 insertions, 47 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c
index fafd94c0f71..b7a397bf435 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -26,7 +26,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
-#ifdef USE_GTK
+#if defined(USE_GTK)
#include <float.h>
#include <stdio.h>
#include <stdlib.h>
@@ -37,13 +37,24 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include "dispextern.h"
#include "frame.h"
#include "systime.h"
+#ifndef HAVE_PGTK
#include "xterm.h"
+#define xp x
+typedef struct x_output xp_output;
+#else
+#define xp pgtk
+typedef struct pgtk_output xp_output;
+#endif
#include "blockinput.h"
#include "window.h"
#include "gtkutil.h"
#include "termhooks.h"
#include "keyboard.h"
#include "coding.h"
+#ifndef PGTK_TRACE
+#define PGTK_TRACE(fmt, ...) ((void) 0)
+#define PGTK_BACKTRACE() ((void) 0)
+#endif
#include <gdk/gdkkeysyms.h>
@@ -52,7 +63,9 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#endif
#ifdef HAVE_GTK3
+#ifndef HAVE_PGTK
#include <gtk/gtkx.h>
+#endif
#include "emacsgtkfixed.h"
#endif
@@ -129,6 +142,7 @@ static GdkDisplay *gdpy_def;
static void
xg_set_screen (GtkWidget *w, struct frame *f)
{
+#ifndef HAVE_PGTK
if (FRAME_X_DISPLAY (f) != DEFAULT_GDK_DISPLAY ())
{
GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
@@ -139,6 +153,17 @@ xg_set_screen (GtkWidget *w, struct frame *f)
else
gtk_window_set_screen (GTK_WINDOW (w), gscreen);
}
+#else
+ if (FRAME_X_DISPLAY(f) != DEFAULT_GDK_DISPLAY ())
+ {
+ GdkScreen *gscreen = gdk_display_get_default_screen (FRAME_X_DISPLAY(f));
+
+ if (GTK_IS_MENU (w))
+ gtk_menu_set_screen (GTK_MENU (w), gscreen);
+ else
+ gtk_window_set_screen (GTK_WINDOW (w), gscreen);
+ }
+#endif
}
@@ -150,12 +175,20 @@ xg_set_screen (GtkWidget *w, struct frame *f)
multiple displays. */
void
+#ifndef HAVE_PGTK
xg_display_open (char *display_name, Display **dpy)
+#else
+xg_display_open (char *display_name, GdkDisplay **dpy)
+#endif
{
GdkDisplay *gdpy;
unrequest_sigio (); /* See comment in x_display_ok, xterm.c. */
+#ifndef HAVE_PGTK
gdpy = gdk_display_open (display_name);
+#else
+ gdpy = gdk_display_open (strlen(display_name) == 0 ? NULL : display_name);
+#endif
request_sigio ();
if (!gdpy_def && gdpy)
{
@@ -164,7 +197,11 @@ xg_display_open (char *display_name, Display **dpy)
gdpy);
}
+#ifndef HAVE_PGTK
*dpy = gdpy ? GDK_DISPLAY_XDISPLAY (gdpy) : NULL;
+#else
+ *dpy = gdpy;
+#endif
}
/* Scaling/HiDPI functions. */
@@ -196,8 +233,13 @@ xg_get_scale (struct frame *f)
/* Close display DPY. */
void
+#ifndef HAVE_PGTK
xg_display_close (Display *dpy)
+#else
+xg_display_close (GdkDisplay *gdpy)
+#endif
{
+#ifndef HAVE_PGTK
GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (dpy);
/* If this is the default display, try to change it before closing.
@@ -221,6 +263,31 @@ xg_display_close (Display *dpy)
}
gdk_display_close (gdpy);
+
+#else
+
+ /* If this is the default display, try to change it before closing.
+ If there is no other display to use, gdpy_def is set to NULL, and
+ the next call to xg_display_open resets the default display. */
+ if (gdk_display_get_default () == gdpy)
+ {
+ struct pgtk_display_info *dpyinfo;
+ GdkDisplay *gdpy_new = NULL;
+
+ /* Find another display. */
+ for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
+ if (dpyinfo->gdpy != gdpy)
+ {
+ gdpy_new = dpyinfo->gdpy;
+ gdk_display_manager_set_default_display (gdk_display_manager_get (),
+ gdpy_new);
+ break;
+ }
+ gdpy_def = gdpy_new;
+ }
+
+ gdk_display_close (gdpy);
+#endif
}
@@ -232,12 +299,19 @@ xg_display_close (Display *dpy)
scroll bars on display DPY. */
GdkCursor *
+#ifndef HAVE_PGTK
xg_create_default_cursor (Display *dpy)
+#else
+xg_create_default_cursor (GdkDisplay *gdpy)
+#endif
{
+#ifndef HAVE_PGTK
GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (dpy);
+#endif
return gdk_cursor_new_for_display (gdpy, GDK_LEFT_PTR);
}
+#ifndef HAVE_PGTK
/* Apply GMASK to GPIX and return a GdkPixbuf with an alpha channel. */
static GdkPixbuf *
@@ -250,8 +324,10 @@ xg_get_pixbuf_from_pix_and_mask (struct frame *f,
Window wunused;
unsigned int width, height, depth, uunused;
+#ifndef HAVE_PGTK
if (FRAME_DISPLAY_INFO (f)->red_bits != 8)
return 0;
+#endif
XGetGeometry (FRAME_X_DISPLAY (f), pix, &wunused, &iunused, &iunused,
&width, &height, &uunused, &depth);
if (depth != 24)
@@ -286,6 +362,7 @@ xg_get_pixbuf_from_pix_and_mask (struct frame *f,
return icon_buf;
}
+#endif
#if defined USE_CAIRO && !defined HAVE_GTK3
static GdkPixbuf *
@@ -633,8 +710,12 @@ xg_check_special_colors (struct frame *f,
g = col.green * 65535,
b = col.blue * 65535;
sprintf (buf, "rgb:%04x/%04x/%04x", r, g, b);
+#ifndef HAVE_PGTK
success_p = x_parse_color (f, buf, color) != 0;
#else
+ success_p = pgtk_parse_color (buf, color) != 0;
+#endif
+#else
GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f));
GdkColor *grgb = get_bg
? &gsty->bg[GTK_STATE_SELECTED]
@@ -667,7 +748,7 @@ hierarchy_ch_cb (GtkWidget *widget,
gpointer user_data)
{
struct frame *f = user_data;
- struct x_output *x = f->output_data.x;
+ xp_output *x = f->output_data.xp;
GtkWidget *top = gtk_widget_get_toplevel (x->ttip_lbl);
if (! top || ! GTK_IS_WINDOW (top))
@@ -689,7 +770,7 @@ qttip_cb (GtkWidget *widget,
gpointer user_data)
{
struct frame *f = user_data;
- struct x_output *x = f->output_data.x;
+ xp_output *x = f->output_data.xp;
if (x->ttip_widget == NULL)
{
GtkWidget *p;
@@ -736,7 +817,7 @@ xg_prepare_tooltip (struct frame *f,
int *width,
int *height)
{
- struct x_output *x = f->output_data.x;
+ xp_output *x = f->output_data.xp;
GtkWidget *widget;
GdkWindow *gwin;
GdkScreen *screen;
@@ -787,13 +868,19 @@ xg_prepare_tooltip (struct frame *f,
void
xg_show_tooltip (struct frame *f, int root_x, int root_y)
{
- struct x_output *x = f->output_data.x;
+ xp_output *x = f->output_data.xp;
if (x->ttip_window)
{
block_input ();
+#ifndef HAVE_PGTK
gtk_window_move (x->ttip_window, root_x / xg_get_scale (f),
root_y / xg_get_scale (f));
gtk_widget_show (GTK_WIDGET (x->ttip_window));
+#else
+ gtk_widget_show (GTK_WIDGET (x->ttip_window));
+ gtk_window_move (x->ttip_window, root_x / xg_get_scale (f),
+ root_y / xg_get_scale (f));
+#endif
unblock_input ();
}
}
@@ -805,10 +892,10 @@ xg_show_tooltip (struct frame *f, int root_x, int root_y)
bool
xg_hide_tooltip (struct frame *f)
{
- if (f->output_data.x->ttip_window)
+ bool ret = 0;
+ if (f->output_data.xp->ttip_window)
{
- GtkWindow *win = f->output_data.x->ttip_window;
-
+ GtkWindow *win = f->output_data.xp->ttip_window;
block_input ();
gtk_widget_hide (GTK_WIDGET (win));
@@ -932,10 +1019,16 @@ xg_frame_resized (struct frame *f, int pixelwidth, int pixelheight)
width = FRAME_PIXEL_TO_TEXT_WIDTH (f, pixelwidth);
height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, pixelheight);
+ PGTK_TRACE("xg_frame_resized: pixel: %dx%d, text: %dx%d", pixelwidth, pixelheight, width, height);
frame_size_history_add
(f, Qxg_frame_resized, width, height, Qnil);
+ PGTK_TRACE("width: %d -> %d.", FRAME_TEXT_WIDTH(f), width);
+ PGTK_TRACE("height: %d -> %d.", FRAME_TEXT_HEIGHT(f), height);
+ PGTK_TRACE("pixelwidth: %d -> %d.", FRAME_PIXEL_WIDTH(f), pixelwidth);
+ PGTK_TRACE("pixelheight: %d -> %d.", FRAME_PIXEL_HEIGHT(f), pixelheight);
+
if (width != FRAME_TEXT_WIDTH (f)
|| height != FRAME_TEXT_HEIGHT (f)
|| pixelwidth != FRAME_PIXEL_WIDTH (f)
@@ -945,6 +1038,9 @@ xg_frame_resized (struct frame *f, int pixelwidth, int pixelheight)
change_frame_size (f, width, height, 0, 1, 0, 1);
SET_FRAME_GARBAGED (f);
cancel_mouse_face (f);
+#ifdef HAVE_PGTK
+ pgtk_cr_destroy_surface (f);
+#endif
}
}
@@ -1007,7 +1103,11 @@ xg_frame_set_char_size (struct frame *f, int width, int height)
else if (FRAME_PARENT_FRAME (f) && FRAME_VISIBLE_P (f))
{
was_visible = true;
+#ifndef HAVE_PGTK
hide_child_frame = EQ (x_gtk_resize_child_frames, Qhide);
+#else
+ hide_child_frame = true;
+#endif // !HAVE_PGTK
if (totalwidth != gwidth || totalheight != gheight)
{
@@ -1060,7 +1160,9 @@ xg_frame_set_char_size (struct frame *f, int width, int height)
/* Must call this to flush out events */
(void)gtk_events_pending ();
gdk_flush ();
+#ifndef HAVE_PGTK
x_wait_for_event (f, ConfigureNotify);
+#endif
if (!NILP (fullscreen))
/* Try to restore fullscreen state. */
@@ -1071,24 +1173,24 @@ xg_frame_set_char_size (struct frame *f, int width, int height)
}
else
adjust_frame_size (f, width, height, 5, 0, Qxg_frame_set_char_size);
-
}
+#ifndef HAVE_PGTK
/* Handle height/width changes (i.e. add/remove/move menu/toolbar).
The policy is to keep the number of editable lines. */
-#if 0
static void
xg_height_or_width_changed (struct frame *f)
{
gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
FRAME_TOTAL_PIXEL_WIDTH (f),
FRAME_TOTAL_PIXEL_HEIGHT (f));
- f->output_data.x->hint_flags = 0;
+ f->output_data.xp->hint_flags = 0;
x_wm_set_size_hint (f, 0, 0);
}
#endif
+#ifndef HAVE_PGTK
/* Convert an X Window WSESC on display DPY to its corresponding GtkWidget.
Must be done like this, because GtkWidget:s can have "hidden"
X Window that aren't accessible.
@@ -1116,6 +1218,7 @@ xg_win_to_widget (Display *dpy, Window wdesc)
unblock_input ();
return gwdesc;
}
+#endif
/* Set the background of widget W to PIXEL. */
@@ -1123,9 +1226,18 @@ static void
xg_set_widget_bg (struct frame *f, GtkWidget *w, unsigned long pixel)
{
#ifdef HAVE_GTK3
- XColor xbg;
+ Emacs_Color xbg;
xbg.pixel = pixel;
+#ifndef HAVE_PGTK
if (XQueryColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), &xbg))
+#else
+ xbg.red = (pixel >> 16) & 0xff;
+ xbg.green = (pixel >> 8) & 0xff;
+ xbg.blue = (pixel >> 0) & 0xff;
+ xbg.red |= xbg.red << 8;
+ xbg.green |= xbg.green << 8;
+ xbg.blue |= xbg.blue << 8;
+#endif
{
const char format[] = "* { background-color: #%02x%02x%02x; }";
/* The format is always longer than the resulting string. */
@@ -1160,7 +1272,16 @@ style_changed_cb (GObject *go,
struct input_event event;
GdkDisplay *gdpy = user_data;
const char *display_name = gdk_display_get_name (gdpy);
+#ifndef HAVE_PGTK
Display *dpy = GDK_DISPLAY_XDISPLAY (gdpy);
+#else
+ GdkDisplay *dpy = gdpy;
+#endif
+
+#ifndef HAVE_PGTK
+ if (display_name == NULL)
+ display_name = "";
+#endif
EVENT_INIT (event);
event.kind = CONFIG_CHANGED_EVENT;
@@ -1181,7 +1302,11 @@ style_changed_cb (GObject *go,
{
struct frame *f = XFRAME (frame);
if (FRAME_LIVE_P (f)
+#ifndef HAVE_PGTK
&& FRAME_X_P (f)
+#else
+ && FRAME_PGTK_P (f)
+#endif
&& FRAME_X_DISPLAY (f) == dpy)
{
FRAME_TERMINAL (f)->set_scroll_bar_default_width_hook (f);
@@ -1216,15 +1341,21 @@ xg_create_frame_widgets (struct frame *f)
#endif
char *title = 0;
+ PGTK_TRACE("xg_create_frame_widgets.");
block_input ();
+#ifndef HAVE_PGTK // gtk_plug not found.
if (FRAME_X_EMBEDDED_P (f))
{
GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
- wtop = gtk_plug_new_for_display (gdpy, f->output_data.x->parent_desc);
+ wtop = gtk_plug_new_for_display (gdpy, f->output_data.xp->parent_desc);
}
else
+#endif
wtop = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+#ifdef HAVE_PGTK
+ gtk_widget_add_events(wtop, GDK_ALL_EVENTS_MASK);
+#endif
/* gtk_window_set_has_resize_grip is a Gtk+ 3.0 function but Ubuntu
has backported it to Gtk+ 2.0 and they add the resize grip for
@@ -1281,8 +1412,8 @@ xg_create_frame_widgets (struct frame *f)
FRAME_GTK_OUTER_WIDGET (f) = wtop;
FRAME_GTK_WIDGET (f) = wfixed;
- f->output_data.x->vbox_widget = wvbox;
- f->output_data.x->hbox_widget = whbox;
+ f->output_data.xp->vbox_widget = wvbox;
+ f->output_data.xp->hbox_widget = whbox;
gtk_widget_set_has_window (wfixed, TRUE);
@@ -1309,10 +1440,12 @@ xg_create_frame_widgets (struct frame *f)
SSDATA (Vx_resource_class));
#endif
+#ifndef HAVE_PGTK
/* Add callback to do nothing on WM_DELETE_WINDOW. The default in
GTK is to destroy the widget. We want Emacs to do that instead. */
g_signal_connect (G_OBJECT (wtop), "delete-event",
G_CALLBACK (delete_cb), f);
+#endif
/* Convert our geometry parameters into a geometry string
and specify it.
@@ -1323,7 +1456,9 @@ xg_create_frame_widgets (struct frame *f)
gtk_widget_add_events (wfixed,
GDK_POINTER_MOTION_MASK
+#ifndef HAVE_PGTK
| GDK_EXPOSURE_MASK
+#endif
| GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK
| GDK_KEY_PRESS_MASK
@@ -1331,13 +1466,25 @@ xg_create_frame_widgets (struct frame *f)
| GDK_LEAVE_NOTIFY_MASK
| GDK_FOCUS_CHANGE_MASK
| GDK_STRUCTURE_MASK
+#ifdef HAVE_PGTK
+ | GDK_SCROLL_MASK
+ | GDK_SMOOTH_SCROLL_MASK
+#endif
| GDK_VISIBILITY_NOTIFY_MASK);
/* Must realize the windows so the X window gets created. It is used
by callers of this function. */
+#ifndef HAVE_PGTK
gtk_widget_realize (wfixed);
+#else
+ gtk_widget_show_all(wtop);
+#endif
+#ifndef HAVE_PGTK
FRAME_X_WINDOW (f) = GTK_WIDGET_TO_X_WIN (wfixed);
+#endif
+#ifndef HAVE_PGTK
initial_set_up_x_back_buffer (f);
+#endif
/* Since GTK clears its window by filling with the background color,
we must keep X and GTK background in sync. */
@@ -1354,6 +1501,7 @@ xg_create_frame_widgets (struct frame *f)
gtk_widget_modify_style (wfixed, style);
#else
gtk_widget_set_can_focus (wfixed, TRUE);
+ gtk_widget_grab_focus(wfixed);
gtk_window_set_resizable (GTK_WINDOW (wtop), TRUE);
#endif
@@ -1366,9 +1514,9 @@ xg_create_frame_widgets (struct frame *f)
}
/* Steal a tool tip window we can move ourselves. */
- f->output_data.x->ttip_widget = 0;
- f->output_data.x->ttip_lbl = 0;
- f->output_data.x->ttip_window = 0;
+ f->output_data.xp->ttip_widget = 0;
+ f->output_data.xp->ttip_lbl = 0;
+ f->output_data.xp->ttip_window = 0;
gtk_widget_set_tooltip_text (wtop, "Dummy text");
g_signal_connect (wtop, "query-tooltip", G_CALLBACK (qttip_cb), f);
@@ -1398,7 +1546,7 @@ xg_free_frame_widgets (struct frame *f)
{
if (FRAME_GTK_OUTER_WIDGET (f))
{
- struct x_output *x = f->output_data.x;
+ xp_output *x = f->output_data.xp;
struct xg_frame_tb_info *tbinfo
= g_object_get_data (G_OBJECT (FRAME_GTK_OUTER_WIDGET (f)),
TB_INFO_KEY);
@@ -1406,10 +1554,14 @@ xg_free_frame_widgets (struct frame *f)
xfree (tbinfo);
/* x_free_frame_resources should have taken care of it */
+#ifndef HAVE_PGTK
eassert (!FRAME_X_DOUBLE_BUFFERED_P (f));
+#endif
gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f));
FRAME_X_WINDOW (f) = 0; /* Set to avoid XDestroyWindow in xterm.c */
+#ifndef HAVE_PGTK
FRAME_X_RAW_DRAWABLE (f) = 0;
+#endif
FRAME_GTK_OUTER_WIDGET (f) = 0;
if (x->ttip_widget)
{
@@ -1451,6 +1603,7 @@ x_wm_set_size_hint (struct frame *f, long int flags, bool user_position)
XSETFRAME (frame, f);
fs_state = Fframe_parameter (frame, Qfullscreen);
+#ifndef HAVE_PGTK
if ((EQ (fs_state, Qmaximized) || EQ (fs_state, Qfullboth)) &&
(x_wm_supports (f, FRAME_DISPLAY_INFO (f)->Xatom_net_wm_state) ||
x_wm_supports (f, FRAME_DISPLAY_INFO (f)->Xatom_net_wm_state_fullscreen)))
@@ -1460,18 +1613,19 @@ x_wm_set_size_hint (struct frame *f, long int flags, bool user_position)
*/
return;
}
+#endif
if (flags)
{
memset (&size_hints, 0, sizeof (size_hints));
- f->output_data.x->size_hints = size_hints;
- f->output_data.x->hint_flags = hint_flags;
+ f->output_data.xp->size_hints = size_hints;
+ f->output_data.xp->hint_flags = hint_flags;
}
else
flags = f->size_hint_flags;
- size_hints = f->output_data.x->size_hints;
- hint_flags = f->output_data.x->hint_flags;
+ size_hints = f->output_data.xp->size_hints;
+ hint_flags = f->output_data.xp->hint_flags;
hint_flags |= GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE;
size_hints.width_inc = frame_resize_pixelwise ? 1 : FRAME_COLUMN_WIDTH (f);
@@ -1484,6 +1638,7 @@ x_wm_set_size_hint (struct frame *f, long int flags, bool user_position)
base_width = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, 1) + FRAME_TOOLBAR_WIDTH (f);
base_height = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, 1)
+ FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f);
+ PGTK_TRACE("base: %dx%d\n", base_width, base_height);
size_hints.base_width = base_width;
size_hints.base_height = base_height;
@@ -1533,16 +1688,16 @@ x_wm_set_size_hint (struct frame *f, long int flags, bool user_position)
size_hints.width_inc /= scale;
size_hints.height_inc /= scale;
- if (hint_flags != f->output_data.x->hint_flags
+ if (hint_flags != f->output_data.xp->hint_flags
|| memcmp (&size_hints,
- &f->output_data.x->size_hints,
+ &f->output_data.xp->size_hints,
sizeof (size_hints)) != 0)
{
block_input ();
gtk_window_set_geometry_hints (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
NULL, &size_hints, hint_flags);
- f->output_data.x->size_hints = size_hints;
- f->output_data.x->hint_flags = hint_flags;
+ f->output_data.xp->size_hints = size_hints;
+ f->output_data.xp->hint_flags = hint_flags;
unblock_input ();
}
}
@@ -1608,7 +1763,11 @@ xg_frame_restack (struct frame *f1, struct frame *f2, bool above_flag)
XSETFRAME (frame2, f2);
gdk_window_restack (gwin1, gwin2, above_flag);
+#ifndef HAVE_PGTK
x_sync (f1);
+#else
+ gdk_flush();
+#endif
}
unblock_input ();
}
@@ -1672,6 +1831,7 @@ xg_set_override_redirect (struct frame *f, Lisp_Object override_redirect)
unblock_input ();
}
+#ifndef HAVE_PGTK
/* Set the frame icon to ICON_PIXMAP/MASK. This must be done with GTK
functions so GTK does not overwrite the icon. */
@@ -1684,6 +1844,7 @@ xg_set_frame_icon (struct frame *f, Pixmap icon_pixmap, Pixmap icon_mask)
if (gp)
gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), gp);
}
+#endif
@@ -2500,7 +2661,7 @@ xg_mark_data (void)
{
struct frame *f = XFRAME (frame);
- if (FRAME_X_P (f) && FRAME_GTK_OUTER_WIDGET (f))
+ if ((FRAME_X_P (f) || FRAME_PGTK_P (f)) && FRAME_GTK_OUTER_WIDGET (f))
{
struct xg_frame_tb_info *tbinfo
= g_object_get_data (G_OBJECT (FRAME_GTK_OUTER_WIDGET (f)),
@@ -3529,7 +3690,7 @@ menubar_map_cb (GtkWidget *w, gpointer user_data)
void
xg_update_frame_menubar (struct frame *f)
{
- struct x_output *x = f->output_data.x;
+ xp_output *x = f->output_data.xp;
GtkRequisition req;
if (!x->menubar_widget || gtk_widget_get_mapped (x->menubar_widget))
@@ -3562,7 +3723,7 @@ xg_update_frame_menubar (struct frame *f)
void
free_frame_menubar (struct frame *f)
{
- struct x_output *x = f->output_data.x;
+ xp_output *x = f->output_data.xp;
if (x->menubar_widget)
{
@@ -3578,10 +3739,11 @@ free_frame_menubar (struct frame *f)
}
}
+#ifndef HAVE_PGTK
bool
-xg_event_is_for_menubar (struct frame *f, const XEvent *event)
+xg_event_is_for_menubar (struct frame *f, const EVENT *event)
{
- struct x_output *x = f->output_data.x;
+ xp_output *x = f->output_data.xp;
GList *iter;
GdkRectangle rec;
GList *list;
@@ -3628,6 +3790,7 @@ xg_event_is_for_menubar (struct frame *f, const XEvent *event)
g_list_free (list);
return iter != 0;
}
+#endif
@@ -3783,6 +3946,7 @@ xg_get_default_scrollbar_height (struct frame *f)
return scroll_bar_width_for_theme * xg_get_scale (f);
}
+#ifndef HAVE_PGTK
/* Return the scrollbar id for X Window WID on display DPY.
Return -1 if WID not in id_to_widget. */
@@ -3803,6 +3967,7 @@ xg_get_scroll_id_for_window (Display *dpy, Window wid)
return -1;
}
+#endif
/* Callback invoked when scroll bar WIDGET is destroyed.
DATA is the index into id_to_widget for WIDGET.
@@ -3852,7 +4017,7 @@ xg_finish_scroll_bar_creation (struct frame *f,
also, which causes flicker. Put an event box between the edit widget
and the scroll bar, so the scroll bar instead draws itself on the
event box window. */
- gtk_fixed_put (GTK_FIXED (f->output_data.x->edit_widget), webox, -1, -1);
+ gtk_fixed_put (GTK_FIXED (f->output_data.xp->edit_widget), webox, -1, -1);
gtk_container_add (GTK_CONTAINER (webox), wscroll);
xg_set_widget_bg (f, webox, FRAME_BACKGROUND_PIXEL (f));
@@ -3862,7 +4027,12 @@ xg_finish_scroll_bar_creation (struct frame *f,
real X window, it and its scroll-bar child try to draw on the
Emacs main window, which we draw over using Xlib. */
gtk_widget_realize (webox);
+#ifdef HAVE_PGTK
+ gtk_widget_show_all(webox);
+#endif
+#ifndef HAVE_PGTK
GTK_WIDGET_TO_X_WIN (webox);
+#endif
/* Set the cursor to an arrow. */
xg_set_cursor (webox, FRAME_DISPLAY_INFO (f)->xg_cursor);
@@ -3967,7 +4137,7 @@ xg_update_scrollbar_pos (struct frame *f,
GtkWidget *wscroll = xg_get_widget_from_map (scrollbar_id);
if (wscroll)
{
- GtkWidget *wfixed = f->output_data.x->edit_widget;
+ GtkWidget *wfixed = f->output_data.xp->edit_widget;
GtkWidget *wparent = gtk_widget_get_parent (wscroll);
gint msl;
int scale = xg_get_scale (f);
@@ -4007,7 +4177,11 @@ xg_update_scrollbar_pos (struct frame *f,
/* Clear under old scroll bar position. */
oldw += (scale - 1) * oldw;
oldx -= (scale - 1) * oldw;
+#ifndef HAVE_PGTK
x_clear_area (f, oldx, oldy, oldw, oldh);
+#else
+ pgtk_clear_area (f, oldx, oldy, oldw, oldh);
+#endif
}
if (!hidden)
@@ -4015,15 +4189,23 @@ xg_update_scrollbar_pos (struct frame *f,
GtkWidget *scrollbar = xg_get_widget_from_map (scrollbar_id);
GtkWidget *webox = gtk_widget_get_parent (scrollbar);
+#ifndef HAVE_PGTK
/* Don't obscure any child frames. */
XLowerWindow (FRAME_X_DISPLAY (f), GTK_WIDGET_TO_X_WIN (webox));
+#else
+ gdk_window_lower(gtk_widget_get_window(webox));
+#endif
}
/* GTK does not redraw until the main loop is entered again, but
if there are no X events pending we will not enter it. So we sync
here to get some events. */
+#ifndef HAVE_PGTK
x_sync (f);
+#else
+ gdk_flush();
+#endif
SET_FRAME_GARBAGED (f);
cancel_mouse_face (f);
}
@@ -4048,7 +4230,7 @@ xg_update_horizontal_scrollbar_pos (struct frame *f,
if (wscroll)
{
- GtkWidget *wfixed = f->output_data.x->edit_widget;
+ GtkWidget *wfixed = f->output_data.xp->edit_widget;
GtkWidget *wparent = gtk_widget_get_parent (wscroll);
gint msl;
int scale = xg_get_scale (f);
@@ -4084,7 +4266,11 @@ xg_update_horizontal_scrollbar_pos (struct frame *f,
}
if (oldx != -1 && oldw > 0 && oldh > 0)
/* Clear under old scroll bar position. */
+#ifndef HAVE_PGTK
x_clear_area (f, oldx, oldy, oldw, oldh);
+#else
+ pgtk_clear_area (f, oldx, oldy, oldw, oldh);
+#endif
/* GTK does not redraw until the main loop is entered again, but
if there are no X events pending we will not enter it. So we sync
@@ -4095,11 +4281,19 @@ xg_update_horizontal_scrollbar_pos (struct frame *f,
xg_get_widget_from_map (scrollbar_id);
GtkWidget *webox = gtk_widget_get_parent (scrollbar);
+#ifndef HAVE_PGTK
/* Don't obscure any child frames. */
XLowerWindow (FRAME_X_DISPLAY (f), GTK_WIDGET_TO_X_WIN (webox));
+#else
+ gdk_window_lower(gtk_widget_get_window(webox));
+#endif
}
+#ifndef HAVE_PGTK
x_sync (f);
+#else
+ gdk_flush();
+#endif
SET_FRAME_GARBAGED (f);
cancel_mouse_face (f);
}
@@ -4128,6 +4322,8 @@ xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
+ PGTK_TRACE("xg_set_toolkit_scroll_bar_thumb: ----------------------------------");
+ PGTK_TRACE("xg_set_toolkit_scroll_bar_thumb: %p, %d, %d, %d.", bar, portion, position, whole);
if (wscroll && bar->dragging == -1)
{
GtkAdjustment *adj;
@@ -4159,17 +4355,26 @@ xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
top = (gdouble) position / whole;
shown = (gdouble) portion / whole;
}
+ PGTK_TRACE("xg_set_toolkit_scroll_bar_thumb: position=%d, portion=%d, whole=%d", position, portion, whole);
+ PGTK_TRACE("xg_set_toolkit_scroll_bar_thumb: top=%f, shown=%f", top, shown);
+ PGTK_TRACE("xg_set_toolkit_scroll_bar_thumb: shown*range=%f", shown * XG_SB_RANGE);
size = clip_to_bounds (1, shown * XG_SB_RANGE, XG_SB_RANGE);
+ PGTK_TRACE("xg_set_toolkit_scroll_bar_thumb: size=%d.", size);
+ PGTK_TRACE("xg_set_toolkit_scroll_bar_thumb: top*range=%f.", top * XG_SB_RANGE);
+ PGTK_TRACE("xg_set_toolkit_scroll_bar_thumb: max-size=%d.", XG_SB_MAX - size);
value = clip_to_bounds (XG_SB_MIN, top * XG_SB_RANGE, XG_SB_MAX - size);
+ PGTK_TRACE("xg_set_toolkit_scroll_bar_thumb: value=%d.", value);
/* Assume all lines are of equal size. */
new_step = size / max (1, FRAME_LINES (f));
old_size = gtk_adjustment_get_page_size (adj);
+ PGTK_TRACE("xg_set_toolkit_scroll_bar_thumb: old_size=%d, size=%d", old_size, size);
if (old_size != size)
{
int old_step = gtk_adjustment_get_step_increment (adj);
+ PGTK_TRACE("xg_set_toolkit_scroll_bar_thumb: old_step=%d, new_step=%d", old_step, new_step);
if (old_step != new_step)
{
gtk_adjustment_set_page_size (adj, size);
@@ -4180,6 +4385,8 @@ xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
}
}
+ PGTK_TRACE("xg_set_toolkit_scroll_bar_thumb: changed=%d, old=%d, value=%d.",
+ changed, int_gtk_range_get_value (GTK_RANGE (wscroll)), value);
if (changed || int_gtk_range_get_value (GTK_RANGE (wscroll)) != value)
{
block_input ();
@@ -4243,14 +4450,24 @@ xg_set_toolkit_horizontal_scroll_bar_thumb (struct scroll_bar *bar,
frame. This function does additional checks. */
bool
-xg_event_is_for_scrollbar (struct frame *f, const XEvent *event)
+xg_event_is_for_scrollbar (struct frame *f, const EVENT *event)
{
bool retval = 0;
- if (f && event->type == ButtonPress && event->xbutton.button < 4)
+ if (f
+#ifndef HAVE_PGTK
+ && event->type == ButtonPress && event->xbutton.button < 4
+#else
+ && event->type == GDK_BUTTON_PRESS && event->button.button < 4
+#endif
+ )
{
/* Check if press occurred outside the edit widget. */
+#ifndef HAVE_PGTK
GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
+#else
+ GdkDisplay *gdpy = FRAME_X_DISPLAY(f);
+#endif
GdkWindow *gwin;
#ifdef HAVE_GTK3
#if GTK_CHECK_VERSION (3, 20, 0)
@@ -4264,11 +4481,17 @@ xg_event_is_for_scrollbar (struct frame *f, const XEvent *event)
#else
gwin = gdk_display_get_window_at_pointer (gdpy, NULL, NULL);
#endif
- retval = gwin != gtk_widget_get_window (f->output_data.x->edit_widget);
+ retval = gwin != gtk_widget_get_window (f->output_data.xp->edit_widget);
}
else if (f
+#ifndef HAVE_PGTK
&& ((event->type == ButtonRelease && event->xbutton.button < 4)
- || event->type == MotionNotify))
+ || event->type == MotionNotify)
+#else
+ && ((event->type == GDK_BUTTON_RELEASE && event->button.button < 4)
+ || event->type == GDK_MOTION_NOTIFY)
+#endif
+ )
{
/* If we are releasing or moving the scroll bar, it has the grab. */
GtkWidget *w = gtk_grab_get_current ();
@@ -4346,7 +4569,11 @@ draw_page (GtkPrintOperation *operation, GtkPrintContext *context,
struct frame *f = XFRAME (Fnth (make_fixnum (page_nr), frames));
cairo_t *cr = gtk_print_context_get_cairo_context (context);
+#ifndef HAVE_PGTK
x_cr_draw_frame (cr, f);
+#else
+ pgtk_cr_draw_frame (cr, f);
+#endif
}
void
@@ -4447,7 +4674,11 @@ xg_tool_bar_callback (GtkWidget *w, gpointer client_data)
/* Convert between the modifier bits GDK uses and the modifier bits
Emacs uses. This assumes GDK and X masks are the same, which they are when
this is written. */
+#ifndef HAVE_PGTK
event.modifiers = x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f), mod);
+#else
+ event.modifiers = pgtk_gtk_to_emacs_modifiers (mod);
+#endif
kbd_buffer_store_event (&event);
/* Return focus to the frame after we have clicked on a detached
@@ -4517,7 +4748,6 @@ xg_tool_bar_help_callback (GtkWidget *w,
Returns FALSE to tell GTK to keep processing this event. */
-#ifndef HAVE_GTK3
static gboolean
xg_tool_bar_item_expose_callback (GtkWidget *w,
GdkEventExpose *event,
@@ -4537,14 +4767,13 @@ xg_tool_bar_item_expose_callback (GtkWidget *w,
return FALSE;
}
-#endif
/* Attach a tool bar to frame F. */
static void
xg_pack_tool_bar (struct frame *f, Lisp_Object pos)
{
- struct x_output *x = f->output_data.x;
+ xp_output *x = f->output_data.xp;
bool into_hbox = EQ (pos, Qleft) || EQ (pos, Qright);
GtkWidget *top_widget = x->toolbar_widget;
@@ -4603,7 +4832,7 @@ tb_size_cb (GtkWidget *widget,
static void
xg_create_tool_bar (struct frame *f)
{
- struct x_output *x = f->output_data.x;
+ xp_output *x = f->output_data.xp;
#ifdef HAVE_GTK3
GtkStyleContext *gsty;
#endif
@@ -4842,7 +5071,7 @@ xg_tool_item_stale_p (GtkWidget *wbutton, const char *stock_name,
static bool
xg_update_tool_bar_sizes (struct frame *f)
{
- struct x_output *x = f->output_data.x;
+ xp_output *x = f->output_data.xp;
GtkRequisition req;
int nl = 0, nr = 0, nt = 0, nb = 0;
GtkWidget *top_widget = x->toolbar_widget;
@@ -4928,7 +5157,11 @@ void
update_frame_tool_bar (struct frame *f)
{
int i, j;
- struct x_output *x = f->output_data.x;
+#ifndef HAVE_PGTK
+ struct x_output *x = f->output_data.xp;
+#else
+ struct pgtk_output *x = f->output_data.pgtk;
+#endif
int hmargin = 0, vmargin = 0;
GtkToolbar *wtoolbar;
GtkToolItem *ti;
@@ -5245,7 +5478,7 @@ update_frame_tool_bar (struct frame *f)
void
free_frame_tool_bar (struct frame *f)
{
- struct x_output *x = f->output_data.x;
+ xp_output *x = f->output_data.xp;
if (x->toolbar_widget)
{
@@ -5291,7 +5524,7 @@ free_frame_tool_bar (struct frame *f)
void
xg_change_toolbar_position (struct frame *f, Lisp_Object pos)
{
- struct x_output *x = f->output_data.x;
+ xp_output *x = f->output_data.xp;
GtkWidget *top_widget = x->toolbar_widget;
if (! x->toolbar_widget || ! top_widget)