[comp.windows.x] Self-Iconification and Emacs

jae@cs.iastate.edu (Andy Edwards) (09/26/90)

Is there a way for a client program to iconify itself?  Suppose I have
an emacs window running and want to iconify it without using the
window manager (i.e. by writing an emacs-lisp function
"iconify-emacs" and binding it to, say, C-z); how can I do this?

running X11R4 on HP-UX and SUN-OS.
--
--------------------------------------------------------------
Andy Edwards
jae@atanasoff.cs.iastate.edu	
Iowa State University

smarks@eng.sun.COM (Stuart Marks, There go I but for the grace of Root) (09/27/90)

| Is there a way for a client program to iconify itself?  Suppose I have
| an emacs window running and want to iconify it without using the
| window manager (i.e. by writing an emacs-lisp function
| "iconify-emacs" and binding it to, say, C-z); how can I do this?

By "without using the window manager" I take it you mean that you don't
want to move the mouse over to the frame's close button (or whatever) to
iconify the window.  If so, the answer is yes--just call XIconifyWindow().  
This call is new for X11R4, so it didn't make it into the books and
documentation until recently.

| running X11R4 on HP-UX and SUN-OS.
          ^^^^^
Ah, good, then you should have no trouble.

s'marks

Stuart W. Marks			ARPA: smarks@eng.sun.com
Windows & Graphics Software	UUCP: sun!smarks
Sun Microsystems, Inc.

erc@pai.UUCP (Eric Johnson) (09/27/90)

In article <jae.654359223@judy.cs.iastate.edu>, jae@cs.iastate.edu (Andy Edwards) writes:
> 
> Is there a way for a client program to iconify itself?  Suppose I have
> an emacs window running and want to iconify it ...
> 

In Release 4 of the X Window System, there is a new Xlib function:
XIconifyWindow():

	XIconifyWindow( display,
		window,
		screen );

	Display	*display;
	Window	window;
	int	screen;


Note that a window manager does not have to accept this. Some window
managers may not even allow for icons. As, usual, this call 
makes a request, a request that can be denied.

XIconifyWindow() is not available under Release 3 (or below),
but you can try to simulate the behavior using ClientMessages
and writes to properties.

> running X11R4 on HP-UX and SUN-OS.

R4 on HP-UX? Did you get this from HP? (I don't think that HP is
shipping R4 yet.)

> --------------------------------------------------------------
> Andy Edwards
> jae@atanasoff.cs.iastate.edu	
> Iowa State University

Hope this helps,
-Eric

-- 
Eric F. Johnson               phone: +1 612 894 0313    BTI: Industrial
Boulware Technologies, Inc.   fax:   +1 612 894 0316    automation systems
415 W. Travelers Trail        email: erc@pai.mn.org     and services
Burnsville, MN 55337 USA

meissner@osf.org (Michael Meissner) (09/29/90)

In article <jae.654359223@judy.cs.iastate.edu> jae@cs.iastate.edu
(Andy Edwards) writes:

| Is there a way for a client program to iconify itself?  Suppose I have
| an emacs window running and want to iconify it without using the
| window manager (i.e. by writing an emacs-lisp function
| "iconify-emacs" and binding it to, say, C-z); how can I do this?
| 
| running X11R4 on HP-UX and SUN-OS.

Other people have mentioned how to do it under X -- if you just want
to be able to do under emacs, I would suggest using epoch.  Epoch is a
modified GNU emacs 18.55 with MUCH better X support, though on the
downside you still need regular GNU emacs to use it on a character
terminal.  You can anonymous ftp epoch from cs.uiuc.edu.

Once you load the standard epoch elisp libraries, the keybinding C-z i
runs `iconify-screen' tells the window manager to iconize the current
screen (epoch allows for more than screen at a time).  You can also do
things like iconize a screen, and have an elisp function called when
it is raised -- I use this for mail and news windows.
--
Michael Meissner	email: meissner@osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Do apple growers tell their kids money doesn't grow on bushes?

jwz@lucid.com (Jamie Zawinski) (09/29/90)

> Other people have mentioned how to do it under X -- if you just want
> to be able to do under emacs, I would suggest using epoch.

Gee, hasn't anybody noticed that Emacs 18.55 has a function called
"x-set-WM-state" in the file "x11fns.c"?

	(defun iconify ()
	  "Iconify the current emacs window."
	  (interactive)
	  (x-set-WM-state "Iconic"))

meissner@osf.org (Michael Meissner) (09/29/90)

In article <JWZ.90Sep28150821@kolyma.lucid.com> jwz@lucid.com (Jamie
Zawinski) writes:

| > Other people have mentioned how to do it under X -- if you just want
| > to be able to do under emacs, I would suggest using epoch.
| 
| Gee, hasn't anybody noticed that Emacs 18.55 has a function called
| "x-set-WM-state" in the file "x11fns.c"?
| 
| 	(defun iconify ()
| 	  "Iconify the current emacs window."
| 	  (interactive)
| 	  (x-set-WM-state "Iconic"))

It must be a local modification, it's not in my version of 18.55.
--
Michael Meissner	email: meissner@osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Do apple growers tell their kids money doesn't grow on bushes?

jv@mh.nl (Johan Vromans) (09/29/90)

Here is the X11R3 code to iconize Emacs 18.55:

Add to x11fns.c:

================
DEFUN ("x-iconify-window", Fx_iconify_window, Sx_iconify_window,
  0, 0, 0,
  "Iconifies the X window.")
  ()
{
  if (WindowMapped) {
    /* this is from thoth@shark.cis.ufl.edu (Robert Forsman) */
    XClientMessageEvent     xev;

    BLOCK_INPUT_DECLARE ();
    check_xterm();

    xev.type = ClientMessage;
    xev.send_event = True;
    xev.window = XXwindow;
    xev.format = 32;
    xev.data.l[0] = IconicState;

    BLOCK_INPUT ();

    xev.message_type = XInternAtom(XXdisplay,"WM_CHANGE_STATE",False);
    XSendEvent(XXdisplay, DefaultRootWindow(XXdisplay), False,
	       SubstructureRedirectMask|SubstructureNotifyMask, &xev);

    UNBLOCK_INPUT ();
    
    XFlush(XXdisplay);
  }
  return Qnil;
}
================

Add to function syms_of_xfns of x11fns.c:

================
  defsubr (&Sx_iconify_window);
================

That's all.
-- 
Johan Vromans				       jv@mh.nl via internet backbones
Multihouse Automatisering bv		       uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62911/62500
------------------------ "Arms are made for hugging" -------------------------

thoth@reef.cis.ufl.edu (Gilligan) (09/29/90)

  We don't have that x-set-WM-state either.  I had to write my own
iconification procedure.  (this was before I knew about the Xlib
convenience function XIconifyWindow).


*** x11oldfns.c	Tue Oct 10 04:04:50 1989
--- x11bobfns.c	Thu Jun 28 19:31:12 1990
***************
*** 828,833 ****
--- 828,879 ----
  	return (Qnil);
  }
  
+ DEFUN ("x-iconify", Fx_iconify, Sx_iconify, 0, 0, "",
+   "this iconifies the emacs window.")
+   ()
+ {
+ 	XClientMessageEvent	xev;
+ 
+ 	BLOCK_INPUT_DECLARE ();
+ 	check_xterm();
+ 
+ 	xev.type = ClientMessage;
+ 	xev.send_event = True;
+ 	xev.window = XXwindow;
+ 	xev.format = 32;
+ 	xev.data.l[0] = IconicState;
+ 
+ 	BLOCK_INPUT ();
+ 
+ 	xev.message_type = XInternAtom(XXdisplay,"WM_CHANGE_STATE",False);
+ 	XSendEvent(XXdisplay, DefaultRootWindow(XXdisplay), False,
+ 		   SubstructureRedirectMask|SubstructureNotifyMask, &xev);
+ 
+ 	UNBLOCK_INPUT ();
+ 
+ 	XFlush(XXdisplay);
+ 
+ 	return Qt;
+ }
+ 
+ 
+ DEFUN ("x-deiconify", Fx_deiconify, Sx_deiconify, 0, 0, "",
+   "this de-iconifies the emacs window.")
+   ()
+ {
+ 	BLOCK_INPUT_DECLARE ();
+ 	check_xterm();
+ 	BLOCK_INPUT ();
+ 
+ 	XMapWindow(XXdisplay,XXwindow);
+ 
+ 	UNBLOCK_INPUT ();
+ 
+ 	XFlush(XXdisplay);
+ 
+ 	return Qt;
+ }
+ 
  XRedrawDisplay ()
  {
  	Fredraw_display ();
***************
*** 892,897 ****
--- 938,945 ----
    defsubr (&Sx_rebind_keys);
  #endif notdef
    defsubr (&Sx_debug);
+   defsubr (&Sx_iconify);
+   defsubr (&Sx_deiconify);
  }
  
  #endif /* HAVE_X_WINDOWS */
--
--
"Until it's on my desk, it's vaporware"  (`it' is the NeXT)