+static void block_signal(int sig, int block_it) {
+ sigset_t ss;
+
+ sigemptyset(&ss);
+ sigaddset(&ss, sig);
+ if(sigprocmask(block_it ? SIG_BLOCK : SIG_UNBLOCK, &ss, 0) < 0) {
+ perror("sigprocmask");
+ exit(1);
+ }
+}
+
+/*
+ * This function retrieves the character set encoding of a font. It
+ * returns the character set without the X11 hack (in case the user
+ * asks to use the font's own encoding).
+ */
+static int set_font_info(struct gui_data *inst, int fontid)
+{
+ GdkFont *font = inst->fonts[fontid];
+ XFontStruct *xfs = GDK_FONT_XFONT(font);
+ Display *disp = GDK_FONT_XDISPLAY(font);
+ Atom charset_registry, charset_encoding;
+ unsigned long registry_ret, encoding_ret;
+ int retval = CS_NONE;
+
+ charset_registry = XInternAtom(disp, "CHARSET_REGISTRY", False);
+ charset_encoding = XInternAtom(disp, "CHARSET_ENCODING", False);
+ inst->fontinfo[fontid].charset = CS_NONE;
+ inst->fontinfo[fontid].is_wide = 0;
+ if (XGetFontProperty(xfs, charset_registry, ®istry_ret) &&
+ XGetFontProperty(xfs, charset_encoding, &encoding_ret)) {
+ char *reg, *enc;
+ reg = XGetAtomName(disp, (Atom)registry_ret);
+ enc = XGetAtomName(disp, (Atom)encoding_ret);
+ if (reg && enc) {
+ char *encoding = dupcat(reg, "-", enc, NULL);
+ retval = inst->fontinfo[fontid].charset =
+ charset_from_xenc(encoding);
+ /* FIXME: when libcharset supports wide encodings fix this. */
+ if (!strcasecmp(encoding, "iso10646-1")) {
+ inst->fontinfo[fontid].is_wide = 1;
+ retval = CS_UTF8;
+ }
+
+ /*
+ * Hack for X line-drawing characters: if the primary
+ * font is encoded as ISO-8859-anything, and has valid
+ * glyphs in the first 32 char positions, it is assumed
+ * that those glyphs are the VT100 line-drawing
+ * character set.
+ *
+ * Actually, we'll hack even harder by only checking
+ * position 0x19 (vertical line, VT100 linedrawing
+ * `x'). Then we can check it easily by seeing if the
+ * ascent and descent differ.
+ */
+ if (inst->fontinfo[fontid].charset == CS_ISO8859_1) {
+ int lb, rb, wid, asc, desc;
+ gchar text[2];
+
+ text[1] = '\0';
+ text[0] = '\x12';
+ gdk_string_extents(inst->fonts[fontid], text,
+ &lb, &rb, &wid, &asc, &desc);
+ if (asc != desc)
+ inst->fontinfo[fontid].charset = CS_ISO8859_1_X11;
+ }
+
+ sfree(encoding);
+ }
+ }
+
+ return retval;
+}
+
+int uxsel_input_add(int fd, int rwx) {
+ int flags = 0;
+ if (rwx & 1) flags |= GDK_INPUT_READ;
+ if (rwx & 2) flags |= GDK_INPUT_WRITE;
+ if (rwx & 4) flags |= GDK_INPUT_EXCEPTION;
+ return gdk_input_add(fd, flags, fd_input_func, NULL);
+}
+
+void uxsel_input_remove(int id) {
+ gdk_input_remove(id);
+}
+
+int pt_main(int argc, char **argv)