;;; xwem-events.el --- Events handlers.;; Copyright (C) 2003 by Free Software Foundation, Inc.;; Author: Zajcev Evgeny <zevlg@yandex.ru>;; Steve Youngs <steve@youngs.au.com>;; Created: 21 Mar 2003;; Keywords: xlib, xwem;; X-CVS: $Id$;; This file is part of XWEM.;; XWEM is free software; you can redistribute it and/or modify it;; under the terms of the GNU General Public License as published by;; the Free Software Foundation; either version 2, or (at your option);; any later version.;; XWEM is distributed in the hope that it will be useful, but WITHOUT;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public;; License for more details.;; You should have received a copy of the GNU General Public License;; along with XEmacs; see the file COPYING. If not, write to the Free;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA;; 02111-1307, USA.;;; Synched up with: Not in FSF;;; Commentary:;;;; This file used to work with X events, also includes some events;; handlers.;;;;; Code(require'xwem-load);;;###xwem-autoload(defunxwem-ev-reconfig(xdpywinxev)"Common ConfigureRequest handler."(let*((win(X-Event-xconfigurerequest-windowxev))(cl(xwem-xwin-clwin))(vmask(X-Event-xconfigurerequest-value-maskxev)))(X-Dpy-log(xwem-dpy)'xwem-event"XWEM-EVENTS: ConfigureRequest event for win=%s vmask=%s, x=%S, y=%S, width=%S, height=%S"'(X-Win-idwin)'vmask'(X-Event-xconfigurerequest-xxev)'(X-Event-xconfigurerequest-yxev)'(X-Event-xconfigurerequest-widthxev)'(X-Event-xconfigurerequest-heightxev));; Handle configure requests only from xwem clients(when(xwem-cl-pcl);; Client window already in air(if(not(Xtestvmask(Xmask-orX-CWXX-CWYX-CWWidthX-CWHeightX-CWBorderWidth)))(xwem-cl-send-configcl);; Geometry change(setf(xwem-cl-new-xgeomcl)(make-X-Geom:x(and(XtestvmaskX-CWX)(X-Event-xconfigurerequest-xxev)):y(and(XtestvmaskX-CWY)(X-Event-xconfigurerequest-yxev)):width(and(XtestvmaskX-CWWidth)(X-Event-xconfigurerequest-widthxev)):height(and(XtestvmaskX-CWHeight)(X-Event-xconfigurerequest-heightxev)):border-width(and(XtestvmaskX-CWBorderWidth)(X-Event-xconfigurerequest-border-widthxev))))(xwem-refitcl)))));;;###xwem-autoload(defunxwem-ev-resize(xdpywinxev)"Handle ResizeRequest event."(let((cl(xwem-xwin-cl(X-Event-xresizerequest-windowxev))))(when(xwem-cl-pcl)(xwem-client-resizecl(X-Event-xresizerequest-widthxev)(X-Event-xresizerequest-heightxev)))));;;###xwem-autoload(defunxwem-ev-mapreq(xdpywinxev)"Handle MapRequest event."(let((cl(xwem-xwin-cl(X-Event-xmaprequest-windowxev))))(if(xwem-cl-pcl);; Transition from Withdrawn->Normal/Iconic state(xwem-cl-honour-init-statecl);; Initial window manage(xwem-xwin-try-to-manage(X-Event-xmaprequest-windowxev)))));;;###xwem-autoload(defunxwem-ev-unmap(xdpywinxev)"Handle UnmapNotify event.";; NOTE: Obsolete X clients which does not send synthetic;; UnmapNotify event (as described in ICCCM 4.1.4) to transit to;; withdraw state, are not supported.(let(cl)(when(and(X-Event-synth-pxev)(not(X-Event-xunmap-from-configurexev))(xwem-cl-p(setqcl(xwem-xwin-cl(X-Event-xunmap-windowxev))))(eq(xwem-cl-statecl)'active))(xwem-withdrawcl))));;;###xwem-autoload(defunxwem-ev-destroy(xdpywinxev)"Handle Destroy event."(let((cl(xwem-xwin-cl(X-Event-xdestroywindow-windowxev))))(when(xwem-cl-pcl)(xwem-cl-destroycl))));;;; -- Events, command events, stuff --;;;###xwem-autoload(defunxwem-event-client(xev)"Return client where X event XEV occured."(let*((xwin(and(X-Event-pxev)(X-Event-CASExev((:X-ButtonPress:X-ButtonRelease)(X-Event-xbutton-eventxev))(:X-MotionNotify(X-Event-xmotion-eventxev)))))(cl(or(andxwin(xwem-xwin-clxwin))(xwem-cl-selected))))cl));;;###xwem-autoload(defunxwem-next-event(&optionaltimeoutevt-list)"Fetch next Emacs keyboard or mouse event, with corresponding X Event.If EVT-LIST is given, stop when event of type that in EVT-LIST isoccured. Default value of EVT-LIST is `(list X-KeyPress X-ButtonPressX-ButtonRelease X-MotionNotify)'.Return Emacs event. To acces corresponding X Event use`(event-object ev)' form."(let((timo(andtimeout(add-timeouttimeoutnil'xwem-timeout)))(nev(allocate-event))(objnil))(while(progn(next-eventnev)(not(cond((and(timeout-event-pnev)(eq(event-objectnev)'xwem-timeout))(setqtimonil); unset itt)((and(eval-event-pnev)(X-Event-p(event-objectnev))(memq(X-Event-type(event-objectnev))(orevt-list(listX-KeyPressX-ButtonPressX-ButtonReleaseX-MotionNotify))));; next-event can fetch only;; keypress/buttonpress/buttonrelease/motion;; events(setqobj(event-objectnev))))))(dispatch-eventnev))(whentimo(disable-timeouttimo))(deallocate-eventnev)obj))(defunxwem-xevent-emacs-event(xev)"Return Emacs event corresponding to X Event XEV."(X-Event-get-propertyxev'emacs-event))(defsetfxwem-xevent-emacs-event(xev)(eev)`(X-Event-put-property,xev'emacs-event,eev));;;###xwem-autoload(defunxwem-event-as-command(e-ev&optionalx-ev)"Interpret event E-EV as command event.Optional X-EV specifies corresponding X Event.";; Remember some information about command invocation(setqxwem-last-xeventx-evxwem-event-client(xwem-event-clientx-ev)xwem-last-evente-evxwem-this-command-keys(vconcat(and(not(xwem-kbd-global-map-current-p))xwem-this-command-keys)(vectore-ev))));;;###xwem-autoload(defunxwem-next-command-event(&optionalprompt)"Return next command event.Actually return cons cell where car is Emacs event and cdr is X Event."(let(eevcevxev);; Normal(whenprompt(xwem-message'promptprompt));; Process while interesting event occur(while(and(setqeev(next-event))(not(cond((and(eval-event-peev)(X-Event-p(setqxev(event-objecteev)))(memq(X-Event-typexev)(listX-KeyPressX-ButtonPressX-ButtonReleaseX-MotionNotify))(setqcev(car(xwem-xevents->emacs-events(listxev)t))))(X-Event-put-propertyxev'emacs-eventcev)'break)((and(eval-event-peev)(eventp(setqcev(event-objecteev)))(eq(event-functioneev)'xwem-dispatch-command-event));; Unread command event(setqxevnil)'break))))(dispatch-eventeev))(whenprompt(xwem-clear-message))(xwem-event-as-commandcevxev)(conscevxev)));;;###xwem-autoload(defunxwem-dispatch-command-event(eev&optionalxev)"Dispatch command Emacs event EEV."(let*((ecl(xwem-event-clientxev))(bind(or(xwem-lookup-keyecl(vectoreev));; Then check for quit key(and(equalxwem-quit-key(events-to-keys(vectoreev)))xwem-quit-command);; Then accept even default bindings(xwem-lookup-keyecl(vectoreev)t))));; If some button press/release does not have binding - ignore it(unless(and(nullbind)(button-event-peev))(xwem-event-as-commandeevxev)(xwem-kbd-dispatch-bindingbind))));;;###xwem-autoload(defunxwem-dispatch-command-xevent(xev)"Dispatch command event XEV.";; If we are grabbing keyboard now and modifier pressed do nothing.(unless(or(=(X-Event-typexev)X-KeyRelease)(and(=(X-Event-typexev)X-KeyPress)(xwem-kbd-kcode-modifier-p(X-Event-xkey-keycodexev))))(setf(xwem-xevent-emacs-eventxev)(car(xwem-xevents->emacs-events(listxev)t)))(xwem-dispatch-command-event(xwem-xevent-emacs-eventxev)xev)));;; Unread command events support;;;###xwem-autoload(defunxwem-unread-command-event(eev-or-xev)"Make event EV to be readed by `xwem-next-command-event' later,or to be executed by `xwem-dispatch-command-event'.Event EV can be either Emacs event, or X-Event."(enqueue-eval-event(if(X-Event-peev-or-xev)'xwem-dispatch-command-xevent'xwem-dispatch-command-event)eev-or-xev))(provide'xwem-events);;; xwem-events.el ends here