MGlyph *, MGlyph *, int, MDrawRegion);
MFontDriver xft_driver =
- { NULL, /* Set to ft_select in mwin__init (). */
+ { NULL, /* Set to ft_select in device_init (). */
xft_open, xft_find_metric,
- NULL, /* Set to ft_encode_char in mwin__init (). */
+ NULL, /* Set to ft_encode_char in device_init (). */
xft_render };
\f
/* Functions for the device driver. */
-static int
-mwin__device_init ()
-{
- M_iso8859_1 = msymbol ("iso8859-1");
- M_iso10646_1 = msymbol ("iso10646-1");
-
- display_info_list = mplist ();
- device_list = mplist ();
-
- Mxim = msymbol ("xim");
- msymbol_put (Mxim, Minput_driver, &minput_xim_driver);
-
- return 0;
-}
-
-static int
-mwin__device_fini ()
-{
- M17N_OBJECT_UNREF (display_info_list);
- M17N_OBJECT_UNREF (device_list);
- return 0;
-}
-
-/** Return an MWDevice object corresponding to a display specified in
- PLIST.
-
- It searches device_list for a device matching the display. If
- found, return the found object. Otherwise, return a newly created
- object. */
-
-static int
-mwin__open_device (MFrame *frame, MPlist *param)
-{
- Display *display = NULL;
- Screen *screen = NULL;
- int screen_num;
- Drawable drawable = 0;
- Widget widget = NULL;
- Colormap cmap = 0;
- int auto_display = 0;
- MDisplayInfo *disp_info = NULL;
- MWDevice *device = NULL;
- MSymbol key;
- XWindowAttributes attr;
- unsigned depth = 0;
- MPlist *plist;
- AppData app_data;
- MFace *face;
-
- for (plist = param; (key = mplist_key (plist)) != Mnil;
- plist = mplist_next (plist))
- {
- if (key == Mdisplay)
- display = (Display *) mplist_value (plist);
- else if (key == Mscreen)
- screen = mplist_value (plist);
- else if (key == Mdrawable)
- drawable = (Drawable) mplist_value (plist);
- else if (key == Mdepth)
- depth = (unsigned) mplist_value (plist);
- else if (key == Mwidget)
- widget = (Widget) mplist_value (plist);
- else if (key == Mcolormap)
- cmap = (Colormap) mplist_value (plist);
- }
-
- if (widget)
- {
- display = XtDisplay (widget);
- screen_num = XScreenNumberOfScreen (XtScreen (widget));
- depth = DefaultDepth (display, screen_num);
- }
- else if (drawable)
- {
- Window root_window;
- int x, y;
- unsigned width, height, border_width;
-
- if (! display)
- MERROR (MERROR_WIN, -1);
- XGetGeometry (display, drawable, &root_window,
- &x, &y, &width, &height, &border_width, &depth);
- XGetWindowAttributes (display, root_window, &attr);
- screen_num = XScreenNumberOfScreen (attr.screen);
- }
- else
- {
- if (screen)
- display = DisplayOfScreen (screen);
- else
- {
- if (! display)
- {
- display = XOpenDisplay (NULL);
- if (! display)
- MERROR (MERROR_WIN, -1);
- auto_display = 1;
- }
- screen = DefaultScreenOfDisplay (display);
- }
- screen_num = XScreenNumberOfScreen (screen);
- if (! depth)
- depth = DefaultDepth (display, screen_num);
- }
-
- if (! cmap)
- cmap = DefaultColormap (display, screen_num);
-
- for (plist = display_info_list; mplist_key (plist) != Mnil;
- plist = mplist_next (plist))
- {
- disp_info = (MDisplayInfo *) mplist_value (plist);
- if (disp_info->display == display)
- break;
- }
-
- if (mplist_key (plist) != Mnil)
- M17N_OBJECT_REF (disp_info);
- else
- {
- M17N_OBJECT (disp_info, free_display_info, MERROR_WIN);
- disp_info->display = display;
- disp_info->auto_display = auto_display;
- disp_info->font_registry_list = mplist ();
- disp_info->iso8859_1_family_list = mplist ();
- disp_info->iso10646_1_family_list = mplist ();
- disp_info->realized_font_list = mplist ();
- find_modifier_bits (disp_info);
- mplist_add (display_info_list, Mt, disp_info);
- }
-
- for (plist = device_list; mplist_key (plist) != Mnil;
- plist = mplist_next (plist))
- {
- device = (MWDevice *) mplist_value (plist);
- if (device->display_info == disp_info
- && device->depth == depth
- && device->cmap == cmap)
- break;
- }
-
- if (mplist_key (plist) != Mnil)
- M17N_OBJECT_REF (device);
- else
- {
- unsigned long valuemask = GCForeground;
- XGCValues values;
-
- M17N_OBJECT (device, free_device, MERROR_WIN);
- device->display_info = disp_info;
- device->screen_num = screen_num;
- /* A drawable on which to create GCs. */
- device->drawable = XCreatePixmap (display,
- RootWindow (display, screen_num),
- 1, 1, depth);
- device->depth = depth;
- device->cmap = cmap;
- device->realized_face_list = mplist ();
- device->realized_fontset_list = mplist ();
- device->gc_list = mplist ();
- values.foreground = BlackPixel (display, screen_num);
- device->scratch_gc = XCreateGC (display, device->drawable,
- valuemask, &values);
-#ifdef HAVE_XFT2
- device->xft_draw = XftDrawCreate (display, device->drawable,
- DefaultVisual (display, screen_num),
- cmap);
-#endif
- }
-
- frame->device = device;
- frame->device_type = MDEVICE_SUPPORT_OUTPUT | MDEVICE_SUPPORT_INPUT;
- frame->font_driver_list = mplist ();
- mplist_add (frame->font_driver_list, Mx, &xfont_driver);
-#ifdef HAVE_XFT2
- mplist_add (frame->font_driver_list, Mfreetype, &xft_driver);
-#elif HAVE_FREETYPE
- mplist_add (frame->font_driver_list, Mfreetype, &mfont__ft_driver);
-#endif
- frame->realized_font_list = disp_info->realized_font_list;
- frame->realized_face_list = device->realized_face_list;
- frame->realized_fontset_list = device->realized_fontset_list;
-
- if (widget)
- {
- XtResource resources[] = {
- { XtNfont, XtCFont, XtRString, sizeof (String),
- XtOffset (AppDataPtr, font), XtRString, DEFAULT_FONT },
- { XtNforeground, XtCForeground, XtRString, sizeof (String),
- XtOffset (AppDataPtr, foreground), XtRString, "black" },
- { XtNbackground, XtCBackground, XtRString, sizeof (String),
- XtOffset (AppDataPtr, background), XtRString, "white" },
- { XtNreverseVideo, XtCReverseVideo, XtRBoolean, sizeof (Boolean),
- XtOffset (AppDataPtr, reverse_video), XtRImmediate, (caddr_t) FALSE }
- };
-
- XtGetApplicationResources (widget, &app_data,
- resources, XtNumber (resources), NULL, 0);
- frame->foreground = msymbol (app_data.foreground);
- frame->background = msymbol (app_data.background);
- frame->videomode = app_data.reverse_video == True ? Mreverse : Mnormal;
- }
- else
- {
- app_data.font = DEFAULT_FONT;
- frame->foreground = msymbol ("black");
- frame->background = msymbol ("white");
- frame->videomode = Mnormal;
- }
-
- {
- int nfonts;
- char **names = XListFonts (display, app_data.font, 1, &nfonts);
-
- if (nfonts > 0)
- {
- if (! (frame->font = mfont_parse_name (names[0], Mx)))
- {
- /* The font name does not conform to XLFD. Try to open the
- font and get XA_FONT property. */
- XFontStruct *xfont = XLoadQueryFont (display, names[0]);
-
- nfonts = 0;
- if (xfont)
- {
- unsigned long value;
- char *name;
-
- if (XGetFontProperty (xfont, XA_FONT, &value)
- && (name = ((char *)
- XGetAtomName (display, (Atom) value))))
- {
- if ((frame->font = mfont_parse_name (name, Mx)))
- nfonts = 1;
- }
- XFreeFont (display, xfont);
- }
- }
- XFreeFontNames (names);
- }
- if (! nfonts)
- frame->font = mfont_parse_name (FALLBACK_FONT, Mx);
- }
-
- face = mface_from_font (frame->font);
- face->property[MFACE_FONTSET] = mfontset (NULL);
- face->property[MFACE_FOREGROUND] = frame->foreground;
- face->property[MFACE_BACKGROUND] = frame->background;
- mface_put_prop (face, Mhline, mface_get_prop (mface__default, Mhline));
- mface_put_prop (face, Mbox, mface_get_prop (mface__default, Mbox));
- face->property[MFACE_VIDEOMODE] = frame->videomode;
- mface_put_prop (face, Mhook_func,
- mface_get_prop (mface__default, Mhook_func));
- face->property[MFACE_RATIO] = (void *) 100;
- mplist_push (param, Mface, face);
- M17N_OBJECT_UNREF (face);
-
-#ifdef X_SET_ERROR_HANDLER
- XSetErrorHandler (x_error_handler);
- XSetIOErrorHandler (x_io_error_handler);
-#endif
-
- return 0;
-}
-
-
static void
mwin__close_device (MFrame *frame)
{
new->width = 1;
values.width = current->width = new->width;
}
- if (current->height != new->height)
+ if (current->height != new->height)
+ {
+ mask |= CWHeight;
+ if (new->height <= 0)
+ new->height = 1;
+ values.height = current->height = new->height;
+ }
+ if (current->x != new->x)
+ {
+ mask |= CWX;
+ values.x = current->x = new->x;
+ }
+ if (current->y != new->y)
+ {
+ mask |= CWY;
+ current->y = new->y;
+ values.y = current->y = new->y;
+ }
+ if (mask)
+ XConfigureWindow (display, (Window) win, mask, &values);
+ XClearWindow (display, (Window) win);
+}
+
+static MSymbol
+mwin__parse_event (MFrame *frame, void *arg, int *modifiers)
+{
+ XEvent *event = (XEvent *) arg;
+ MDisplayInfo *disp_info = FRAME_DEVICE (frame)->display_info;
+ int len;
+ char buf[512];
+ KeySym keysym;
+ MSymbol key;
+
+ *modifiers = 0;
+ if (event->xany.type != KeyPress
+ /* && event->xany.type != KeyRelease */
+ )
+ return Mnil;
+ len = XLookupString ((XKeyEvent *) event, (char *) buf, 512, &keysym, NULL);
+ if (len > 1)
+ return Mnil;
+ if (len == 1)
+ {
+ int c = keysym;
+
+ if (c < XK_space || c > XK_asciitilde)
+ c = buf[0];
+ if ((c == ' ' || c == 127) && ((XKeyEvent *) event)->state & ShiftMask)
+ *modifiers |= MINPUT_KEY_SHIFT_MODIFIER;
+ if (((XKeyEvent *) event)->state & ControlMask)
+ {
+ if (c >= 'a' && c <= 'z')
+ c += 'A' - 'a';
+ if (c >= ' ' && c < 127)
+ *modifiers |= MINPUT_KEY_CONTROL_MODIFIER;
+ }
+ key = minput__char_to_key (c);
+ }
+ else if (keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
+ return Mnil;
+ else
+ {
+ char *str = XKeysymToString (keysym);
+
+ if (! str)
+ return Mnil;
+ key = msymbol (str);
+ if (((XKeyEvent *) event)->state & ShiftMask)
+ *modifiers |= MINPUT_KEY_SHIFT_MODIFIER;
+ if (((XKeyEvent *) event)->state & ControlMask)
+ *modifiers |= MINPUT_KEY_CONTROL_MODIFIER;
+ }
+ if (((XKeyEvent *) event)->state & disp_info->meta_mask)
+ *modifiers |= MINPUT_KEY_META_MODIFIER;
+ if (((XKeyEvent *) event)->state & disp_info->alt_mask)
+ *modifiers |= MINPUT_KEY_ALT_MODIFIER;
+ if (((XKeyEvent *) event)->state & disp_info->super_mask)
+ *modifiers |= MINPUT_KEY_SUPER_MODIFIER;
+ if (((XKeyEvent *) event)->state & disp_info->hyper_mask)
+ *modifiers |= MINPUT_KEY_HYPER_MODIFIER;
+
+ return key;
+}
+
+
+void
+mwin__dump_gc (MFrame *frame, MRealizedFace *rface)
+{
+ unsigned long valuemask = GCForeground | GCBackground | GCClipMask;
+ XGCValues values;
+ Display *display = FRAME_DISPLAY (frame);
+ GCInfo *info = rface->info;
+ int i;
+
+ for (i = 0; i <= GC_INVERSE; i++)
+ {
+ XGetGCValues (display, info->gc[i], valuemask, &values);
+ fprintf (stderr, "GC%d: fore/#%lX back/#%lX", i,
+ values.foreground, values.background);
+ fprintf (stderr, "\n");
+ }
+}
+
+static MDeviceDriver x_driver =
+ {
+ mwin__close_device,
+ mwin__device_get_prop,
+ mwin__realize_face,
+ mwin__free_realized_face,
+ mwin__fill_space,
+ mwin__draw_empty_boxes,
+ mwin__draw_hline,
+ mwin__draw_box,
+ mwin__draw_points,
+ mwin__region_from_rect,
+ mwin__union_rect_with_region,
+ mwin__intersect_region,
+ mwin__region_add_rect,
+ mwin__region_to_rect,
+ mwin__free_region,
+ mwin__dump_region,
+ mwin__create_window,
+ mwin__destroy_window,
+ mwin__map_window,
+ mwin__unmap_window,
+ mwin__window_geometry,
+ mwin__adjust_window,
+ mwin__parse_event
+ };
+
+/* Functions to be stored in MDeviceLibraryInterface by dlsym (). */
+
+int
+device_init ()
+{
+ M_iso8859_1 = msymbol ("iso8859-1");
+ M_iso10646_1 = msymbol ("iso10646-1");
+
+ display_info_list = mplist ();
+ device_list = mplist ();
+
+#ifdef HAVE_XFT2
+ xft_driver.select = mfont__ft_driver.select;
+ xft_driver.encode_char = mfont__ft_driver.encode_char;
+#endif
+
+ Mxim = msymbol ("xim");
+ msymbol_put (Mxim, Minput_driver, &minput_xim_driver);
+
+ return 0;
+}
+
+int
+device_fini ()
+{
+ M17N_OBJECT_UNREF (display_info_list);
+ M17N_OBJECT_UNREF (device_list);
+ return 0;
+}
+
+/** Return an MWDevice object corresponding to a display specified in
+ PLIST.
+
+ It searches device_list for a device matching the display. If
+ found, return the found object. Otherwise, return a newly created
+ object. */
+
+int
+device_open (MFrame *frame, MPlist *param)
+{
+ Display *display = NULL;
+ Screen *screen = NULL;
+ int screen_num;
+ Drawable drawable = 0;
+ Widget widget = NULL;
+ Colormap cmap = 0;
+ int auto_display = 0;
+ MDisplayInfo *disp_info = NULL;
+ MWDevice *device = NULL;
+ MSymbol key;
+ XWindowAttributes attr;
+ unsigned depth = 0;
+ MPlist *plist;
+ AppData app_data;
+ MFace *face;
+
+ for (plist = param; (key = mplist_key (plist)) != Mnil;
+ plist = mplist_next (plist))
+ {
+ if (key == Mdisplay)
+ display = (Display *) mplist_value (plist);
+ else if (key == Mscreen)
+ screen = mplist_value (plist);
+ else if (key == Mdrawable)
+ drawable = (Drawable) mplist_value (plist);
+ else if (key == Mdepth)
+ depth = (unsigned) mplist_value (plist);
+ else if (key == Mwidget)
+ widget = (Widget) mplist_value (plist);
+ else if (key == Mcolormap)
+ cmap = (Colormap) mplist_value (plist);
+ }
+
+ if (widget)
+ {
+ display = XtDisplay (widget);
+ screen_num = XScreenNumberOfScreen (XtScreen (widget));
+ depth = DefaultDepth (display, screen_num);
+ }
+ else if (drawable)
+ {
+ Window root_window;
+ int x, y;
+ unsigned width, height, border_width;
+
+ if (! display)
+ MERROR (MERROR_WIN, -1);
+ XGetGeometry (display, drawable, &root_window,
+ &x, &y, &width, &height, &border_width, &depth);
+ XGetWindowAttributes (display, root_window, &attr);
+ screen_num = XScreenNumberOfScreen (attr.screen);
+ }
+ else
+ {
+ if (screen)
+ display = DisplayOfScreen (screen);
+ else
+ {
+ if (! display)
+ {
+ display = XOpenDisplay (NULL);
+ if (! display)
+ MERROR (MERROR_WIN, -1);
+ auto_display = 1;
+ }
+ screen = DefaultScreenOfDisplay (display);
+ }
+ screen_num = XScreenNumberOfScreen (screen);
+ if (! depth)
+ depth = DefaultDepth (display, screen_num);
+ }
+
+ if (! cmap)
+ cmap = DefaultColormap (display, screen_num);
+
+ for (plist = display_info_list; mplist_key (plist) != Mnil;
+ plist = mplist_next (plist))
+ {
+ disp_info = (MDisplayInfo *) mplist_value (plist);
+ if (disp_info->display == display)
+ break;
+ }
+
+ if (mplist_key (plist) != Mnil)
+ M17N_OBJECT_REF (disp_info);
+ else
{
- mask |= CWHeight;
- if (new->height <= 0)
- new->height = 1;
- values.height = current->height = new->height;
- }
- if (current->x != new->x)
+ M17N_OBJECT (disp_info, free_display_info, MERROR_WIN);
+ disp_info->display = display;
+ disp_info->auto_display = auto_display;
+ disp_info->font_registry_list = mplist ();
+ disp_info->iso8859_1_family_list = mplist ();
+ disp_info->iso10646_1_family_list = mplist ();
+ disp_info->realized_font_list = mplist ();
+ find_modifier_bits (disp_info);
+ mplist_add (display_info_list, Mt, disp_info);
+ }
+
+ for (plist = device_list; mplist_key (plist) != Mnil;
+ plist = mplist_next (plist))
{
- mask |= CWX;
- values.x = current->x = new->x;
+ device = (MWDevice *) mplist_value (plist);
+ if (device->display_info == disp_info
+ && device->depth == depth
+ && device->cmap == cmap)
+ break;
}
- if (current->y != new->y)
+
+ if (mplist_key (plist) != Mnil)
+ M17N_OBJECT_REF (device);
+ else
{
- mask |= CWY;
- current->y = new->y;
- values.y = current->y = new->y;
+ unsigned long valuemask = GCForeground;
+ XGCValues values;
+
+ M17N_OBJECT (device, free_device, MERROR_WIN);
+ device->display_info = disp_info;
+ device->screen_num = screen_num;
+ /* A drawable on which to create GCs. */
+ device->drawable = XCreatePixmap (display,
+ RootWindow (display, screen_num),
+ 1, 1, depth);
+ device->depth = depth;
+ device->cmap = cmap;
+ device->realized_face_list = mplist ();
+ device->realized_fontset_list = mplist ();
+ device->gc_list = mplist ();
+ values.foreground = BlackPixel (display, screen_num);
+ device->scratch_gc = XCreateGC (display, device->drawable,
+ valuemask, &values);
+#ifdef HAVE_XFT2
+ device->xft_draw = XftDrawCreate (display, device->drawable,
+ DefaultVisual (display, screen_num),
+ cmap);
+#endif
}
- if (mask)
- XConfigureWindow (display, (Window) win, mask, &values);
- XClearWindow (display, (Window) win);
-}
-static MSymbol
-mwin__parse_event (MFrame *frame, void *arg, int *modifiers)
-{
- XEvent *event = (XEvent *) arg;
- MDisplayInfo *disp_info = FRAME_DEVICE (frame)->display_info;
- int len;
- char buf[512];
- KeySym keysym;
- MSymbol key;
+ frame->device = device;
+ frame->device_type = MDEVICE_SUPPORT_OUTPUT | MDEVICE_SUPPORT_INPUT;
+ frame->driver = &x_driver;
+ frame->font_driver_list = mplist ();
+ mplist_add (frame->font_driver_list, Mx, &xfont_driver);
+#ifdef HAVE_XFT2
+ mplist_add (frame->font_driver_list, Mfreetype, &xft_driver);
+#elif HAVE_FREETYPE
+ mplist_add (frame->font_driver_list, Mfreetype, &mfont__ft_driver);
+#endif
+ frame->realized_font_list = disp_info->realized_font_list;
+ frame->realized_face_list = device->realized_face_list;
+ frame->realized_fontset_list = device->realized_fontset_list;
- *modifiers = 0;
- if (event->xany.type != KeyPress
- /* && event->xany.type != KeyRelease */
- )
- return Mnil;
- len = XLookupString ((XKeyEvent *) event, (char *) buf, 512, &keysym, NULL);
- if (len > 1)
- return Mnil;
- if (len == 1)
+ if (widget)
{
- int c = keysym;
+ XtResource resources[] = {
+ { XtNfont, XtCFont, XtRString, sizeof (String),
+ XtOffset (AppDataPtr, font), XtRString, DEFAULT_FONT },
+ { XtNforeground, XtCForeground, XtRString, sizeof (String),
+ XtOffset (AppDataPtr, foreground), XtRString, "black" },
+ { XtNbackground, XtCBackground, XtRString, sizeof (String),
+ XtOffset (AppDataPtr, background), XtRString, "white" },
+ { XtNreverseVideo, XtCReverseVideo, XtRBoolean, sizeof (Boolean),
+ XtOffset (AppDataPtr, reverse_video), XtRImmediate, (caddr_t) FALSE }
+ };
- if (c < XK_space || c > XK_asciitilde)
- c = buf[0];
- if ((c == ' ' || c == 127) && ((XKeyEvent *) event)->state & ShiftMask)
- *modifiers |= MINPUT_KEY_SHIFT_MODIFIER;
- if (((XKeyEvent *) event)->state & ControlMask)
- {
- if (c >= 'a' && c <= 'z')
- c += 'A' - 'a';
- if (c >= ' ' && c < 127)
- *modifiers |= MINPUT_KEY_CONTROL_MODIFIER;
- }
- key = minput__char_to_key (c);
+ XtGetApplicationResources (widget, &app_data,
+ resources, XtNumber (resources), NULL, 0);
+ frame->foreground = msymbol (app_data.foreground);
+ frame->background = msymbol (app_data.background);
+ frame->videomode = app_data.reverse_video == True ? Mreverse : Mnormal;
}
- else if (keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
- return Mnil;
else
{
- char *str = XKeysymToString (keysym);
-
- if (! str)
- return Mnil;
- key = msymbol (str);
- if (((XKeyEvent *) event)->state & ShiftMask)
- *modifiers |= MINPUT_KEY_SHIFT_MODIFIER;
- if (((XKeyEvent *) event)->state & ControlMask)
- *modifiers |= MINPUT_KEY_CONTROL_MODIFIER;
+ app_data.font = DEFAULT_FONT;
+ frame->foreground = msymbol ("black");
+ frame->background = msymbol ("white");
+ frame->videomode = Mnormal;
}
- if (((XKeyEvent *) event)->state & disp_info->meta_mask)
- *modifiers |= MINPUT_KEY_META_MODIFIER;
- if (((XKeyEvent *) event)->state & disp_info->alt_mask)
- *modifiers |= MINPUT_KEY_ALT_MODIFIER;
- if (((XKeyEvent *) event)->state & disp_info->super_mask)
- *modifiers |= MINPUT_KEY_SUPER_MODIFIER;
- if (((XKeyEvent *) event)->state & disp_info->hyper_mask)
- *modifiers |= MINPUT_KEY_HYPER_MODIFIER;
- return key;
-}
+ {
+ int nfonts;
+ char **names = XListFonts (display, app_data.font, 1, &nfonts);
+ if (nfonts > 0)
+ {
+ if (! (frame->font = mfont_parse_name (names[0], Mx)))
+ {
+ /* The font name does not conform to XLFD. Try to open the
+ font and get XA_FONT property. */
+ XFontStruct *xfont = XLoadQueryFont (display, names[0]);
-void
-mwin__dump_gc (MFrame *frame, MRealizedFace *rface)
-{
- unsigned long valuemask = GCForeground | GCBackground | GCClipMask;
- XGCValues values;
- Display *display = FRAME_DISPLAY (frame);
- GCInfo *info = rface->info;
- int i;
+ nfonts = 0;
+ if (xfont)
+ {
+ unsigned long value;
+ char *name;
- for (i = 0; i <= GC_INVERSE; i++)
- {
- XGetGCValues (display, info->gc[i], valuemask, &values);
- fprintf (stderr, "GC%d: fore/#%lX back/#%lX", i,
- values.foreground, values.background);
- fprintf (stderr, "\n");
- }
-}
+ if (XGetFontProperty (xfont, XA_FONT, &value)
+ && (name = ((char *)
+ XGetAtomName (display, (Atom) value))))
+ {
+ if ((frame->font = mfont_parse_name (name, Mx)))
+ nfonts = 1;
+ }
+ XFreeFont (display, xfont);
+ }
+ }
+ XFreeFontNames (names);
+ }
+ if (! nfonts)
+ frame->font = mfont_parse_name (FALLBACK_FONT, Mx);
+ }
-static MDeviceDriver x_driver =
- {
- 0,
- mwin__device_init,
- mwin__device_fini,
- mwin__open_device,
- mwin__close_device,
- mwin__device_get_prop,
- mwin__realize_face,
- mwin__free_realized_face,
- mwin__fill_space,
- mwin__draw_empty_boxes,
- mwin__draw_hline,
- mwin__draw_box,
- mwin__draw_points,
- mwin__region_from_rect,
- mwin__union_rect_with_region,
- mwin__intersect_region,
- mwin__region_add_rect,
- mwin__region_to_rect,
- mwin__free_region,
- mwin__dump_region,
- mwin__create_window,
- mwin__destroy_window,
- mwin__map_window,
- mwin__unmap_window,
- mwin__window_geometry,
- mwin__adjust_window,
- mwin__parse_event
- };
+ face = mface_from_font (frame->font);
+ face->property[MFACE_FONTSET] = mfontset (NULL);
+ face->property[MFACE_FOREGROUND] = frame->foreground;
+ face->property[MFACE_BACKGROUND] = frame->background;
+ mface_put_prop (face, Mhline, mface_get_prop (mface__default, Mhline));
+ mface_put_prop (face, Mbox, mface_get_prop (mface__default, Mbox));
+ face->property[MFACE_VIDEOMODE] = frame->videomode;
+ mface_put_prop (face, Mhook_func,
+ mface_get_prop (mface__default, Mhook_func));
+ face->property[MFACE_RATIO] = (void *) 100;
+ mplist_push (param, Mface, face);
+ M17N_OBJECT_UNREF (face);
+
+#ifdef X_SET_ERROR_HANDLER
+ XSetErrorHandler (x_error_handler);
+ XSetIOErrorHandler (x_io_error_handler);
+#endif
+
+ return 0;
+}
\f
}
#endif
+/*=*/
+
/*** @} */
#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
\f
/* External API */
-int
-m17n_init_X ()
-{
- x_driver.initialized = 0;
- mplist_put (m17n__device_library_list, Mx, &x_driver);
-
-#ifdef HAVE_XFT2
- xft_driver.select = mfont__ft_driver.select;
- xft_driver.encode_char = mfont__ft_driver.encode_char;
-#endif
-
- return 0;
-}
-
-/*=*/
/*** @addtogroup m17nInputMethodWin */
/*=*/
/*** @{ */
#define DLOPEN_SHLIB_EXT ".so"
#endif
+/** Information about a dynamic library supporting a specific graphic
+ device. */
+typedef struct
+{
+ /** Name of the dynamic library (e.g. "libm17n-X.so"). */
+ char *library;
+ /** Handle fo the dynamic library. */
+ void *handle;
+ /** Function to call just after loading the library. */
+ int (*init) ();
+ /** Function to call to open a frame on the graphic device. */
+ int (*open) (MFrame *frame, MPlist *param);
+ /** Function to call just before unloading the library. */
+ int (*fini) ();
+} MDeviceLibraryInterface;
+
+
+/** Plist of device symbol vs MDeviceLibraryInterface. */
+
+static MPlist *device_library_list;
+
/** Close MFrame and free it. */
static void
free (object);
}
+
+/** Register a dynamic library of name LIB by a key NAME. */
+
+static int
+register_device_library (MSymbol name, char *lib)
+{
+ MDeviceLibraryInterface *interface;
+
+ MSTRUCT_CALLOC (interface, MERROR_WIN);
+ interface->library = malloc (strlen (lib)
+ + strlen (DLOPEN_SHLIB_EXT) + 1);
+ sprintf (interface->library, "%s%s", lib, DLOPEN_SHLIB_EXT);
+ if (! device_library_list)
+ device_library_list = mplist ();
+ mplist_add (device_library_list, name, interface);
+ return 0;
+}
+
\f
#ifdef HAVE_FREETYPE
/** Null device support. */
MPlist *realized_face_list;
} null_device;
+static void
+null_device_close (MFrame *frame)
+{
+}
+
+static void *
+null_device_get_prop (MFrame *frame, MSymbol key)
+{
+ return NULL;
+}
+
+static void
+null_device_realize_face (MRealizedFace *rface)
+{
+ rface->info = NULL;
+}
+
+static void
+null_device_free_realized_face (MRealizedFace *rface)
+{
+}
+
+static MDeviceDriver null_driver =
+ {
+ null_device_close,
+ null_device_get_prop,
+ null_device_realize_face,
+ null_device_free_realized_face
+ };
+
static int
null_device_init ()
{
frame->device = NULL;
frame->device_type = 0;
+ frame->driver = &null_driver;
frame->font_driver_list = mplist ();
mplist_add (frame->font_driver_list, Mfreetype, &mfont__ft_driver);
frame->realized_font_list = null_device.realized_font_list;
return 0;
}
-static void
-null_device_close (MFrame *frame)
-{
-}
-
-static void *
-null_device_get_prop (MFrame *frame, MSymbol key)
-{
- return NULL;
-}
-
-static void
-null_device_realize_face (MRealizedFace *rface)
-{
- rface->info = NULL;
-}
-
-static void
-null_device_free_realized_face (MRealizedFace *rface)
-{
-}
-
-static MDeviceDriver null_driver =
- {
- 0,
- null_device_init,
- null_device_fini,
- null_device_open,
- null_device_close,
- null_device_get_prop,
- null_device_realize_face,
- null_device_free_realized_face
- };
+static MDeviceLibraryInterface null_interface =
+ { NULL, NULL, null_device_init, null_device_open, null_device_fini };
#endif
\f
MSymbol Mfreetype;
-/** Plist of device symbol vs functions to initialized the device
- library. */
-MPlist *m17n__device_library_list;
-
-
/*** @} */
#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
Mdepth = msymbol ("depth");
Mwidget = msymbol ("widget");
+ register_device_library (Mx, "libm17n-X");
+ register_device_library (Mgd, "libm17n-gd");
+
MDEBUG_PUSH_TIME ();
if (mfont__init () < 0)
goto err;
goto err;
MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize input-win module."));
mframe_default = NULL;
-
- m17n__device_library_list = mplist ();
-#ifdef HAVE_FREETYPE
- null_driver.initialized = 0;
- mplist_put (m17n__device_library_list, Mt, &null_driver);
-#endif
-
return 0;
err:
MDEBUG_PUSH_TIME ();
MDEBUG_PUSH_TIME ();
MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize device modules."));
- MPLIST_DO (plist, m17n__device_library_list)
+ MPLIST_DO (plist, device_library_list)
{
- MDeviceDriver *driver = MPLIST_VAL (plist);
+ MDeviceLibraryInterface *interface = MPLIST_VAL (plist);
- if (driver->initialized)
+ if (interface->handle && interface->fini)
{
- (*driver->fini) ();
- driver->initialized = 0;
+ (*interface->fini) ();
+ dlclose (interface->handle);
}
+ free (interface->library);
}
- M17N_OBJECT_UNREF (m17n__device_library_list);
+#ifdef HAVE_FREETYPE
+ if (null_interface.handle)
+ (*null_interface.fini) ();
+#endif /* not HAVE_FREETYPE */
+ M17N_OBJECT_UNREF (device_library_list);
MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize input-gui module."));
minput__win_fini ();
MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize draw module."));
int plist_created = 0;
MPlist *pl;
MSymbol device;
- MDeviceDriver *driver;
+ MDeviceLibraryInterface *interface;
if (plist)
{
pl = mplist_find_by_key (plist, Mdevice);
if (pl)
- {
- device = MPLIST_VAL (pl);
- if (device == Mt)
- MERROR (MERROR_WIN, NULL);
- if (device == Mnil)
- device = Mt;
- }
+ device = MPLIST_VAL (pl);
else
device = Mx;
}
device = Mx;
}
- driver = mplist_get (m17n__device_library_list, device);
- if (! driver)
- MERROR (MERROR_WIN, NULL);
- if (! driver->initialized)
+ if (device == Mnil)
{
- if ((*driver->init) () < 0)
+#ifdef HAVE_FREETYPE
+ interface = &null_interface;
+ if (! interface->handle)
+ {
+ (*interface->init) ();
+ interface->handle = (void *) 1;
+ }
+#else /* not HAVE_FREETYPE */
+ MERROR (MERROR_WIN, NULL);
+#endif /* not HAVE_FREETYPE */
+ }
+ else
+ {
+ interface = mplist_get (device_library_list, device);
+ if (! interface)
MERROR (MERROR_WIN, NULL);
- driver->initialized = 1;
- }
+ if (! interface->handle)
+ {
+ interface->handle = dlopen (interface->library, RTLD_NOW);
+ if (! interface->handle)
+ MERROR (MERROR_WIN, NULL);
+ interface->init = dlsym (interface->handle, "device_init");
+ interface->open = dlsym (interface->handle, "device_open");
+ interface->fini = dlsym (interface->handle, "device_fini");
+ if (! interface->init || ! interface->open || ! interface->fini
+ || (*interface->init) () < 0)
+ {
+ dlclose (interface->handle);
+ MERROR (MERROR_WIN, NULL);
+ }
+ }
+ }
M17N_OBJECT (frame, free_frame, MERROR_FRAME);
- if ((*driver->open) (frame, plist) < 0)
+ if ((*interface->open) (frame, plist) < 0)
{
free (frame);
MERROR (MERROR_WIN, NULL);
}
- frame->driver = driver;
if (! mframe_default)
mframe_default = frame;