diff options
| author | Jan Djärv | 2004-02-03 16:35:38 +0000 |
|---|---|---|
| committer | Jan Djärv | 2004-02-03 16:35:38 +0000 |
| commit | b4715a729383e91f79dd9eaa56cca7b49f51229c (patch) | |
| tree | 10f6c86cbd719dc0e478f8b11cd43f2f405632ca /src | |
| parent | 1fb3821bbd76f13b8c288122eca57f84a362d8d9 (diff) | |
| download | emacs-b4715a729383e91f79dd9eaa56cca7b49f51229c.tar.gz emacs-b4715a729383e91f79dd9eaa56cca7b49f51229c.zip | |
* xfns.c (x-send-client-message): Moved to xselect.c
(Fx_change_window_property): Add optional arguments TYPE, FORMAT and
OUTER_P.
(Fx_window_property): Add optional arguments TYPE, SOURCE, DELETE_P,
VECTOR_RET_P. Handle AnyPropertyType. Call x_property_data_to_lisp
if vector_ret_p is true.
(syms_of_xfns): Sx_send_client_message moved to xselect.c.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xfns.c | 270 |
1 files changed, 129 insertions, 141 deletions
diff --git a/src/xfns.c b/src/xfns.c index e940b16eba1..02d185b96de 100644 --- a/src/xfns.c +++ b/src/xfns.c | |||
| @@ -4284,125 +4284,6 @@ x_sync (f) | |||
| 4284 | 4284 | ||
| 4285 | 4285 | ||
| 4286 | /*********************************************************************** | 4286 | /*********************************************************************** |
| 4287 | General X functions exposed to Elisp. | ||
| 4288 | ***********************************************************************/ | ||
| 4289 | |||
| 4290 | DEFUN ("x-send-client-message", Fx_send_client_event, | ||
| 4291 | Sx_send_client_message, 6, 6, 0, | ||
| 4292 | doc: /* Send a client message of MESSAGE-TYPE to window DEST on DISPLAY. | ||
| 4293 | |||
| 4294 | For DISPLAY, specify either a frame or a display name (a string). | ||
| 4295 | If DISPLAY is nil, that stands for the selected frame's display. | ||
| 4296 | DEST may be an integer, in which case it is a Window id. The value 0 may | ||
| 4297 | be used to send to the root window of the DISPLAY. | ||
| 4298 | If DEST is a frame the event is sent to the outer window of that frame. | ||
| 4299 | Nil means the currently selected frame. | ||
| 4300 | If DEST is the string "PointerWindow" the event is sent to the window that | ||
| 4301 | contains the pointer. If DEST is the string "InputFocus" the event is | ||
| 4302 | sent to the window that has the input focus. | ||
| 4303 | FROM is the frame sending the event. Use nil for currently selected frame. | ||
| 4304 | MESSAGE-TYPE is the name of an Atom as a string. | ||
| 4305 | FORMAT must be one of 8, 16 or 32 and determines the size of the values in | ||
| 4306 | bits. VALUES is a list of integer and/or strings containing the values to | ||
| 4307 | send. If a value is a string, it is converted to an Atom and the value of | ||
| 4308 | the Atom is sent. If more values than fits into the event is given, | ||
| 4309 | the excessive values are ignored. */) | ||
| 4310 | (display, dest, from, message_type, format, values) | ||
| 4311 | Lisp_Object display, dest, from, message_type, format, values; | ||
| 4312 | { | ||
| 4313 | struct x_display_info *dpyinfo = check_x_display_info (display); | ||
| 4314 | Window wdest; | ||
| 4315 | XEvent event; | ||
| 4316 | Lisp_Object cons; | ||
| 4317 | int i; | ||
| 4318 | int max_nr_values = (int) sizeof (event.xclient.data.b); | ||
| 4319 | struct frame *f = check_x_frame (from); | ||
| 4320 | |||
| 4321 | CHECK_STRING (message_type); | ||
| 4322 | CHECK_NUMBER (format); | ||
| 4323 | CHECK_CONS (values); | ||
| 4324 | |||
| 4325 | for (cons = values; CONSP (cons); cons = XCDR (cons)) | ||
| 4326 | { | ||
| 4327 | Lisp_Object o = XCAR (cons); | ||
| 4328 | |||
| 4329 | if (! INTEGERP (o) && ! STRINGP (o)) | ||
| 4330 | error ("Bad data in VALUES, must be integer or string"); | ||
| 4331 | } | ||
| 4332 | |||
| 4333 | event.xclient.type = ClientMessage; | ||
| 4334 | event.xclient.format = XFASTINT (format); | ||
| 4335 | |||
| 4336 | if (event.xclient.format != 8 && event.xclient.format != 16 | ||
| 4337 | && event.xclient.format != 32) | ||
| 4338 | error ("FORMAT must be one of 8, 16 or 32"); | ||
| 4339 | if (event.xclient.format == 16) max_nr_values /= 2; | ||
| 4340 | if (event.xclient.format == 32) max_nr_values /= 4; | ||
| 4341 | |||
| 4342 | if (FRAMEP (dest) || NILP (dest)) | ||
| 4343 | { | ||
| 4344 | struct frame *fdest = check_x_frame (dest); | ||
| 4345 | wdest = FRAME_OUTER_WINDOW (fdest); | ||
| 4346 | } | ||
| 4347 | else if (STRINGP (dest)) | ||
| 4348 | { | ||
| 4349 | if (strcmp (SDATA (dest), "PointerWindow") == 0) | ||
| 4350 | wdest = PointerWindow; | ||
| 4351 | else if (strcmp (SDATA (dest), "InputFocus") == 0) | ||
| 4352 | wdest = InputFocus; | ||
| 4353 | else | ||
| 4354 | error ("DEST as a string must be one of PointerWindow or InputFocus"); | ||
| 4355 | } | ||
| 4356 | else | ||
| 4357 | { | ||
| 4358 | CHECK_NUMBER (dest); | ||
| 4359 | wdest = (Window) XFASTINT (dest); | ||
| 4360 | if (wdest == 0) wdest = dpyinfo->root_window; | ||
| 4361 | } | ||
| 4362 | |||
| 4363 | BLOCK_INPUT; | ||
| 4364 | for (cons = values, i = 0; | ||
| 4365 | CONSP (cons) && i < max_nr_values; | ||
| 4366 | cons = XCDR (cons), ++i) | ||
| 4367 | { | ||
| 4368 | Lisp_Object o = XCAR (cons); | ||
| 4369 | long val; | ||
| 4370 | |||
| 4371 | if (INTEGERP (o)) | ||
| 4372 | val = XINT (o); | ||
| 4373 | else if (STRINGP (o)) | ||
| 4374 | val = XInternAtom (dpyinfo->display, SDATA (o), False); | ||
| 4375 | |||
| 4376 | if (event.xclient.format == 8) | ||
| 4377 | event.xclient.data.b[i] = (char) val; | ||
| 4378 | else if (event.xclient.format == 16) | ||
| 4379 | event.xclient.data.s[i] = (short) val; | ||
| 4380 | else | ||
| 4381 | event.xclient.data.l[i] = val; | ||
| 4382 | } | ||
| 4383 | |||
| 4384 | for ( ; i < max_nr_values; ++i) | ||
| 4385 | if (event.xclient.format == 8) | ||
| 4386 | event.xclient.data.b[i] = 0; | ||
| 4387 | else if (event.xclient.format == 16) | ||
| 4388 | event.xclient.data.s[i] = 0; | ||
| 4389 | else | ||
| 4390 | event.xclient.data.l[i] = 0; | ||
| 4391 | |||
| 4392 | event.xclient.message_type | ||
| 4393 | = XInternAtom (dpyinfo->display, SDATA (message_type), False); | ||
| 4394 | event.xclient.display = dpyinfo->display; | ||
| 4395 | event.xclient.window = FRAME_OUTER_WINDOW (f); | ||
| 4396 | |||
| 4397 | XSendEvent (dpyinfo->display, wdest, False, 0xffff, &event); | ||
| 4398 | |||
| 4399 | XFlush (dpyinfo->display); | ||
| 4400 | UNBLOCK_INPUT; | ||
| 4401 | |||
| 4402 | return Qnil; | ||
| 4403 | } | ||
| 4404 | |||
| 4405 | /*********************************************************************** | ||
| 4406 | Image types | 4287 | Image types |
| 4407 | ***********************************************************************/ | 4288 | ***********************************************************************/ |
| 4408 | 4289 | ||
| @@ -9593,24 +9474,86 @@ x_kill_gs_process (pixmap, f) | |||
| 9593 | ***********************************************************************/ | 9474 | ***********************************************************************/ |
| 9594 | 9475 | ||
| 9595 | DEFUN ("x-change-window-property", Fx_change_window_property, | 9476 | DEFUN ("x-change-window-property", Fx_change_window_property, |
| 9596 | Sx_change_window_property, 2, 3, 0, | 9477 | Sx_change_window_property, 2, 6, 0, |
| 9597 | doc: /* Change window property PROP to VALUE on the X window of FRAME. | 9478 | doc: /* Change window property PROP to VALUE on the X window of FRAME. |
| 9598 | PROP and VALUE must be strings. FRAME nil or omitted means use the | 9479 | PROP must be a string. |
| 9599 | selected frame. Value is VALUE. */) | 9480 | VALUE may be a string or a list of conses, numbers and/or strings. |
| 9600 | (prop, value, frame) | 9481 | If an element in the list is a string, it is converted to |
| 9601 | Lisp_Object frame, prop, value; | 9482 | an Atom and the value of the Atom is used. If an element is a cons, |
| 9483 | it is converted to a 32 bit number where the car is the 16 top bits and the | ||
| 9484 | cdr is the lower 16 bits. | ||
| 9485 | FRAME nil or omitted means use the selected frame. | ||
| 9486 | If TYPE is given and non-nil, it is the name of the type of VALUE. | ||
| 9487 | If TYPE is not given or nil, the type is STRING. | ||
| 9488 | FORMAT gives the size in bits of each element if VALUE is a list. | ||
| 9489 | It must be one of 8, 16 or 32. | ||
| 9490 | If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8. | ||
| 9491 | If OUTER_P is non-nil, the property is changed for the outer X window of | ||
| 9492 | FRAME. Default is to change on the edit X window. | ||
| 9493 | |||
| 9494 | Value is VALUE. */) | ||
| 9495 | (prop, value, frame, type, format, outer_p) | ||
| 9496 | Lisp_Object frame, prop, value, outer_p; | ||
| 9602 | { | 9497 | { |
| 9603 | struct frame *f = check_x_frame (frame); | 9498 | struct frame *f = check_x_frame (frame); |
| 9604 | Atom prop_atom; | 9499 | Atom prop_atom; |
| 9500 | Atom target_type = XA_STRING; | ||
| 9501 | int element_format = 8; | ||
| 9502 | unsigned char *data; | ||
| 9503 | int nelements; | ||
| 9504 | Lisp_Object cons; | ||
| 9505 | Window w; | ||
| 9605 | 9506 | ||
| 9606 | CHECK_STRING (prop); | 9507 | CHECK_STRING (prop); |
| 9607 | CHECK_STRING (value); | 9508 | |
| 9509 | if (! NILP (format)) | ||
| 9510 | { | ||
| 9511 | CHECK_NUMBER (format); | ||
| 9512 | element_format = XFASTINT (format); | ||
| 9513 | |||
| 9514 | if (element_format != 8 && element_format != 16 | ||
| 9515 | && element_format != 32) | ||
| 9516 | error ("FORMAT must be one of 8, 16 or 32"); | ||
| 9517 | } | ||
| 9518 | |||
| 9519 | if (CONSP (value)) | ||
| 9520 | { | ||
| 9521 | nelements = x_check_property_data (value); | ||
| 9522 | if (nelements == -1) | ||
| 9523 | error ("Bad data in VALUE, must be number, string or cons"); | ||
| 9524 | |||
| 9525 | if (element_format == 8) | ||
| 9526 | data = (unsigned char *) xmalloc (nelements); | ||
| 9527 | else if (element_format == 16) | ||
| 9528 | data = (unsigned char *) xmalloc (nelements*2); | ||
| 9529 | else | ||
| 9530 | data = (unsigned char *) xmalloc (nelements*4); | ||
| 9531 | |||
| 9532 | x_fill_property_data (FRAME_X_DISPLAY (f), value, data, element_format); | ||
| 9533 | } | ||
| 9534 | else | ||
| 9535 | { | ||
| 9536 | CHECK_STRING (value); | ||
| 9537 | data = SDATA (value); | ||
| 9538 | nelements = SCHARS (value); | ||
| 9539 | } | ||
| 9608 | 9540 | ||
| 9609 | BLOCK_INPUT; | 9541 | BLOCK_INPUT; |
| 9610 | prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False); | 9542 | prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False); |
| 9611 | XChangeProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | 9543 | if (! NILP (type)) |
| 9612 | prop_atom, XA_STRING, 8, PropModeReplace, | 9544 | { |
| 9613 | SDATA (value), SCHARS (value)); | 9545 | CHECK_STRING (type); |
| 9546 | target_type = XInternAtom (FRAME_X_DISPLAY (f), SDATA (type), False); | ||
| 9547 | } | ||
| 9548 | |||
| 9549 | if (! NILP (outer_p)) w = FRAME_OUTER_WINDOW (f); | ||
| 9550 | else w = FRAME_X_WINDOW (f); | ||
| 9551 | |||
| 9552 | XChangeProperty (FRAME_X_DISPLAY (f), w, | ||
| 9553 | prop_atom, target_type, element_format, PropModeReplace, | ||
| 9554 | data, nelements); | ||
| 9555 | |||
| 9556 | if (CONSP (value)) xfree (data); | ||
| 9614 | 9557 | ||
| 9615 | /* Make sure the property is set when we return. */ | 9558 | /* Make sure the property is set when we return. */ |
| 9616 | XFlush (FRAME_X_DISPLAY (f)); | 9559 | XFlush (FRAME_X_DISPLAY (f)); |
| @@ -9644,13 +9587,20 @@ FRAME nil or omitted means use the selected frame. Value is PROP. */) | |||
| 9644 | 9587 | ||
| 9645 | 9588 | ||
| 9646 | DEFUN ("x-window-property", Fx_window_property, Sx_window_property, | 9589 | DEFUN ("x-window-property", Fx_window_property, Sx_window_property, |
| 9647 | 1, 2, 0, | 9590 | 1, 6, 0, |
| 9648 | doc: /* Value is the value of window property PROP on FRAME. | 9591 | doc: /* Value is the value of window property PROP on FRAME. |
| 9649 | If FRAME is nil or omitted, use the selected frame. Value is nil | 9592 | If FRAME is nil or omitted, use the selected frame. |
| 9650 | if FRAME hasn't a property with name PROP or if PROP has no string | 9593 | If TYPE is nil or omitted, get the property as a string. Otherwise TYPE |
| 9651 | value. */) | 9594 | is the name of the Atom that denotes the type expected. |
| 9652 | (prop, frame) | 9595 | If SOURCE is non-nil, get the property on that window instead of from |
| 9653 | Lisp_Object prop, frame; | 9596 | FRAME. The number 0 denotes the root window. |
| 9597 | If DELETE_P is non-nil, delete the property after retreiving it. | ||
| 9598 | If VECTOR_RET_P is non-nil, don't return a string but a vector of values. | ||
| 9599 | |||
| 9600 | Value is nil if FRAME hasn't a property with name PROP or if PROP has | ||
| 9601 | no value of TYPE. */) | ||
| 9602 | (prop, frame, type, source, delete_p, vector_ret_p) | ||
| 9603 | Lisp_Object prop, frame, type, source, delete_p, vector_ret_p; | ||
| 9654 | { | 9604 | { |
| 9655 | struct frame *f = check_x_frame (frame); | 9605 | struct frame *f = check_x_frame (frame); |
| 9656 | Atom prop_atom; | 9606 | Atom prop_atom; |
| @@ -9658,14 +9608,43 @@ value. */) | |||
| 9658 | Lisp_Object prop_value = Qnil; | 9608 | Lisp_Object prop_value = Qnil; |
| 9659 | char *tmp_data = NULL; | 9609 | char *tmp_data = NULL; |
| 9660 | Atom actual_type; | 9610 | Atom actual_type; |
| 9611 | Atom target_type = XA_STRING; | ||
| 9661 | int actual_format; | 9612 | int actual_format; |
| 9662 | unsigned long actual_size, bytes_remaining; | 9613 | unsigned long actual_size, bytes_remaining; |
| 9614 | Window target_window = FRAME_X_WINDOW (f); | ||
| 9615 | struct gcpro gcpro1; | ||
| 9663 | 9616 | ||
| 9617 | GCPRO1 (prop_value); | ||
| 9664 | CHECK_STRING (prop); | 9618 | CHECK_STRING (prop); |
| 9619 | |||
| 9620 | if (! NILP (source)) | ||
| 9621 | { | ||
| 9622 | if (NUMBERP (source)) | ||
| 9623 | { | ||
| 9624 | if (FLOATP (source)) | ||
| 9625 | target_window = (Window) XFLOAT (source); | ||
| 9626 | else | ||
| 9627 | target_window = XFASTINT (source); | ||
| 9628 | |||
| 9629 | if (target_window == 0) | ||
| 9630 | target_window = FRAME_X_DISPLAY_INFO (f)->root_window; | ||
| 9631 | } | ||
| 9632 | else if (CONSP (source)) | ||
| 9633 | target_window = cons_to_long (source); | ||
| 9634 | } | ||
| 9635 | |||
| 9665 | BLOCK_INPUT; | 9636 | BLOCK_INPUT; |
| 9637 | if (STRINGP (type)) | ||
| 9638 | { | ||
| 9639 | if (strcmp ("AnyPropertyType", SDATA (type)) == 0) | ||
| 9640 | target_type = AnyPropertyType; | ||
| 9641 | else | ||
| 9642 | target_type = XInternAtom (FRAME_X_DISPLAY (f), SDATA (type), False); | ||
| 9643 | } | ||
| 9644 | |||
| 9666 | prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False); | 9645 | prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False); |
| 9667 | rc = XGetWindowProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | 9646 | rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window, |
| 9668 | prop_atom, 0, 0, False, XA_STRING, | 9647 | prop_atom, 0, 0, False, target_type, |
| 9669 | &actual_type, &actual_format, &actual_size, | 9648 | &actual_type, &actual_format, &actual_size, |
| 9670 | &bytes_remaining, (unsigned char **) &tmp_data); | 9649 | &bytes_remaining, (unsigned char **) &tmp_data); |
| 9671 | if (rc == Success) | 9650 | if (rc == Success) |
| @@ -9675,19 +9654,29 @@ value. */) | |||
| 9675 | XFree (tmp_data); | 9654 | XFree (tmp_data); |
| 9676 | tmp_data = NULL; | 9655 | tmp_data = NULL; |
| 9677 | 9656 | ||
| 9678 | rc = XGetWindowProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | 9657 | rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window, |
| 9679 | prop_atom, 0, bytes_remaining, | 9658 | prop_atom, 0, bytes_remaining, |
| 9680 | False, XA_STRING, | 9659 | ! NILP (delete_p), target_type, |
| 9681 | &actual_type, &actual_format, | 9660 | &actual_type, &actual_format, |
| 9682 | &actual_size, &bytes_remaining, | 9661 | &actual_size, &bytes_remaining, |
| 9683 | (unsigned char **) &tmp_data); | 9662 | (unsigned char **) &tmp_data); |
| 9684 | if (rc == Success && tmp_data) | 9663 | if (rc == Success && tmp_data) |
| 9685 | prop_value = make_string (tmp_data, size); | 9664 | { |
| 9665 | if (NILP (vector_ret_p)) | ||
| 9666 | prop_value = make_string (tmp_data, size); | ||
| 9667 | else | ||
| 9668 | prop_value = x_property_data_to_lisp (f, | ||
| 9669 | (unsigned char *) tmp_data, | ||
| 9670 | actual_type, | ||
| 9671 | actual_format, | ||
| 9672 | actual_size); | ||
| 9673 | } | ||
| 9686 | 9674 | ||
| 9687 | XFree (tmp_data); | 9675 | if (tmp_data) XFree (tmp_data); |
| 9688 | } | 9676 | } |
| 9689 | 9677 | ||
| 9690 | UNBLOCK_INPUT; | 9678 | UNBLOCK_INPUT; |
| 9679 | UNGCPRO; | ||
| 9691 | return prop_value; | 9680 | return prop_value; |
| 9692 | } | 9681 | } |
| 9693 | 9682 | ||
| @@ -11097,7 +11086,6 @@ meaning don't clear the cache. */); | |||
| 11097 | defsubr (&Sx_close_connection); | 11086 | defsubr (&Sx_close_connection); |
| 11098 | defsubr (&Sx_display_list); | 11087 | defsubr (&Sx_display_list); |
| 11099 | defsubr (&Sx_synchronize); | 11088 | defsubr (&Sx_synchronize); |
| 11100 | defsubr (&Sx_send_client_message); | ||
| 11101 | defsubr (&Sx_focus_frame); | 11089 | defsubr (&Sx_focus_frame); |
| 11102 | defsubr (&Sx_backspace_delete_keys_p); | 11090 | defsubr (&Sx_backspace_delete_keys_p); |
| 11103 | 11091 | ||