1 /* apm/acpi dockapp - phear it 1.34
2 * Copyright (C) 2000, 2001, 2002 timecop@japan.co.jp
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <X11/Xutil.h>
33 #include <X11/extensions/shape.h>
39 #define WMACPI_VER "2.2rc3"
43 #include "master_low.xpm"
44 static char **master_xpm
= master_low_xpm
;
50 Display
*display
; /* display */
51 Window win
; /* main window */
52 Pixmap pixmap
; /* main pixmap */
53 Pixmap mask
; /* mask pixmap */
54 Pixmap text
; /* pixmap for text scroller */
55 unsigned short width
; /* width of pixmap */
56 unsigned short height
; /* height of pixmap */
57 int screen
; /* current screen */
58 int tw
; /* text width inside text pixmap */
59 int update
; /* need to redraw? */
60 int blink
; /* should we blink the LED? (critical battery) */
61 int bell
; /* bell on critical low, or not? */
62 int scroll
; /* scroll message text? */
63 int scroll_reset
; /* reset the scrolling text */
68 struct dockapp
*dockapp
;
69 /* global_t *globals; */
71 /* this gives us a variable scroll rate, depending on the importance of the
73 #define DEFAULT_SCROLL_RESET 150;
74 int scroll_reset
= DEFAULT_SCROLL_RESET
;
76 /* copy a chunk of pixmap around the app */
77 static void copy_xpm_area(int x
, int y
, int w
, int h
, int dx
, int dy
)
79 XCopyArea(DADisplay
, dockapp
->pixmap
, dockapp
->pixmap
,
80 DAGC
, x
, y
, w
, h
, dx
, dy
);
84 /* display AC power symbol */
85 static void display_power_glyph(void)
87 copy_xpm_area(67, 38, 12, 7, 6, 17);
90 /* get rid of AC power symbol */
91 static void kill_power_glyph(void)
93 copy_xpm_area(67, 48, 12, 7, 6, 17);
96 /* display battery symbol */
97 static void display_battery_glyph(void)
99 copy_xpm_area(82, 38, 12, 7, 20, 17);
102 /* get rid of battery symbol */
103 static void kill_battery_glyph(void)
105 copy_xpm_area(82, 48, 12, 7, 20, 17);
108 /* clear the time display */
109 static void clear_time_display(void)
111 copy_xpm_area(114, 76, 31, 11, 7, 32);
114 /* set time display to -- -- */
115 static void invalid_time_display(void)
117 copy_xpm_area(122, 14, 31, 11, 7, 32);
120 static void reset_scroll(void) {
121 dockapp
->scroll_reset
= 1;
124 static void clear_text_area(void) {
125 copy_xpm_area(66, 9, 52, 7, 6, 50);
128 static void redraw_window(void)
130 if (dockapp
->update
) {
131 XCopyArea(dockapp
->display
, dockapp
->pixmap
, dockapp
->win
,
132 DAGC
, 0, 0, 64, 64, 0, 0);
137 static void new_window(char *display
, char *name
, int argc
, char **argv
)
141 /* Initialise the dockapp window and appicon */
142 DAOpenDisplay(display
, argc
, argv
);
143 DACreateIcon(name
, 64, 64, argc
, argv
);
144 dockapp
->display
= DADisplay
;
145 dockapp
->win
= DAWindow
;
147 XSelectInput(dockapp
->display
, dockapp
->win
,
148 ExposureMask
| ButtonPressMask
| ButtonReleaseMask
|
149 StructureNotifyMask
);
151 /* create the main pixmap . . . */
152 DAMakePixmapFromData(master_xpm
, &dockapp
->pixmap
, &dockapp
->mask
,
153 &dockapp
->width
, &dockapp
->height
);
154 DASetPixmap(dockapp
->pixmap
);
155 DASetShape(dockapp
->mask
);
157 /* text area is 318x7, or 53 characters long */
158 dockapp
->text
= XCreatePixmap(dockapp
->display
, dockapp
->win
, 318, 7,
159 DefaultDepth(dockapp
->display
,
161 if (!dockapp
->text
) {
162 pfatal("FATAL: Cannot create text scroll pixmap!\n");
166 /* force the window to stay this size - otherwise the user could
167 * resize us and see our panties^Wmaster pixmap . . . */
168 hints
= XAllocSizeHints();
170 hints
->flags
|= PMinSize
| PMaxSize
;
171 hints
->min_width
= 64;
172 hints
->max_width
= 64;
173 hints
->min_height
= 64;
174 hints
->max_height
= 64;
175 XSetWMNormalHints(dockapp
->display
, dockapp
->win
, hints
);
182 static void copy_to_text_buffer(int sx
, int sy
, int w
, int h
, int dx
, int dy
)
184 XCopyArea(dockapp
->display
, dockapp
->pixmap
, dockapp
->text
,
185 DAGC
, sx
, sy
, w
, h
, dx
, dy
);
188 static void copy_to_text_area(int sx
, int sy
, int w
, int h
, int dx
, int dy
)
190 XCopyArea(dockapp
->display
, dockapp
->text
, dockapp
->pixmap
,
191 DAGC
, sx
, sy
, w
, h
, dx
, dy
);
194 static void scroll_text(void)
196 static int start
, end
, stop
;
197 int x
= 6; /* x coord of the start of the text area */
198 int y
= 50; /* y coord */
199 int width
= 51; /* width of the text area */
200 int height
= 7; /* height of the text area */
201 int tw
= dockapp
->tw
; /* width of the rendered text */
204 if (!dockapp
->scroll
)
208 * Conceptually this is viewing the text through a scrolling
209 * window - the window starts out with the end immediately before
210 * the text, and stops when the start of the window is immediately
211 * after the end of the text.
213 * We begin with the start of the window at pixel (0 - width) and
214 * as we scroll we render only the portion of the window above
215 * pixel 0. The destination of the copy during this period starts
216 * out at the end of the text area and works left as more of the
217 * text is being copied, until a full window is being copied.
219 * As the end of the window moves out past the end of the text, we
220 * want to keep the destination at the beginning of the text area,
221 * but copy a smaller and smaller chunk of the text. Eventually the
222 * start of the window will scroll past the end of the text, at
223 * which point we stop doing any work and wait to be reset.
226 if (dockapp
->scroll_reset
) {
231 dockapp
->scroll_reset
= 0;
255 copy_to_text_area(sx
, 0, w
, height
, dx
, y
);
262 static void render_text(char *string
)
266 /* drop out immediately if scrolling is disabled - we don't render
267 * any text at all, since there's not much else we could do
268 * sensibly without scrolling. */
269 if (!dockapp
->scroll
)
272 if (strlen(string
) > 53)
275 /* prepare the text area by clearing it */
276 for (i
= 0; i
< 54; i
++) {
277 copy_to_text_buffer(133, 57, 6, 8, i
* 6, 0);
281 for (i
= 0; string
[i
]; i
++) {
282 c
= toupper(string
[i
]);
283 if (c
>= 'A' && c
<= 'Z') { /* letter */
285 copy_to_text_buffer(c
* 6, 67, 6, 7, k
, 0);
286 } else if (c
>= '0' && c
<= '9') { /* number */
288 copy_to_text_buffer(c
* 6 + 66, 58, 6, 7, k
, 0);
289 } else if (c
== '.') {
290 copy_to_text_buffer(140, 58, 6, 7, k
, 0);
291 } else if (c
== '-') {
292 copy_to_text_buffer(126, 58, 6, 7, k
, 0);
296 dockapp
->tw
= k
; /* length of text segment */
297 /* re-scroll the message */
302 static void clear_percentage(void)
304 /* clear the number */
305 copy_xpm_area(95, 47, 21, 9, 37, 16);
307 copy_xpm_area(66, 18, 54, 8, 5, 5);
309 dockapp
->percent
= -1;
312 static void display_percentage(int percent
)
315 int width
= 54; /* width of the bar */
316 float ratio
= 100.0/width
; /* ratio between the current percentage
317 * and the number of pixels in the bar */
322 if (dockapp
->percent
== percent
)
330 if (dockapp
->percent
== -1)
331 copy_xpm_area(127, 28, 5, 7, 52, 17);
333 if (percent
< 100) { /* 0 - 99 */
334 copy_xpm_area(95, 48, 8, 7, 37, 17);
336 copy_xpm_area((percent
/ 10) * 6 + 67, 28, 5, 7, 40, 17);
337 copy_xpm_area((percent
% 10) * 6 + 67, 28, 5, 7, 46, 17);
339 copy_xpm_area(95, 37, 21, 9, 37, 16); /* 100% */
340 dockapp
->percent
= percent
;
342 bar
= (int)((float)percent
/ ratio
);
344 copy_xpm_area(66, 0, bar
, 8, 5, 5);
346 copy_xpm_area(66 + bar
, 18, 54 - bar
, 8, bar
+ 5, 5);
349 static void display_time(int minutes
)
351 static int ohour
= -1, omin
= -1;
354 if (minutes
<= 0) { /* error - clear the display */
355 invalid_time_display();
360 /* render time on the display */
362 /* our display area only fits %2d:%2d, so we need to make sure
363 * what we're displaying will fit in those constraints. I don't
364 * think we're likely to see any batteries that do more than
365 * 100 hours any time soon, so it's fairly safe. */
372 if (hour
== ohour
&& min
== omin
)
376 copy_xpm_area(tmp
* 7 + 1, 76, 6, 11, 7, 32);
378 copy_xpm_area(tmp
* 7 + 1, 76, 6, 11, 14, 32);
380 copy_xpm_area(tmp
* 7 + 1, 76, 6, 11, 25, 32);
382 copy_xpm_area(tmp
* 7 + 1, 76, 6, 11, 32, 32);
383 copy_xpm_area(71, 76, 3, 11, 21, 32);
389 * The reworked state handling stuff.
392 /* set the current state of the power panel */
399 static void really_blink_power_glyph(void)
401 static int counter
= 0;
404 display_power_glyph();
405 else if (counter
== 20)
407 else if (counter
> 30)
412 static void blink_power_glyph(void)
415 really_blink_power_glyph();
418 static void really_blink_battery_glyph(void)
420 static int counter
= 0;
423 display_battery_glyph();
424 else if (counter
== 20)
425 kill_battery_glyph();
426 else if (counter
> 30)
431 static void blink_battery_glyph(void)
434 really_blink_battery_glyph();
437 static void set_power_panel(global_t
*globals
)
439 static enum panel_states power
= PS_NULL
;
440 battery_t
*binfo
= globals
->binfo
;
441 adapter_t
*ap
= &globals
->adapter
;
443 if (ap
->power
== AC
) {
444 if (power
!= PS_AC
) {
446 kill_battery_glyph();
447 display_power_glyph();
449 } else if (ap
->power
== BATT
) {
450 if (power
!= PS_BATT
) {
453 display_battery_glyph();
457 if (globals
->battery_count
> 0) {
458 if (binfo
->charge_state
== CHARGE
)
461 if ((binfo
->state
== CRIT
) && (ap
->power
== BATT
))
462 blink_battery_glyph();
466 void scroll_faster(double factor
) {
467 scroll_reset
= scroll_reset
* factor
;
470 void scroll_slower(double factor
) {
471 scroll_reset
= scroll_reset
* factor
;
474 void reset_scroll_speed(void) {
475 scroll_reset
= DEFAULT_SCROLL_RESET
;
479 * The message that needs to be displayed needs to be decided
480 * according to a heirarchy: a message like not present needs to take
481 * precedence over a global thing like the current power status, and
482 * something like a low battery warning should take precedence over
483 * the "on battery" message. Likewise, a battery charging message
484 * needs to take precedence over the on ac power message. The other
485 * question is how much of a precedence local messages should take
486 * over global ones . . .
488 * So, there are three possible sets of messages: not present, on-line
489 * and off-line messages. We need to decide which of those sets is
490 * appropriate right now, and then decide within them.
493 M_NB
, /* no batteries */
494 M_NP
, /* not present */
495 M_AC
, /* on ac power */
496 M_CH
, /* battery charging */
497 M_BATT
, /* on battery */
498 M_LB
, /* low battery */
499 M_CB
, /* critical low battery */
500 M_HCB
, /* battery reported critical capacity state */
501 M_NULL
, /* empty starting state */
504 static void set_message(global_t
*globals
)
506 static enum messages state
= M_NULL
;
507 battery_t
*binfo
= globals
->binfo
;
508 adapter_t
*ap
= &globals
->adapter
;
510 if (globals
->battery_count
== 0) {
513 reset_scroll_speed();
514 render_text("no batteries");
520 /* battery not present case */
521 if (!binfo
->present
) {
524 reset_scroll_speed();
525 render_text("not present");
527 } else if (ap
->power
== AC
) {
528 if (binfo
->charge_state
== CHARGE
) {
531 reset_scroll_speed();
532 render_text("battery charging");
537 reset_scroll_speed();
538 render_text("on ac power");
542 if (binfo
->state
== CRIT
) {
546 render_text("critical low battery");
548 } else if (binfo
->state
== LOW
) {
552 render_text("low battery");
555 if (state
!= M_BATT
) {
557 reset_scroll_speed();
558 render_text("on battery");
564 void set_time_display(global_t
*globals
)
566 if (globals
->battery_count
== 0) {
567 invalid_time_display();
571 if (globals
->binfo
->charge_state
== CHARGE
)
572 display_time(globals
->binfo
->charge_time
);
573 else if (globals
->binfo
->charge_state
== DISCHARGE
)
574 display_time(globals
->rtime
);
576 invalid_time_display();
579 void clear_batt_id_area(void)
581 copy_xpm_area(125, 40, 7, 11, 51, 32);
584 void set_batt_id_area(int bno
)
586 int w
= 7; /* Width of the number */
587 int h
= 11; /* Height of the number */
588 int dx
= 50; /* x coord of the target area */
589 int dy
= 32; /* y coord of the target area */
590 int sx
= (bno
+ 1) * 7; /* source x coord */
591 int sy
= 76; /* source y coord */
593 copy_xpm_area(sx
, sy
, w
, h
, dx
, dy
);
596 #define VERSION "wmacpi version " WMACPI_VER "\nUsing libacpi version " LIBACPI_VER
598 void cli_wmacpi(global_t
*globals
, int samples
)
600 int i
, j
, sleep_time
= 0;
604 pdebug("samples: %d\n", samples
);
606 sleep_time
= 1000000/samples
;
608 /* we want to acquire samples over some period of time, so . . . */
609 for(i
= 0; i
< samples
+ 2; i
++) {
610 for(j
= 0; j
< globals
->battery_count
; j
++)
611 acquire_batt_info(globals
, j
);
612 acquire_global_info(globals
);
616 ap
= &globals
->adapter
;
617 if(ap
->power
== AC
) {
618 printf("On AC Power");
619 for(i
= 0; i
< globals
->battery_count
; i
++) {
620 binfo
= &batteries
[i
];
621 if(binfo
->present
&& (binfo
->charge_state
== CHARGE
)) {
622 printf("; Battery %s charging", binfo
->name
);
623 printf(", currently at %2d%%", binfo
->percentage
);
624 if(binfo
->charge_time
>= 0)
625 printf(", %2d:%02d remaining",
626 binfo
->charge_time
/60,
627 binfo
->charge_time
%60);
631 } else if(ap
->power
== BATT
) {
632 printf("On Battery");
633 for(i
= 0; i
< globals
->battery_count
; i
++) {
634 binfo
= &batteries
[i
];
635 if(binfo
->present
&& (binfo
->percentage
>= 0))
636 printf(", Battery %s at %d%%", binfo
->name
,
639 if(globals
->rtime
>= 0)
640 printf("; %d:%02d remaining", globals
->rtime
/60,
647 battery_t
*switch_battery(global_t
*globals
, int battno
)
649 globals
->binfo
= &batteries
[battno
];
650 pinfo("changing to monitor battery %s\n", globals
->binfo
->name
);
651 set_batt_id_area(battno
);
654 return globals
->binfo
;
657 int main(int argc
, char **argv
)
659 char *display
= NULL
;
660 int sample_count
= 0;
661 int batt_reinit
, ac_reinit
;
664 int cli
= 0, samples
= 1, critical
= 10;
667 int sleep_time
= 1000000/sleep_rate
;
668 int scroll_count
= 0;
669 enum rtime_mode rt_mode
= RT_RATE
;
671 battery_t
*binfo
= NULL
;
674 DAProgramOption options
[] = {
675 {"-r", "--no-scroll", "disable scrolling message", DONone
, False
, {NULL
}},
676 {"-n", "--no-blink", "disable blinking of various UI elements", DONone
, False
, {NULL
}},
677 {"-x", "--cmdline", "run in command line mode", DONone
, False
, {NULL
}},
678 {"-f", "--force-capacity-mode", "force the use of capacity mode for calculating time remaining", DONone
, False
, {NULL
}},
679 {"-d", "--display", "display or remote display", DOString
, False
, {&display
}},
680 {"-c", "--critical", "set critical low alarm at <number> percent\n (default: 10 percent)", DONatural
, False
, {&critical
}},
681 {"-m", "--battery", "battery number to monitor", DONatural
, False
, {&battery_no
}},
682 {"-s", "--sample-rate", "number of times per minute to sample battery information\n default 20 (once every three seconds)", DONatural
, False
, {&samplerate
}},
683 {"-V", "--verbosity", "Set verbosity", DONatural
, False
, {&verbosity
}},
684 {"-a", "--samples", "number of samples to average over (cli mode only)", DONatural
, False
, {&samples
}},
687 dockapp
= calloc(1, sizeof(struct dockapp
));
688 globals
= calloc(1, sizeof(global_t
));
693 dockapp
->scroll_reset
= 0;
694 globals
->crit_level
= 10;
697 /* after this many samples, we reinit the battery and AC adapter
699 * XXX: make these configurable . . . */
703 /* this needs to be up here because we need to know what batteries
704 * are available /before/ we can decide if the battery we want to
705 * monitor is available. */
706 /* parse command-line options */
707 DAParseArguments(argc
, argv
, options
, 10,
708 "A battery monitor dockapp for ACPI based systems",
717 if (options
[3].used
) {
722 if (samplerate
== 0) samplerate
= 1;
723 if (samplerate
> 600) samplerate
= 600;
725 if (critical
> 100) {
726 fprintf(stderr
, "Please use values between 0 and 100%%\n");
727 fprintf(stderr
, "Using default value of 10%%\n");
730 globals
->crit_level
= critical
;
732 if (battery_no
>= MAXBATT
) {
733 fprintf(stderr
, "Please specify a battery number below %d\n", MAXBATT
);
736 pinfo("Monitoring battery %d\n", battery_no
);
738 if (power_init(globals
))
739 /* power_init functions handle printing error messages */
742 globals
->rt_mode
= rt_mode
;
743 globals
->rt_forced
= rt_forced
;
745 if (battery_no
> globals
->battery_count
) {
746 pinfo("Battery %d not available for monitoring.\n", battery_no
);
749 /* check for cli mode */
751 cli_wmacpi(globals
, samples
);
754 /* check to see if we've got a valid DISPLAY env variable, as a simple check to see if
755 * we're running under X */
756 if (!getenv("DISPLAY")) {
757 pdebug("Not running under X - using cli mode\n");
758 cli_wmacpi(globals
, samples
);
764 /* make new dockapp window */
765 /* Don't even /think/ of asking me why, but if I set the window name to
766 * "acpi", the app refuses to dock properly - it's just plain /weird/.
767 * So, wmacpi it is . . . */
768 new_window(display
, "wmacpi", argc
, argv
);
770 /* get initial statistics */
771 acquire_all_info(globals
);
773 if (globals
->battery_count
> 0) {
774 binfo
= &batteries
[battery_no
];
775 globals
->binfo
= binfo
;
776 set_batt_id_area(battery_no
);
777 pinfo("monitoring battery %s\n", binfo
->name
);
780 clear_time_display();
781 set_power_panel(globals
);
782 set_message(globals
);
789 while (XPending(dockapp
->display
)) {
790 XNextEvent(dockapp
->display
, &event
);
791 switch (event
.type
) {
795 while (XCheckTypedEvent(dockapp
->display
, Expose
, &event
));
799 XCloseDisplay(dockapp
->display
);
805 if (globals
->battery_count
== 0)
808 /* cycle through the known batteries. */
810 battery_no
= battery_no
% globals
->battery_count
;
812 binfo
= switch_battery(globals
, battery_no
);
815 /* what /is/ this crap?
816 * Turns out that libdockapp adds the WM_DELETE_WINDOW atom to
817 * the WM_PROTOCOLS property for the window, which means that
818 * rather than get a simple DestroyNotify message, we get a
819 * nice little message from the WM saying "hey, can you delete
820 * yourself, pretty please?". So, when running as a window
821 * rather than an icon, we're impossible to kill in a friendly
822 * manner, because we're expecting to die from a DestroyNotify
823 * and thus blithely ignoring the WM knocking on our window
826 * This simply checks for that scenario - it may fail oddly if
827 * something else comes to us via a WM_PROTOCOLS ClientMessage
828 * event, but I suspect it's not going to be an issue. */
829 wmdelwin
= XInternAtom(dockapp
->display
, "WM_DELETE_WINDOW", 1);
830 atom
= event
.xclient
.data
.l
[0];
831 if (atom
== wmdelwin
) {
832 XCloseDisplay(dockapp
->display
);
839 /* XXX: some laptops have problems with sampling the battery
840 * regularly - apparently, the BIOS disables interrupts while
841 * reading from the battery, which is generally on a slow bus
842 * and is a slow device, so you get significant periods without
843 * interrupts. This causes interactivity to suffer . . .
845 * My proposed workaround is to allow the user to set the sample
846 * rate - it defaults to ten, but can be set lower (or higher).
848 * The only problem with this is that we need to sample less
849 * frequently, while still allowing the app to update normally.
850 * That means calling redraw_window() and all the set_*() functions
851 * normally, but only calling acquire_all_info() every so often.
852 * As it stands, we only call acquire_all_info() once every three
853 * seconds (once every thirty updates) . . . I'm not entirely sure
854 * /how/ this could cause interactivity problems, but hey . . .
856 * So, given the base rate of once every three seconds, we want to
857 * change this test to . . . */
858 /* Okay, this needs /fixing/ - it's ridiculous. We should be giving
859 * the user the option of saying how many times per minute the
860 * battery should be sampled, defaulting to 20 times.
862 * We sleep for one tenth of a second at a time, so 60 seconds
863 * translates to 600 sleeps. So, we change the default sample
864 * rate to 20, and the calculation below becomes . . .*/
865 if (sample_count
++ == ((sleep_rate
*60)/samplerate
)) {
866 if (globals
->battery_count
== 0) {
869 reinit_batteries(globals
);
871 /* battery appeared */
872 if (globals
->battery_count
> 0) {
873 if (battery_no
> globals
->battery_count
)
876 binfo
= switch_battery(globals
, battery_no
);
880 acquire_all_info(globals
);
882 /* we need to be able to reinitialise batteries and adapters, because
883 * they change - you can hotplug batteries on most laptops these days
884 * and who knows what kind of shit will be happening soon . . . */
885 if (batt_count
++ >= batt_reinit
) {
886 if(reinit_batteries(globals
))
887 pfatal("Oh my god, the batteries are gone!\n");
891 if (ac_count
++ >= ac_reinit
) {
892 if(reinit_ac_adapters(globals
))
893 pfatal("What happened to our AC adapters?!?\n");
899 if (scroll_count
++ >= scroll_reset
) {
904 /* The old code had some kind of weird crap with timers and the like.
905 * As far as I can tell, it's meaningless - the time we want to display
906 * is the time calculated from the remaining capacity, as per the
907 * ACPI spec. The only thing I'd change is the handling of a charging
908 * state: my best guess, based on the behaviour I'm seeing with my
909 * Lifebook, is that the present rate value when charging is the rate
910 * at which the batteries are being charged, which would mean I'd just
911 * need to reverse the rtime calculation to be able to work out how
912 * much time remained until the batteries were fully charged . . .
913 * That would be rather useful, though given it would vary rather a lot
914 * it seems likely that it'd be little more than a rough guesstimate. */
915 set_time_display(globals
);
916 set_power_panel(globals
);
917 set_message(globals
);
919 if (globals
->battery_count
== 0) {
921 clear_batt_id_area();
923 display_percentage(binfo
->percentage
);
927 /* redraw_window, if anything changed - determined inside