annotate src/balloon-x.c @ 134:34a5b81f86ba r20-2b1

Import from CVS: tag r20-2b1
author cvs
date Mon, 13 Aug 2007 09:30:11 +0200
parents
children b980b6286996
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
1 #include <config.h>
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
2 #include "lisp.h"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
3
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
4 #include "device.h"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
5 #include "console-x.h"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
6
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
7 #include "balloon_help.h"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
8
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
9 /* ### start of hack */
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
10
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
11 static unsigned long alloc_color( Display* dpy, const char* colorname, int light )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
12 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
13 Colormap cmap = DefaultColormap( dpy, DefaultScreen(dpy) );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
14 unsigned long pixel = 0;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
15 XColor color;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
16
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
17 if( XParseColor(dpy, cmap, colorname, &color) && XAllocColor(dpy, cmap, &color) )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
18 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
19 pixel = color.pixel;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
20 }
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
21 else
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
22 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
23 if( light )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
24 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
25 printf("Warning: could not allocate color \"%s\", using \"white\"\n", colorname);
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
26 pixel = alloc_color( dpy, "white", True );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
27 }
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
28 else
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
29 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
30 printf("Warning: could not allocate color \"%s\", using \"black\"\n", colorname);
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
31 pixel = alloc_color( dpy, "black", True );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
32 }
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
33 }
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
34 return pixel;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
35 }
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
36
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
37 static XFontStruct* open_font( Display* dpy, const char* font_name )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
38 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
39 XFontStruct* fontStruct = NULL;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
40
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
41 fontStruct = XLoadQueryFont( dpy, font_name ? font_name : "fixed" );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
42 if( fontStruct == NULL )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
43 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
44 printf("Warning: could not load font \"%s\", using \"fixed\".\n", font_name);
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
45 fontStruct = XLoadQueryFont( dpy, "fixed" );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
46 assert( fontStruct != NULL );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
47 }
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
48 return fontStruct;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
49 }
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
50
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
51 static void init( void )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
52 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
53 static int init;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
54
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
55 if( !init )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
56 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
57 Pixel fg, bg, shine, shadow;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
58 XFontStruct* font;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
59 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (Vdefault_x_device));
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
60
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
61 fg = alloc_color( dpy, "grey60", 1 );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
62 bg = alloc_color( dpy, "black", 0 );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
63
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
64 shine = alloc_color( dpy, "grey80", 1 );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
65 shadow = alloc_color( dpy, "grey40", 0 );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
66
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
67 font = open_font( dpy, "-adobe-helvetica-medium-r-normal--12-*" );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
68
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
69 balloon_help_create( dpy, bg, fg, shine, shadow, font );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
70 init = 1;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
71 }
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
72 }
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
73
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
74 /* ### end of hack */
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
75
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
76 DEFUN( "show-balloon-help", Fshow_balloon_help, 1, 1, 0, /*
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
77 Show balloon help.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
78 */
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
79 (string))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
80 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
81 char *p;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
82 CHECK_STRING (string);
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
83
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
84 p = (char *) XSTRING_DATA (string);
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
85
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
86 init();
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
87
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
88 balloon_help_show( p );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
89
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
90 return Qnil;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
91 }
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
92
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
93 DEFUN( "hide-balloon-help", Fhide_balloon_help, 0, 0, 0, /*
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
94 Hide balloon help.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
95 */
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
96 ())
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
97 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
98 init();
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
99
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
100 balloon_help_hide();
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
101
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
102 return Qnil;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
103 }
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
104
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
105 DEFUN( "balloon-help-move-to-pointer", Fballoon_help_move_to_pointer, 0, 0, 0, /*
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
106 Hide balloon help.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
107 */
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
108 ())
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
109 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
110 init();
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
111
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
112 balloon_help_move_to_pointer();
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
113
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
114 return Qnil;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
115 }
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
116
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
117
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
118
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
119 /************************************************************************/
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
120 /* initialization */
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
121 /************************************************************************/
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
122
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
123 void
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
124 syms_of_balloon_x (void)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
125 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
126 DEFSUBR( Fshow_balloon_help );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
127 DEFSUBR( Fhide_balloon_help );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
128 DEFSUBR( Fballoon_help_move_to_pointer );
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
129 }
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
130
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
131 void
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
132 vars_of_balloon_x (void)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
133 {
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
134 Fprovide (intern ("balloon-help"));
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents:
diff changeset
135 }