shithub: purgatorio

Download patch

ref: 79c64a79a248c31733d4ec0ff9fe1a1e57a58f51
parent: acc58dfee42368825f7595d63240fd6e88559776
author: henesy <devnull@localhost>
date: Sun Dec 13 15:21:38 EST 2020

wm/clock: create context if none exists ;; wmclient(2): correct and align with current implementation

--- a/appl/wm/clock.b
+++ b/appl/wm/clock.b
@@ -44,6 +44,9 @@
 	sys->pctl(Sys->NEWPGRP, nil);
 	wmclient->init();
 
+	if(ctxt == nil)
+		ctxt = wmclient->makedrawcontext();
+
 	w := wmclient->window(ctxt, "clock", Wmclient->Appl);	# Plain?
 	display := w.display;
 	back = display.colormix(Draw->Palebluegreen, Draw->White);
@@ -53,10 +56,10 @@
 	dots = display.newimage(Rect((0,0),(1,1)), Draw->CMAP8, 1, Draw->Blue);
 
 	w.reshape(Rect((0, 0), (100, 100)));
+	w.onscreen("place");
 	w.startinput("ptr" :: nil);
 
 	now := daytime->now();
-	w.onscreen(nil);
 	drawclock(w.image, now);
 
 	ticks := chan of int;
@@ -67,8 +70,10 @@
 		w.wmctl(ctl);
 		if(ctl != nil && ctl[0] == '!')
 			drawclock(w.image, now);
+
 	p := <-w.ctxt.ptr =>
 		w.pointer(*p);
+
 	<-ticks =>
 		t := daytime->now();
 		if(t != now){
--- a/appl/wm/wm.b
+++ b/appl/wm/wm.b
@@ -207,6 +207,7 @@
 	n := len args;
 	if(req[0] == '!' && n < 3)
 		return "bad arg count";
+
 	case hd args {
 	"key" =>
 		# XXX should we restrict this capability to certain clients only?
@@ -217,6 +218,7 @@
 			spawn bufferproc(fakekbdin, fakekbd);
 		}
 		fakekbdin <-= hd tl args;
+
 	"ptr" =>
 		# ptr x y
 		if(n != 3)
@@ -228,6 +230,7 @@
 			c.ptr <-= nil;		# flush queue
 			c.ptr <-= ref Pointer(buttons, (int hd tl args, int hd tl tl args), sys->millisec());
 		}
+
 	"cursor" =>
 		# cursor hotx hoty dx dy data
 		if(n != 6 && n != 1)
@@ -235,6 +238,7 @@
 		c.cursor = req;
 		if(ptrfocus == c || kbdfocus == c)
 			return wmclient->win.wmctl(c.cursor);
+
 	"start" =>
 		if(n != 2)
 			return "bad arg count";
@@ -255,6 +259,7 @@
 		* =>
 			return "unknown input source";
 		}
+
 	"!reshape" =>
 		# reshape tag reqid rect [how]
 		# XXX allow "how" to specify that the origin of the window is never
@@ -285,6 +290,7 @@
 			}
 		}
 		return reshape(c, tag, r);
+
 	"delete" =>
 		# delete tag
 		if(tl args == nil)
@@ -292,10 +298,13 @@
 		c.setimage(hd tl args, nil);
 		if(c.wins == nil && c == kbdfocus)
 			setfocus(win, nil);
+
 	"raise" =>
 		c.top();
+
 	"lower" =>
 		c.bottom();
+
 	"!move" or
 	"!size" =>
 		# !move tag reqid startx starty
@@ -318,10 +327,13 @@
 				return "bad arg count";
 			sizewin(wmctxt.ptr, c, w, Point(int hd args, int hd tl args));
 		}
+
 	"fixedorigin" =>
 		c.flags |= Fixedorigin;
+
 	"rect" =>
 		;
+
 	"kbdfocus" =>
 		if(n != 2)
 			return "bad arg count";
@@ -329,10 +341,12 @@
 			setfocus(win, c);
 		else if(c == kbdfocus)
 			setfocus(win, nil);
+
 	# controller specific messages:
 	"request" =>		# can be used to test for control.
 		if((c.flags & Controller) == 0)
 			return "you are not in control";
+
 	"ctl" =>
 		# ctl id msg
 		if((c.flags & Controlstarted) == 0)
@@ -346,6 +360,7 @@
 		if(z == nil)
 			return "no such client";
 		z.ctl <-= str->quoted(tl tl args);
+
 	"endcontrol" =>
 		if(c != controller)
 			return "invalid request";
@@ -352,6 +367,7 @@
 		controller = nil;
 		allowcontrol = 1;
 		c.flags &= ~(Controlstarted | Controller);
+
 	* =>
 		if(c == controller || controller == nil || (controller.flags & Controlstarted) == 0)
 			return "unknown control request";
--- a/man/2/wmclient
+++ b/man/2/wmclient
@@ -1,6 +1,6 @@
 .TH WMCLIENT 2
 .SH NAME
-wmclient: makedrawcontext, window, snarfput, snarfget \-
+wmclient: makedrawcontext, window, snarfput, snarfget, cursorspec \-
 window manager interface for Draw-based applications.
 .SH SYNOPSIS
 .EX
@@ -12,32 +12,36 @@
 Hide,
 Help,
 OK,
-Plain:     con 1 << iota;
+Popup,
+Plain:  con 1 << iota;
 
 Appl:   con Resize | Hide;
 
-init:       fn();
-makedrawcontext: fn():  ref Draw->Context;
-window:	fn(ctxt: ref Draw->Context, title: string, buts: int): ref Window;
-snarfput:   fn(buf: string);
-snarfget:   fn(): string;
+init:             fn();
+makedrawcontext:  fn():  ref Draw->Context;
+window:           fn(ctxt: ref Draw->Context, title: string, buts: int): ref Window;
+snarfput:         fn(buf: string);
+snarfget:         fn(): string;
+cursorspec:       fn(img: ref Draw->Image): string;
+
 Window: adt{
-	display:	ref Draw->Display;
-	r: Draw->Rect;		# full rectangle of window, including titlebar.
-	image: ref Draw->Image;
-	screenr: Draw->Rect;
-	ctxt: ref Draw->Wmcontext;
-	focused:	int;
-	ctl:		chan of string;
+	display:   ref Draw->Display;
+	r:         Draw->Rect;
+	image:     ref Draw->Image;
+	displayr:  Draw->Rect;
+	ctxt:      ref Draw->Wmcontext;
+	bd:        int;
+	focused:   int;
+	ctl:       chan of string;
 
-	startinput:	fn(w: self ref Window, devs: list of string);
-	wmctl:	fn(w: self ref Window, request: string): string;
-	settitle:	fn(w: self ref Window, name: string): string;
-	reshape:	fn(w: self ref Window, r: Draw->Rect);
-	onscreen:	fn(w: self ref Window, how: string);
-	screenr2imager:	fn(w: self ref Window, sr: Draw->Rect): Draw->Rect;
-	imager2screenr:	fn(w: self ref Window, ir: Draw->Rect): Draw->Rect;
-	pointer:	fn(w: self ref Window, p: Draw->Pointer): int;
+	startinput:  fn(w: self ref Window, devs: list of string);
+	wmctl:       fn(w: self ref Window, request: string): string;
+	settitle:    fn(w: self ref Window, name: string): string;
+	reshape:     fn(w: self ref Window, r: Draw->Rect);
+	onscreen:    fn(w: self ref Window, how: string);
+	screenr:     fn(w: self ref Window, sr: Draw->Rect): Draw->Rect;
+	imager:      fn(w: self ref Window, ir: Draw->Rect): Draw->Rect;
+	pointer:     fn(w: self ref Window, p: Draw->Pointer): int;
 };
 
 .EE
@@ -49,10 +53,12 @@
 containing an image that can be drawn on with the
 routines described in
 .IR draw-image (2).
+
 .PP
 .B Init
 should be called once to initialise the internal state of
 .BR wmclient .
+
 .PP
 .B Makedrawcontext
 establishes an initial connection with the window manager,
@@ -61,6 +67,7 @@
 context suitable for creating new windows. It is only
 necessary to call this if the application has not already
 been provided with a context.
+
 .PP
 .B Window
 creates a new window through
@@ -80,6 +87,7 @@
 If
 .B Plain
 is given, the window is given no decoration at all.
+
 .PP
 When a window, say
 .IR w ,
@@ -94,17 +102,19 @@
 gives the requested rectangle of the new
 image, excluding window decoration, such as the
 title bar and the window border.
+
 An application can use
-.IB w .screenr2imager
+.IB w .imager
 to find out the usable rectangle within screen
 rectangle
-.I sr
+.I ir
 when window decorations are taken into account.
-.IB W .imager2screenr
+.IB W .screenr
 converts in the other direction.
 .IB W .screenr
 contains the current rectangle of the screen containing
 the window.
+
 .PP
 .IB W .image
 holds the window's image when it has been successfully created;
@@ -121,6 +131,8 @@
 sets the title that is shown on the window's title bar;
 it can make the window's size (and therefore the window's image)
 change.
+
+
 .PP
 .IB W .ctl
 is a channel down which requests from the titlebar are sent.
@@ -133,6 +145,7 @@
 in
 .IR string (2).
 The messages include:
+
 .TP
 .B exit
 The window should be closed.
@@ -139,6 +152,7 @@
 .IB W .wmctl
 will kill all processes in the current
 process group.
+
 .TP
 .B !move \fIx\fP \fIy\fP
 The user has started to try to drag the window.
@@ -146,6 +160,7 @@
 and
 .I y
 give the location of the initial pointer click.
+
 .TP
 .B !size \fImindx\fP \fImindy\fP
 The user wishes to resize the window.
@@ -153,6 +168,7 @@
 and
 .I mindy
 give the minimum size acceptable for the window.
+
 .TP
 .B help
 The help button has been clicked.
@@ -159,6 +175,7 @@
 .TP
 .B ok
 The OK  button has been clicked.
+
 .TP
 .B hide
 The Hide button has been clicked.
@@ -165,6 +182,8 @@
 .IB W .wmctl
 will delete the window, and an entry
 will be shown on the toolbar.
+
+
 .PP
 In order to function correctly, an application
 should process not only events from the
@@ -186,6 +205,7 @@
 application should process the pointer event,
 otherwise the event has been consumed by the
 titlebar.
+
 .PP
 When created, the window is not visible;
 .IB w .onscreen
@@ -193,7 +213,8 @@
 position and a size for it.
 .I How
 specifies what sort of placement is required
-for the window; it can be one of
+for the window; it can be one of:
+
 .TP
 .B place
 tries to choose a suitable place on the screen
@@ -202,6 +223,7 @@
 (if
 .I how
 is nil).
+
 .TP
 .B onscreen
 tries to keep the position and size the same
@@ -208,10 +230,17 @@
 as specified on the window, adjusting them only
 to bring the window fully on screen, and making sure
 that the window is no bigger than the entire display.
+
 .TP
 .B exact
 does not change the specified size or position
 of the window unless absolutely necessary.
+
+.TP
+.B max
+makes the window take up the entire display. 
+
+
 .PP
 .B Snarfget
 and
@@ -218,6 +247,7 @@
 .B snarfput
 retrieve and replace the contents of the window
 manager's snarf buffer.
+
 .SH FILES
 .TF /chan/snarf
 .TP
@@ -224,10 +254,13 @@
 .B /chan/snarf
 snarf buffer maintained by
 .IR wm (1)
+
 .TP
-.B /chan/wm
+.B /chan/wmctl
 channel for interaction with
 .IR wm (1)
+
+
 .SH SOURCE
 .B /appl/lib/wmclient.b
 .SH SEE ALSO