comparison src/xfns.c @ 25528:b5dd1bafd001

Include math.h. Add extern declaration for atof in case we don't see one. (Qscreen_gamma): New. (struct x_frame_parm_table): Add prototypes, add x_set_screen_gamma. (gamma_correct): New function. (defined_color): Call it. (x_set_screen_gamma): New. (x_set_title): Add parameter old_value. (RES_TYPE_FLOAT): New. (x_get_arg): Handle RES_TYPE_FLOAT. (Fx_create_frame): Call x_default_parameter for `screen-gamma'. (lookup_pixel_color): Change call to x_alloc_nearest_color to new prototype. (lookup_rgb_color): Ditto. (syms_of_xfns): Initialize Qscreen_gamma.
author Gerd Moellmann <gerd@gnu.org>
date Fri, 03 Sep 1999 18:49:56 +0000
parents 9bc9d4d6c716
children 693ca9ba497a
comparison
equal deleted inserted replaced
25527:93b2f5b92137 25528:b5dd1bafd001
28 /* Rewritten for X11 by Joseph Arceneaux */ 28 /* Rewritten for X11 by Joseph Arceneaux */
29 29
30 #include <signal.h> 30 #include <signal.h>
31 #include <config.h> 31 #include <config.h>
32 #include <stdio.h> 32 #include <stdio.h>
33 #include <math.h>
33 34
34 /* This makes the fields of a Display accessible, in Xlib header files. */ 35 /* This makes the fields of a Display accessible, in Xlib header files. */
35 36
36 #define XLIB_ILLEGAL_ACCESS 37 #define XLIB_ILLEGAL_ACCESS
37 38
118 /* This is part of a kludge--see lwlib/xlwmenu.c. */ 119 /* This is part of a kludge--see lwlib/xlwmenu.c. */
119 extern XFontStruct *xlwmenu_default_font; 120 extern XFontStruct *xlwmenu_default_font;
120 #endif 121 #endif
121 122
122 extern void free_frame_menubar (); 123 extern void free_frame_menubar ();
124 extern double atof ();
123 125
124 #endif /* USE_X_TOOLKIT */ 126 #endif /* USE_X_TOOLKIT */
125 127
126 #define min(a,b) ((a) < (b) ? (a) : (b)) 128 #define min(a,b) ((a) < (b) ? (a) : (b))
127 #define max(a,b) ((a) > (b) ? (a) : (b)) 129 #define max(a,b) ((a) > (b) ? (a) : (b))
249 Lisp_Object Qx_resource_name; 251 Lisp_Object Qx_resource_name;
250 Lisp_Object Quser_position; 252 Lisp_Object Quser_position;
251 Lisp_Object Quser_size; 253 Lisp_Object Quser_size;
252 Lisp_Object Qdisplay; 254 Lisp_Object Qdisplay;
253 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background; 255 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
256 Lisp_Object Qscreen_gamma;
254 257
255 /* The below are defined in frame.c. */ 258 /* The below are defined in frame.c. */
256 259
257 extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth; 260 extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth;
258 extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle; 261 extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle;
739 that is an index in this table. */ 742 that is an index in this table. */
740 743
741 struct x_frame_parm_table 744 struct x_frame_parm_table
742 { 745 {
743 char *name; 746 char *name;
744 void (*setter)( /* struct frame *frame, Lisp_Object val, oldval */ ); 747 void (*setter) P_ ((struct frame *, Lisp_Object, Lisp_Object));
745 }; 748 };
746 749
747 void x_set_foreground_color (); 750 void x_set_foreground_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
748 void x_set_background_color (); 751 void x_set_background_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
749 void x_set_mouse_color (); 752 void x_set_mouse_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
750 void x_set_cursor_color (); 753 void x_set_cursor_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
751 void x_set_border_color (); 754 void x_set_border_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
752 void x_set_cursor_type (); 755 void x_set_cursor_type P_ ((struct frame *, Lisp_Object, Lisp_Object));
753 void x_set_icon_type (); 756 void x_set_icon_type P_ ((struct frame *, Lisp_Object, Lisp_Object));
754 void x_set_icon_name (); 757 void x_set_icon_name P_ ((struct frame *, Lisp_Object, Lisp_Object));
755 void x_set_font (); 758 void x_set_font P_ ((struct frame *, Lisp_Object, Lisp_Object));
756 void x_set_border_width (); 759 void x_set_border_width P_ ((struct frame *, Lisp_Object, Lisp_Object));
757 void x_set_internal_border_width (); 760 void x_set_internal_border_width P_ ((struct frame *, Lisp_Object,
758 void x_explicitly_set_name (); 761 Lisp_Object));
759 void x_set_autoraise (); 762 void x_explicitly_set_name P_ ((struct frame *, Lisp_Object, Lisp_Object));
760 void x_set_autolower (); 763 void x_set_autoraise P_ ((struct frame *, Lisp_Object, Lisp_Object));
761 void x_set_vertical_scroll_bars (); 764 void x_set_autolower P_ ((struct frame *, Lisp_Object, Lisp_Object));
762 void x_set_visibility (); 765 void x_set_vertical_scroll_bars P_ ((struct frame *, Lisp_Object,
763 void x_set_menu_bar_lines (); 766 Lisp_Object));
764 void x_set_scroll_bar_width (); 767 void x_set_visibility P_ ((struct frame *, Lisp_Object, Lisp_Object));
765 void x_set_title (); 768 void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
766 void x_set_unsplittable (); 769 void x_set_scroll_bar_width P_ ((struct frame *, Lisp_Object, Lisp_Object));
770 void x_set_title P_ ((struct frame *, Lisp_Object, Lisp_Object));
771 void x_set_unsplittable P_ ((struct frame *, Lisp_Object, Lisp_Object));
767 void x_set_toolbar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object)); 772 void x_set_toolbar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
768 void x_set_scroll_bar_foreground P_ ((struct frame *, Lisp_Object, 773 void x_set_scroll_bar_foreground P_ ((struct frame *, Lisp_Object,
769 Lisp_Object)); 774 Lisp_Object));
770 void x_set_scroll_bar_background P_ ((struct frame *, Lisp_Object, 775 void x_set_scroll_bar_background P_ ((struct frame *, Lisp_Object,
771 Lisp_Object)); 776 Lisp_Object));
772 static Lisp_Object x_default_scroll_bar_color_parameter P_ ((struct frame *, 777 static Lisp_Object x_default_scroll_bar_color_parameter P_ ((struct frame *,
773 Lisp_Object, 778 Lisp_Object,
774 Lisp_Object, 779 Lisp_Object,
775 char *, char *, 780 char *, char *,
776 int)); 781 int));
782 static void x_set_screen_gamma P_ ((struct frame *, Lisp_Object, Lisp_Object));
777 783
778 static struct x_frame_parm_table x_frame_parms[] = 784 static struct x_frame_parm_table x_frame_parms[] =
779 { 785 {
780 "auto-raise", x_set_autoraise, 786 "auto-raise", x_set_autoraise,
781 "auto-lower", x_set_autolower, 787 "auto-lower", x_set_autolower,
798 "vertical-scroll-bars", x_set_vertical_scroll_bars, 804 "vertical-scroll-bars", x_set_vertical_scroll_bars,
799 "visibility", x_set_visibility, 805 "visibility", x_set_visibility,
800 "toolbar-lines", x_set_toolbar_lines, 806 "toolbar-lines", x_set_toolbar_lines,
801 "scroll-bar-foreground", x_set_scroll_bar_foreground, 807 "scroll-bar-foreground", x_set_scroll_bar_foreground,
802 "scroll-bar-background", x_set_scroll_bar_background, 808 "scroll-bar-background", x_set_scroll_bar_background,
809 "screen-gamma", x_set_screen_gamma
803 }; 810 };
804 811
805 /* Attach the `x-frame-parameter' properties to 812 /* Attach the `x-frame-parameter' properties to
806 the Lisp symbol names of parameters relevant to X. */ 813 the Lisp symbol names of parameters relevant to X. */
807 814
1206 XSETFASTINT (tem, f->output_data.x->parent_desc); 1213 XSETFASTINT (tem, f->output_data.x->parent_desc);
1207 store_in_alist (alistptr, Qparent_id, tem); 1214 store_in_alist (alistptr, Qparent_id, tem);
1208 } 1215 }
1209 1216
1210 1217
1218
1219 /* Gamma-correct COLOR on frame F. */
1220
1221 void
1222 gamma_correct (f, color)
1223 struct frame *f;
1224 XColor *color;
1225 {
1226 if (f->gamma)
1227 {
1228 color->red = pow (color->red / 65535.0, f->gamma) * 65535.0 + 0.5;
1229 color->green = pow (color->green / 65535.0, f->gamma) * 65535.0 + 0.5;
1230 color->blue = pow (color->blue / 65535.0, f->gamma) * 65535.0 + 0.5;
1231 }
1232 }
1233
1234
1211 /* Decide if color named COLOR is valid for the display associated with 1235 /* Decide if color named COLOR is valid for the display associated with
1212 the selected frame; if so, return the rgb values in COLOR_DEF. 1236 the selected frame; if so, return the rgb values in COLOR_DEF.
1213 If ALLOC is nonzero, allocate a new colormap cell. */ 1237 If ALLOC is nonzero, allocate a new colormap cell. */
1214 1238
1215 int 1239 int
1227 screen_colormap = DefaultColormap (display, XDefaultScreen (display)); 1251 screen_colormap = DefaultColormap (display, XDefaultScreen (display));
1228 1252
1229 status = XParseColor (display, screen_colormap, color, color_def); 1253 status = XParseColor (display, screen_colormap, color, color_def);
1230 if (status && alloc) 1254 if (status && alloc)
1231 { 1255 {
1256 /* Apply gamma correction. */
1257 gamma_correct (f, color_def);
1258
1232 status = XAllocColor (display, screen_colormap, color_def); 1259 status = XAllocColor (display, screen_colormap, color_def);
1233 if (!status) 1260 if (!status)
1234 { 1261 {
1235 /* If we got to this point, the colormap is full, so we're 1262 /* If we got to this point, the colormap is full, so we're
1236 going to try and get the next closest color. 1263 going to try and get the next closest color.
1328 1355
1329 Fsignal (Qerror, Fcons (build_string ("undefined color"), 1356 Fsignal (Qerror, Fcons (build_string ("undefined color"),
1330 Fcons (arg, Qnil))); 1357 Fcons (arg, Qnil)));
1331 } 1358 }
1332 1359
1360 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
1361 the previous value of that parameter, NEW_VALUE is the new value. */
1362
1363 static void
1364 x_set_screen_gamma (f, new_value, old_value)
1365 struct frame *f;
1366 Lisp_Object new_value, old_value;
1367 {
1368 if (NILP (new_value))
1369 f->gamma = 0;
1370 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
1371 /* The value 0.4545 is the normal viewing gamma. */
1372 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
1373 else
1374 Fsignal (Qerror, Fcons (build_string ("Illegal screen-gamma"),
1375 Fcons (new_value, Qnil)));
1376
1377 clear_face_cache (0);
1378 }
1379
1380
1333 /* Functions called only from `x_set_frame_param' 1381 /* Functions called only from `x_set_frame_param'
1334 to set individual parameters. 1382 to set individual parameters.
1335 1383
1336 If FRAME_X_WINDOW (f) is 0, 1384 If FRAME_X_WINDOW (f) is 0,
1337 the frame is being created and its X-window does not exist yet. 1385 the frame is being created and its X-window does not exist yet.
2152 If EXPLICIT is zero, that indicates that Emacs redisplay code is 2200 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2153 suggesting a new name, which lisp code should override; if 2201 suggesting a new name, which lisp code should override; if
2154 F->explicit_name is set, ignore the new name; otherwise, set it. */ 2202 F->explicit_name is set, ignore the new name; otherwise, set it. */
2155 2203
2156 void 2204 void
2157 x_set_title (f, name) 2205 x_set_title (f, name, old_name)
2158 struct frame *f; 2206 struct frame *f;
2159 Lisp_Object name; 2207 Lisp_Object name, old_name;
2160 { 2208 {
2161 /* Don't change the title if it's already NAME. */ 2209 /* Don't change the title if it's already NAME. */
2162 if (EQ (name, f->title)) 2210 if (EQ (name, f->title))
2163 return; 2211 return;
2164 2212
2551 2599
2552 /* Types we might convert a resource string into. */ 2600 /* Types we might convert a resource string into. */
2553 enum resource_types 2601 enum resource_types
2554 { 2602 {
2555 RES_TYPE_NUMBER, 2603 RES_TYPE_NUMBER,
2604 RES_TYPE_FLOAT,
2556 RES_TYPE_BOOLEAN, 2605 RES_TYPE_BOOLEAN,
2557 RES_TYPE_STRING, 2606 RES_TYPE_STRING,
2558 RES_TYPE_SYMBOL 2607 RES_TYPE_SYMBOL
2559 }; 2608 };
2560 2609
2597 2646
2598 switch (type) 2647 switch (type)
2599 { 2648 {
2600 case RES_TYPE_NUMBER: 2649 case RES_TYPE_NUMBER:
2601 return make_number (atoi (XSTRING (tem)->data)); 2650 return make_number (atoi (XSTRING (tem)->data));
2651
2652 case RES_TYPE_FLOAT:
2653 return make_float (atof (XSTRING (tem)->data));
2602 2654
2603 case RES_TYPE_BOOLEAN: 2655 case RES_TYPE_BOOLEAN:
2604 tem = Fdowncase (tem); 2656 tem = Fdowncase (tem);
2605 if (!strcmp (XSTRING (tem)->data, "on") 2657 if (!strcmp (XSTRING (tem)->data, "on")
2606 || !strcmp (XSTRING (tem)->data, "true")) 2658 || !strcmp (XSTRING (tem)->data, "true"))
3699 "pointerColor", "Foreground", RES_TYPE_STRING); 3751 "pointerColor", "Foreground", RES_TYPE_STRING);
3700 x_default_parameter (f, parms, Qcursor_color, build_string ("black"), 3752 x_default_parameter (f, parms, Qcursor_color, build_string ("black"),
3701 "cursorColor", "Foreground", RES_TYPE_STRING); 3753 "cursorColor", "Foreground", RES_TYPE_STRING);
3702 x_default_parameter (f, parms, Qborder_color, build_string ("black"), 3754 x_default_parameter (f, parms, Qborder_color, build_string ("black"),
3703 "borderColor", "BorderColor", RES_TYPE_STRING); 3755 "borderColor", "BorderColor", RES_TYPE_STRING);
3756 x_default_parameter (f, parms, Qscreen_gamma, Qnil,
3757 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT);
3704 3758
3705 x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_foreground, 3759 x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_foreground,
3706 "scrollBarForeground", 3760 "scrollBarForeground",
3707 "ScrollBarForeground", 1); 3761 "ScrollBarForeground", 1);
3708 x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_background, 3762 x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_background,
7211 color.green = g; 7265 color.green = g;
7212 color.blue = b; 7266 color.blue = b;
7213 7267
7214 BLOCK_INPUT; 7268 BLOCK_INPUT;
7215 cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f)); 7269 cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f));
7216 rc = x_alloc_nearest_color (FRAME_X_DISPLAY (f), FRAME_X_SCREEN (f), 7270 rc = x_alloc_nearest_color (f, cmap, &color);
7217 cmap, &color);
7218 UNBLOCK_INPUT; 7271 UNBLOCK_INPUT;
7219 7272
7220 if (rc) 7273 if (rc)
7221 { 7274 {
7222 ++ct_colors_allocated; 7275 ++ct_colors_allocated;
7261 BLOCK_INPUT; 7314 BLOCK_INPUT;
7262 7315
7263 cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f)); 7316 cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f));
7264 color.pixel = pixel; 7317 color.pixel = pixel;
7265 XQueryColor (FRAME_X_DISPLAY (f), cmap, &color); 7318 XQueryColor (FRAME_X_DISPLAY (f), cmap, &color);
7266 rc = x_alloc_nearest_color (FRAME_X_DISPLAY (f), FRAME_X_SCREEN (f), 7319 rc = x_alloc_nearest_color (f, cmap, &color);
7267 cmap, &color);
7268 UNBLOCK_INPUT; 7320 UNBLOCK_INPUT;
7269 7321
7270 if (rc) 7322 if (rc)
7271 { 7323 {
7272 ++ct_colors_allocated; 7324 ++ct_colors_allocated;
10125 staticpro (&Qdisplay); 10177 staticpro (&Qdisplay);
10126 Qscroll_bar_foreground = intern ("scroll-bar-foreground"); 10178 Qscroll_bar_foreground = intern ("scroll-bar-foreground");
10127 staticpro (&Qscroll_bar_foreground); 10179 staticpro (&Qscroll_bar_foreground);
10128 Qscroll_bar_background = intern ("scroll-bar-background"); 10180 Qscroll_bar_background = intern ("scroll-bar-background");
10129 staticpro (&Qscroll_bar_background); 10181 staticpro (&Qscroll_bar_background);
10182 Qscreen_gamma = intern ("screen-gamma");
10183 staticpro (&Qscreen_gamma);
10130 /* This is the end of symbol initialization. */ 10184 /* This is the end of symbol initialization. */
10131 10185
10132 Qlaplace = intern ("laplace"); 10186 Qlaplace = intern ("laplace");
10133 staticpro (&Qlaplace); 10187 staticpro (&Qlaplace);
10134 10188