1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 09:58:01 +00:00

Allow direct use of X11 to be conditionally compiled out.

A major aim of introducing GTK 3 support is to permit compiling for
non-X11 platforms that GTK 3 supports, so I'm going to need to be able
to build as a pure GTK application with no use of X11 internals.
Naturally, I don't intend to stop supporting the hybrid GTK+X11 mode
in which X server-side bitmap fonts are available.

Use of X11 can be removed by compiling with -DNOT_X_WINDOWS. That's
the same compatibility flag that was already used by the unfinished OS
X port to disable the X-specific parts of uxpty.c; now it just applies
to more source files.

(There's no 'configure' option to set this flag at present. I haven't
worked out whether we'll need one yet.)
This commit is contained in:
Simon Tatham 2015-08-08 16:35:19 +01:00
parent a6ccb8e720
commit 2ac190c06d
3 changed files with 76 additions and 19 deletions

View File

@ -10,9 +10,11 @@
#if !GTK_CHECK_VERSION(3,0,0) #if !GTK_CHECK_VERSION(3,0,0)
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#endif #endif
#ifndef NOT_X_WINDOWS
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#endif
#include "gtkcompat.h" #include "gtkcompat.h"

View File

@ -16,10 +16,12 @@
#if !GTK_CHECK_VERSION(3,0,0) #if !GTK_CHECK_VERSION(3,0,0)
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#endif #endif
#ifndef NOT_X_WINDOWS
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#endif
#include "putty.h" #include "putty.h"
#include "gtkfont.h" #include "gtkfont.h"
@ -97,8 +99,12 @@ struct unifont_vtable {
const char *prefix; const char *prefix;
}; };
#ifndef NOT_X_WINDOWS
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
* X11 font implementation, directly using Xlib calls. * X11 font implementation, directly using Xlib calls. Conditioned out
* if X11 fonts aren't available at all (e.g. building with GTK3 for a
* back end other than X).
*/ */
static int x11font_has_glyph(unifont *font, wchar_t glyph); static int x11font_has_glyph(unifont *font, wchar_t glyph);
@ -828,6 +834,8 @@ static char *x11font_scale_fontname(GtkWidget *widget, const char *name,
return NULL; /* shan't */ return NULL; /* shan't */
} }
#endif /* NOT_X_WINDOWS */
#if GTK_CHECK_VERSION(2,0,0) #if GTK_CHECK_VERSION(2,0,0)
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -1449,7 +1457,9 @@ static const struct unifont_vtable *unifont_types[] = {
#if GTK_CHECK_VERSION(2,0,0) #if GTK_CHECK_VERSION(2,0,0)
&pangofont_vtable, &pangofont_vtable,
#endif #endif
#ifndef NOT_X_WINDOWS
&x11font_vtable, &x11font_vtable,
#endif
}; };
/* /*
@ -1660,6 +1670,7 @@ typedef struct unifontsel_internal {
GtkListStore *family_model, *style_model, *size_model; GtkListStore *family_model, *style_model, *size_model;
GtkWidget *family_list, *style_list, *size_entry, *size_list; GtkWidget *family_list, *style_list, *size_entry, *size_list;
GtkWidget *filter_buttons[4]; GtkWidget *filter_buttons[4];
int n_filter_buttons;
GtkWidget *preview_area; GtkWidget *preview_area;
GdkPixmap *preview_pixmap; GdkPixmap *preview_pixmap;
int preview_width, preview_height; int preview_width, preview_height;
@ -1967,7 +1978,7 @@ static void unifontsel_set_filter_buttons(unifontsel_internal *fs)
{ {
int i; int i;
for (i = 0; i < lenof(fs->filter_buttons); i++) { for (i = 0; i < fs->n_filter_buttons; i++) {
int flagbit = GPOINTER_TO_INT(gtk_object_get_data int flagbit = GPOINTER_TO_INT(gtk_object_get_data
(GTK_OBJECT(fs->filter_buttons[i]), (GTK_OBJECT(fs->filter_buttons[i]),
"user-data")); "user-data"));
@ -2747,14 +2758,21 @@ unifontsel *unifontsel_new(const char *wintitle)
gtk_table_attach(GTK_TABLE(table), w, 0, 3, 3, 4, gtk_table_attach(GTK_TABLE(table), w, 0, 3, 3, 4,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 8); GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 8);
i = 0; /*
* We only provide the checkboxes for client- and server-side
* fonts if we have the X11 back end available, because that's the
* only situation in which more than one class of font is
* available anyway.
*/
fs->n_filter_buttons = 0;
#ifndef NOT_X_WINDOWS
w = gtk_check_button_new_with_label("Show client-side fonts"); w = gtk_check_button_new_with_label("Show client-side fonts");
gtk_object_set_data(GTK_OBJECT(w), "user-data", gtk_object_set_data(GTK_OBJECT(w), "user-data",
GINT_TO_POINTER(FONTFLAG_CLIENTSIDE)); GINT_TO_POINTER(FONTFLAG_CLIENTSIDE));
gtk_signal_connect(GTK_OBJECT(w), "toggled", gtk_signal_connect(GTK_OBJECT(w), "toggled",
GTK_SIGNAL_FUNC(unifontsel_button_toggled), fs); GTK_SIGNAL_FUNC(unifontsel_button_toggled), fs);
gtk_widget_show(w); gtk_widget_show(w);
fs->filter_buttons[i++] = w; fs->filter_buttons[fs->n_filter_buttons++] = w;
gtk_table_attach(GTK_TABLE(table), w, 0, 3, 4, 5, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), w, 0, 3, 4, 5, GTK_FILL, 0, 0, 0);
w = gtk_check_button_new_with_label("Show server-side fonts"); w = gtk_check_button_new_with_label("Show server-side fonts");
gtk_object_set_data(GTK_OBJECT(w), "user-data", gtk_object_set_data(GTK_OBJECT(w), "user-data",
@ -2762,7 +2780,7 @@ unifontsel *unifontsel_new(const char *wintitle)
gtk_signal_connect(GTK_OBJECT(w), "toggled", gtk_signal_connect(GTK_OBJECT(w), "toggled",
GTK_SIGNAL_FUNC(unifontsel_button_toggled), fs); GTK_SIGNAL_FUNC(unifontsel_button_toggled), fs);
gtk_widget_show(w); gtk_widget_show(w);
fs->filter_buttons[i++] = w; fs->filter_buttons[fs->n_filter_buttons++] = w;
gtk_table_attach(GTK_TABLE(table), w, 0, 3, 5, 6, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), w, 0, 3, 5, 6, GTK_FILL, 0, 0, 0);
w = gtk_check_button_new_with_label("Show server-side font aliases"); w = gtk_check_button_new_with_label("Show server-side font aliases");
gtk_object_set_data(GTK_OBJECT(w), "user-data", gtk_object_set_data(GTK_OBJECT(w), "user-data",
@ -2770,18 +2788,19 @@ unifontsel *unifontsel_new(const char *wintitle)
gtk_signal_connect(GTK_OBJECT(w), "toggled", gtk_signal_connect(GTK_OBJECT(w), "toggled",
GTK_SIGNAL_FUNC(unifontsel_button_toggled), fs); GTK_SIGNAL_FUNC(unifontsel_button_toggled), fs);
gtk_widget_show(w); gtk_widget_show(w);
fs->filter_buttons[i++] = w; fs->filter_buttons[fs->n_filter_buttons++] = w;
gtk_table_attach(GTK_TABLE(table), w, 0, 3, 6, 7, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), w, 0, 3, 6, 7, GTK_FILL, 0, 0, 0);
#endif
w = gtk_check_button_new_with_label("Show non-monospaced fonts"); w = gtk_check_button_new_with_label("Show non-monospaced fonts");
gtk_object_set_data(GTK_OBJECT(w), "user-data", gtk_object_set_data(GTK_OBJECT(w), "user-data",
GINT_TO_POINTER(FONTFLAG_NONMONOSPACED)); GINT_TO_POINTER(FONTFLAG_NONMONOSPACED));
gtk_signal_connect(GTK_OBJECT(w), "toggled", gtk_signal_connect(GTK_OBJECT(w), "toggled",
GTK_SIGNAL_FUNC(unifontsel_button_toggled), fs); GTK_SIGNAL_FUNC(unifontsel_button_toggled), fs);
gtk_widget_show(w); gtk_widget_show(w);
fs->filter_buttons[i++] = w; fs->filter_buttons[fs->n_filter_buttons++] = w;
gtk_table_attach(GTK_TABLE(table), w, 0, 3, 7, 8, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), w, 0, 3, 7, 8, GTK_FILL, 0, 0, 0);
assert(i == lenof(fs->filter_buttons)); assert(fs->n_filter_buttons <= lenof(fs->filter_buttons));
fs->filter_flags = FONTFLAG_CLIENTSIDE | FONTFLAG_SERVERSIDE | fs->filter_flags = FONTFLAG_CLIENTSIDE | FONTFLAG_SERVERSIDE |
FONTFLAG_SERVERALIAS; FONTFLAG_SERVERALIAS;
unifontsel_set_filter_buttons(fs); unifontsel_set_filter_buttons(fs);

View File

@ -22,10 +22,12 @@
#if !GTK_CHECK_VERSION(3,0,0) #if !GTK_CHECK_VERSION(3,0,0)
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#endif #endif
#ifndef NOT_X_WINDOWS
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#endif
#if GTK_CHECK_VERSION(2,0,0) #if GTK_CHECK_VERSION(2,0,0)
#include <gtk/gtkimmodule.h> #include <gtk/gtkimmodule.h>
@ -143,7 +145,11 @@ static void exit_callback(void *vinst);
char *x_get_default(const char *key) char *x_get_default(const char *key)
{ {
#ifndef NOT_X_WINDOWS
return XGetDefault(GDK_DISPLAY(), app_name, key); return XGetDefault(GDK_DISPLAY(), app_name, key);
#else
return NULL;
#endif
} }
void connection_fatal(void *frontend, const char *p, ...) void connection_fatal(void *frontend, const char *p, ...)
@ -1792,6 +1798,7 @@ void palette_reset(void *frontend)
*/ */
void init_cutbuffers() void init_cutbuffers()
{ {
#ifndef NOT_X_WINDOWS
unsigned char empty[] = ""; unsigned char empty[] = "";
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(), XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
XA_CUT_BUFFER0, XA_STRING, 8, PropModeAppend, empty, 0); XA_CUT_BUFFER0, XA_STRING, 8, PropModeAppend, empty, 0);
@ -1809,14 +1816,17 @@ void init_cutbuffers()
XA_CUT_BUFFER6, XA_STRING, 8, PropModeAppend, empty, 0); XA_CUT_BUFFER6, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(), XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
XA_CUT_BUFFER7, XA_STRING, 8, PropModeAppend, empty, 0); XA_CUT_BUFFER7, XA_STRING, 8, PropModeAppend, empty, 0);
#endif
} }
/* Store the data in a cut-buffer. */ /* Store the data in a cut-buffer. */
void store_cutbuffer(char * ptr, int len) void store_cutbuffer(char * ptr, int len)
{ {
#ifndef NOT_X_WINDOWS
/* ICCCM says we must rotate the buffers before storing to buffer 0. */ /* ICCCM says we must rotate the buffers before storing to buffer 0. */
XRotateBuffers(GDK_DISPLAY(), 1); XRotateBuffers(GDK_DISPLAY(), 1);
XStoreBytes(GDK_DISPLAY(), ptr, len); XStoreBytes(GDK_DISPLAY(), ptr, len);
#endif
} }
/* Retrieve data from a cut-buffer. /* Retrieve data from a cut-buffer.
@ -1824,6 +1834,7 @@ void store_cutbuffer(char * ptr, int len)
*/ */
char * retrieve_cutbuffer(int * nbytes) char * retrieve_cutbuffer(int * nbytes)
{ {
#ifndef NOT_X_WINDOWS
char * ptr; char * ptr;
ptr = XFetchBytes(GDK_DISPLAY(), nbytes); ptr = XFetchBytes(GDK_DISPLAY(), nbytes);
if (*nbytes <= 0 && ptr != 0) { if (*nbytes <= 0 && ptr != 0) {
@ -1831,6 +1842,9 @@ char * retrieve_cutbuffer(int * nbytes)
ptr = 0; ptr = 0;
} }
return ptr; return ptr;
#else
return NULL;
#endif
} }
void write_clip(void *frontend, wchar_t * data, int *attr, int len, int must_deselect) void write_clip(void *frontend, wchar_t * data, int *attr, int len, int must_deselect)
@ -1850,8 +1864,10 @@ void write_clip(void *frontend, wchar_t * data, int *attr, int len, int must_des
if (!inst->direct_to_font) { if (!inst->direct_to_font) {
const wchar_t *tmp = data; const wchar_t *tmp = data;
int tmplen = len; int tmplen = len;
#ifndef NOT_X_WINDOWS
XTextProperty tp; XTextProperty tp;
char *list[1]; char *list[1];
#endif
inst->pasteout_data_utf8 = snewn(len*6, char); inst->pasteout_data_utf8 = snewn(len*6, char);
inst->pasteout_data_utf8_len = len*6; inst->pasteout_data_utf8_len = len*6;
@ -1872,6 +1888,7 @@ void write_clip(void *frontend, wchar_t * data, int *attr, int len, int must_des
/* /*
* Now let Xlib convert our UTF-8 data into compound text. * Now let Xlib convert our UTF-8 data into compound text.
*/ */
#ifndef NOT_X_WINDOWS
list[0] = inst->pasteout_data_utf8; list[0] = inst->pasteout_data_utf8;
if (Xutf8TextListToTextProperty(GDK_DISPLAY(), list, 1, if (Xutf8TextListToTextProperty(GDK_DISPLAY(), list, 1,
XCompoundTextStyle, &tp) == 0) { XCompoundTextStyle, &tp) == 0) {
@ -1879,7 +1896,9 @@ void write_clip(void *frontend, wchar_t * data, int *attr, int len, int must_des
memcpy(inst->pasteout_data_ctext, tp.value, tp.nitems); memcpy(inst->pasteout_data_ctext, tp.value, tp.nitems);
inst->pasteout_data_ctext_len = tp.nitems; inst->pasteout_data_ctext_len = tp.nitems;
XFree(tp.value); XFree(tp.value);
} else { } else
#endif
{
inst->pasteout_data_ctext = NULL; inst->pasteout_data_ctext = NULL;
inst->pasteout_data_ctext_len = 0; inst->pasteout_data_ctext_len = 0;
} }
@ -2002,18 +2021,18 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
guint time, gpointer data) guint time, gpointer data)
{ {
struct gui_data *inst = (struct gui_data *)data; struct gui_data *inst = (struct gui_data *)data;
XTextProperty tp;
char **list;
char *text; char *text;
int length, count, ret; int length;
#ifndef NOT_X_WINDOWS
char **list;
int free_list_required = 0; int free_list_required = 0;
int free_required = 0; int free_required = 0;
#endif
int charset; int charset;
GdkAtom seldata_target = gtk_selection_data_get_target(seldata); GdkAtom seldata_target = gtk_selection_data_get_target(seldata);
GdkAtom seldata_type = gtk_selection_data_get_data_type(seldata); GdkAtom seldata_type = gtk_selection_data_get_data_type(seldata);
const guchar *seldata_data = gtk_selection_data_get_data(seldata); const guchar *seldata_data = gtk_selection_data_get_data(seldata);
gint seldata_length = gtk_selection_data_get_length(seldata); gint seldata_length = gtk_selection_data_get_length(seldata);
gint seldata_format = gtk_selection_data_get_format(seldata);
if (seldata_target == utf8_string_atom && seldata_length <= 0) { if (seldata_target == utf8_string_atom && seldata_length <= 0) {
/* /*
@ -2051,6 +2070,7 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
* If we have no data, try looking in a cut buffer. * If we have no data, try looking in a cut buffer.
*/ */
if (seldata_length <= 0) { if (seldata_length <= 0) {
#ifndef NOT_X_WINDOWS
text = retrieve_cutbuffer(&length); text = retrieve_cutbuffer(&length);
if (length == 0) if (length == 0)
return; return;
@ -2058,18 +2078,32 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
* source, so use that as a de-facto standard. */ * source, so use that as a de-facto standard. */
charset = CS_ISO8859_1; charset = CS_ISO8859_1;
free_required = 1; free_required = 1;
#else
return;
#endif
} else { } else {
/* /*
* Convert COMPOUND_TEXT into UTF-8. * Convert COMPOUND_TEXT into UTF-8.
*/ */
if (seldata_type == compound_text_atom) { if (seldata_type == compound_text_atom) {
#ifndef NOT_X_WINDOWS
XTextProperty tp;
int ret, count;
tp.value = (unsigned char *)seldata_data; tp.value = (unsigned char *)seldata_data;
tp.encoding = (Atom) seldata_type; tp.encoding = (Atom) seldata_type;
tp.format = seldata_format; tp.format = gtk_selection_data_get_format(seldata);
tp.nitems = seldata_length; tp.nitems = seldata_length;
ret = Xutf8TextPropertyToTextList(GDK_DISPLAY(), &tp, ret = Xutf8TextPropertyToTextList(GDK_DISPLAY(), &tp,
&list, &count); &list, &count);
if (ret != 0 || count != 1) { if (ret == 0 && count == 1) {
text = list[0];
length = strlen(list[0]);
charset = CS_UTF8;
free_list_required = 1;
} else
#endif
{
/* /*
* Compound text failed; fall back to STRING. * Compound text failed; fall back to STRING.
*/ */
@ -2078,10 +2112,6 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
inst->input_event_time); inst->input_event_time);
return; return;
} }
text = list[0];
length = strlen(list[0]);
charset = CS_UTF8;
free_list_required = 1;
} else { } else {
text = (char *)seldata_data; text = (char *)seldata_data;
length = seldata_length; length = seldata_length;
@ -2101,10 +2131,12 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
term_do_paste(inst->term); term_do_paste(inst->term);
#ifndef NOT_X_WINDOWS
if (free_list_required) if (free_list_required)
XFreeStringList(list); XFreeStringList(list);
if (free_required) if (free_required)
XFree(text); XFree(text);
#endif
} }
void get_clip(void *frontend, wchar_t ** p, int *len) void get_clip(void *frontend, wchar_t ** p, int *len)
@ -2668,11 +2700,13 @@ char *get_x_display(void *frontend)
return gdk_get_display(); return gdk_get_display();
} }
#ifndef NOT_X_WINDOWS
long get_windowid(void *frontend) long get_windowid(void *frontend)
{ {
struct gui_data *inst = (struct gui_data *)frontend; struct gui_data *inst = (struct gui_data *)frontend;
return (long)GDK_WINDOW_XWINDOW(gtk_widget_get_window(inst->area)); return (long)GDK_WINDOW_XWINDOW(gtk_widget_get_window(inst->area));
} }
#endif
static void help(FILE *fp) { static void help(FILE *fp) {
if(fprintf(fp, if(fprintf(fp,
@ -2796,6 +2830,7 @@ int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch,
SECOND_PASS_ONLY; SECOND_PASS_ONLY;
conf_set_str(conf, CONF_line_codepage, val); conf_set_str(conf, CONF_line_codepage, val);
#ifndef NOT_X_WINDOWS
} else if (!strcmp(p, "-geometry")) { } else if (!strcmp(p, "-geometry")) {
int flags, x, y; int flags, x, y;
unsigned int w, h; unsigned int w, h;
@ -2815,6 +2850,7 @@ int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch,
inst->gravity = ((flags & XNegative ? 1 : 0) | inst->gravity = ((flags & XNegative ? 1 : 0) |
(flags & YNegative ? 2 : 0)); (flags & YNegative ? 2 : 0));
} }
#endif
} else if (!strcmp(p, "-sl")) { } else if (!strcmp(p, "-sl")) {
EXPECTS_ARG; EXPECTS_ARG;