jcs
/wifi_da
/amendments
/20
window: Do updates on an off-screen bitmap to avoid flashing
jcs made amendment 20 about 1 year ago
--- window.c Tue Oct 24 09:42:59 2023
+++ window.c Tue Oct 24 23:07:34 2023
@@ -28,6 +28,7 @@ SICNHandle signal_icons;
ControlHandle ssid_list;
MenuHandle ssid_menu;
Rect ssid_menu_rect;
+BitMap win_shadow;
short nwifi_scan_networks = 0;
struct wifi_network_entry wifi_menu_networks[nitems(wifi_scan_networks)] = { 0 };
short nwifi_menu_networks = 0;
@@ -52,6 +53,10 @@ create_window(short ctlrefnum)
win = NewWindow(0L, &bounds, "\pWi-Fi", true, rDocProc, 0L, true, 0L);
((WindowPeek)win)->windowKind = ctlrefnum;
+
+ win_shadow.rowBytes = (((DA_WIDTH - 1) / 16) + 1) * 2;
+ win_shadow.baseAddr = xmalloczero(win_shadow.rowBytes * DA_HEIGHT);
+ SetRect(&win_shadow.bounds, 0, 0, DA_WIDTH, DA_HEIGHT);
signal_icons = (SICNHandle)GetResource('SICN', OwnedResourceID(0));
if (signal_icons == NULL)
@@ -96,11 +101,15 @@ update_window(bool force)
short i, icon;
RgnHandle tmpRgn;
Rect r, destRect;
- BitMap bm;
+ BitMap bm, cur_bits;
GetPort(&savePort);
SetPort(win);
+ DEBUG_LOG(("redrawing window"));
+ cur_bits = win->portBits;
+ SetPortBits(&win_shadow);
+
if (!force)
BeginUpdate(win);
@@ -148,6 +157,11 @@ update_window(bool force)
if (!force)
EndUpdate(win);
+ SetPortBits(&cur_bits);
+
+ CopyBits(&win_shadow, &win->portBits, &win_shadow.bounds,
+ &win_shadow.bounds, srcCopy, nil);
+
ValidRect(&win->portRect);
SetPort(savePort);
}
@@ -166,11 +180,15 @@ update_wifi_cur_info(void)
if (memcmp(&old_info, &wifi_cur_info, sizeof(old_info)) != 0) {
if (memcmp(&old_info.ssid, &wifi_cur_info.ssid,
- sizeof(old_info.ssid)) == 0)
+ sizeof(old_info.ssid)) == 0) {
/* just updating RSSI */
+ DEBUG_LOG(("update_wifi_cur_info: just updating rssi to %d",
+ wifi_cur_info.rssi));
update_window(true);
- else
+ } else {
+ DEBUG_LOG(("update_wifi_cur_info: updating ssid list"));
update_wifi_ssid_list(false);
+ }
}
}
@@ -240,7 +258,7 @@ update_wifi_ssid_list(bool update_networks)
CtoPstr(ssid);
if (n > 0)
- InsMenuItem(ssid_menu, "\pcarl", mitem);
+ InsMenuItem(ssid_menu, "\p...", mitem);
SetItem(ssid_menu, mitem, ssid);