4 Commits
12 changed files with 5167 additions and 4365 deletions
+5 -1
View File
@@ -23,7 +23,11 @@ The real taskbar is hidden and a see-through pill takes its place. The pill is a
- Click the newspaper and a panel of local headlines opens above the bar, newest first, with the outlet and how long ago each ran. Click a headline and it opens in your default browser. It uses the same ZIP code as the weather: the ZIP code is turned into a town name and the headlines are Google News' feed for that town, so someone in 43220 gets Columbus stations and papers and someone in 46750 gets Fort Wayne and Huntington ones. The headlines are only downloaded when a ZIP code is set. Small towns have fewer stories than cities.
- "Show weather on the bar" and "Show local news on the bar" in the settings window turn either feature off. The icon leaves the bar and nothing is downloaded for it; tick the box again and it comes back.
- Click the little speech bubble and Google Messages for web opens in a small window above the bar, so you can read and answer texts without opening a browser tab. The first time, scan the QR code from the Messages app on your phone (Settings, Device pairing) and tick "Remember this computer"; after that it stays signed in. It runs Microsoft Edge in app mode (no tabs, no address bar) with its own private profile folder in `%LOCALAPPDATA%\MirrorBar\messages`, separate from your normal Edge, and goes only to messages.google.com. Once you have paired, MirrorBar quietly starts it in the background about 20 seconds after it launches, keeps the window just off the edge of the screen, and shows the unread count from the window title as a red number on the bubble. Click anywhere else and the window slides away again. Right-click the bubble and choose "Close Messages" to stop the background window and give the memory back. Messages for web only works while your phone is on and connected; that is how Google built it. `messages-titles.txt` in the MirrorBar data folder keeps the first 25 different window titles it has seen, only so the unread badge can be tuned; delete it any time.
- "Show weather on the bar", "Show local news on the bar", "Show system stats on the bar" and "Show Google Messages on the bar" in the settings window turn each feature off. The icon leaves the bar and nothing is downloaded for it; tick the box again and it comes back.
- The weather, news and system stats panels are as see-through as the bar itself: set the bar to Clear and the panels go clear too, with only their text, pictures and outline staying solid. Untick "Panels match the bar's transparency" in the settings window to keep the panels solid.
- Click the little monitor and a panel opens with the usual neofetch information: OS, host, kernel, uptime, resolution, CPU, GPU, memory, each fixed disk, battery and local IP. Click any line to copy it to the clipboard, or click the top of the panel to copy everything as plain text you can paste into other programs. Nothing leaves your PC; it is all read from Windows.
- Pick the color of the Windows logo, the clock, and the battery/volume/wifi/arrow icons from the right-click menu (white, blue, sky blue, green, yellow, orange, red, pink, purple, black).
+32 -1
View File
@@ -14,6 +14,7 @@ var (
showWeather = true
showNews = true
showSys = true
showGM = true // the Google Messages bubble
)
func featuresFile() string { return filepath.Join(dataDir(), "features.txt") }
@@ -36,12 +37,16 @@ func loadFeatures() {
showNews = on
case "sys":
showSys = on
case "messages":
showGM = on
case "panelfade":
flyMatchBar = on
}
}
}
func saveFeatures() {
s := "weather=" + b01(showWeather) + "\nnews=" + b01(showNews) + "\nsys=" + b01(showSys) + "\n"
s := "weather=" + b01(showWeather) + "\nnews=" + b01(showNews) + "\nsys=" + b01(showSys) + "\nmessages=" + b01(showGM) + "\npanelfade=" + b01(flyMatchBar) + "\n"
_ = os.MkdirAll(dataDir(), 0o755)
_ = os.WriteFile(featuresFile(), []byte(s), 0o644)
}
@@ -96,6 +101,32 @@ func setShowSys(on bool) {
featuresChanged()
}
// setShowGM is called by the settings window.
func setShowGM(on bool) {
if showGM == on {
return
}
showGM = on
saveFeatures()
if on {
gmAutoTried = false // let the background check start Messages again
} else {
gmClose()
}
featuresChanged()
}
// setFlyMatchBar is called by the settings window: should the panels be as
// see-through as the bar?
func setFlyMatchBar(on bool) {
if flyMatchBar == on {
return
}
flyMatchBar = on
saveFeatures()
flyRefreshAll()
}
func featuresChanged() {
settingsZipStatusUpdate()
redraw(hwndMain)
+43 -42
View File
@@ -106,7 +106,7 @@ func weatherInit(inst uintptr) {
wc.Size = uint32(unsafe.Sizeof(wc))
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
wxHwnd, _, _ = pCreateWindowEx.Call(
wsExToolWindow|wsExTopmost|wsExNoActivate,
wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
uintptr(unsafe.Pointer(className)),
uintptr(unsafe.Pointer(u16(""))),
wsPopup,
@@ -155,6 +155,7 @@ func weatherToggle() {
previewHide()
newsHide() // one panel at a time
sysHide()
gmHide()
weatherRefresh(false)
wxShown = true
wxPrevBtn = true // ignore a button that is still held from the click that opened this
@@ -223,7 +224,7 @@ func weatherPlace() {
x = clampI(x, 0, sw-cw)
y = clampI(y, 0, sh-ch)
pSetWindowPos.Call(wxHwnd, hwndTopmost, uintptr(x), uintptr(y), uintptr(cw), uintptr(ch), swpNoActivate|swpShowWindow)
pInvalidateRect.Call(wxHwnd, 0, 1)
flyRefresh(wxHwnd)
}
// weatherPoll closes the panel when a mouse button goes down anywhere outside
@@ -302,44 +303,13 @@ func wxMakeFonts() {
func wxPaint(hwnd uintptr) { flyPaint(hwnd, wxDraw) }
// flyPaint paints a panel at double size into a memory bitmap with the given
// drawing function, then shrinks it onto the window.
// flyPaint answers a paint request: the panel is rendered see-through (see
// flyrender.go) instead of being painted by Windows.
func flyPaint(hwnd uintptr, draw func(hdc uintptr, W, H int32)) {
var ps paintStruct
hdc, _, _ := pBeginPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
defer pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
var rc rect
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&rc)))
W, H := rc.Right-rc.Left, rc.Bottom-rc.Top
if W <= 0 || H <= 0 {
return
}
const ss = 2
mem, _, _ := pCreateCompatibleDC.Call(hdc)
defer pDeleteDC.Call(mem)
bmi := bitmapInfoHeader{Width: W * ss, Height: -(H * ss), Planes: 1, BitCount: 32}
bmi.Size = uint32(unsafe.Sizeof(bmi))
var bits unsafe.Pointer
bmp, _, _ := pCreateDIBSection.Call(hdc, uintptr(unsafe.Pointer(&bmi)), 0, uintptr(unsafe.Pointer(&bits)), 0, 0)
if bmp == 0 || bits == nil {
return
}
defer pDeleteObject.Call(bmp)
old, _, _ := pSelectObject.Call(mem, bmp)
defer pSelectObject.Call(mem, old)
saved := scale
defer func() { scale = saved }()
scale *= ss
wxMakeFonts()
draw(mem, W*ss, H*ss)
scale = saved
pSetStretchBltMode.Call(hdc, halftone)
pSetBrushOrgEx.Call(hdc, 0, 0, 0)
pStretchBlt.Call(hdc, 0, 0, uintptr(W), uintptr(H), mem, 0, 0, uintptr(W*ss), uintptr(H*ss), srcCopy)
pBeginPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
flyRender(hwnd, draw)
}
var (
@@ -362,8 +332,7 @@ func wxText(hdc uintptr, s string, r rect, font, col, flags uintptr) {
// here is a double size distance.
func wxDraw(hdc uintptr, W, H int32) {
u := px
fillRaw(hdc, rect{0, 0, W, H}, iconColor()) // the outline follows the tray icon color
fillRaw(hdc, rect{u(1), u(1), W - u(1), H - u(1)}, colBack)
flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
pad := u(14)
inner := W - 2*pad
@@ -512,8 +481,40 @@ func wxSunGlyph(hdc uintptr, cx, cy, s float64) {
}
func wxCrescent(hdc uintptr, cx, cy, rad float64) {
wxCircle(hdc, cx, cy, rad, rgb(235, 232, 205))
wxCircle(hdc, cx+0.45*rad, cy-0.25*rad, 0.85*rad, colBack)
brush, _, _ := pCreateSolidBrush.Call(rgb(235, 232, 205))
defer pDeleteObject.Call(brush)
ix, iy, ir := cx+0.45*rad, cy-0.25*rad, 0.85*rad // the circle that is cut out
top := int32(math.Round(cy))
r := int32(math.Ceil(rad))
for dy := -r; dy <= r; dy++ {
y := top + dy
oh2 := rad*rad - float64(dy)*float64(dy)
if oh2 <= 0 {
continue
}
oh := math.Sqrt(oh2)
x0, x1 := cx-oh, cx+oh
var segs [][2]float64
fy := float64(y) + 0.5 - iy
if ih2 := ir*ir - fy*fy; ih2 > 0 {
ih := math.Sqrt(ih2)
if l := ix - ih; l > x0 {
segs = append(segs, [2]float64{x0, math.Min(l, x1)})
}
if rr := ix + ih; rr < x1 {
segs = append(segs, [2]float64{math.Max(rr, x0), x1})
}
} else {
segs = append(segs, [2]float64{x0, x1})
}
for _, sg := range segs {
if sg[1]-sg[0] < 0.5 {
continue
}
line := rect{int32(math.Round(sg[0])), y, int32(math.Round(sg[1])), y + 1}
pFillRect.Call(hdc, uintptr(unsafe.Pointer(&line)), brush)
}
}
}
// wxIcon draws the picture for a kind of weather inside the square r.
+166
View File
@@ -0,0 +1,166 @@
package main
// Painting the three panels (weather, news, system stats) as see-through
// windows that follow the bar's own background opacity. The panels are painted
// the same way the bar is: the content (text, pictures, lines) is drawn twice at
// double size, once on black and once on white; comparing the two copies shows
// how solid every pixel is. The panel's background color is then added back at
// the bar's see-through level, and the result is handed to Windows as a layered
// window with a transparency value for every pixel.
import (
"unsafe"
)
// flyMatchBar is the "panels match the bar's transparency" setting. When it is
// off the panels are solid, as they were before.
var flyMatchBar = true
func flyBgAlpha() uint32 {
if flyMatchBar {
return uint32(bgAlpha)
}
return 255
}
// flyFrame draws the one pixel outline around a panel, in the tray icon color.
// The background inside it is not painted here; flyRender adds it.
func flyFrame(hdc uintptr, W, H int32) {
t, col := px(1), iconColor()
fillRaw(hdc, rect{0, 0, W, t}, col)
fillRaw(hdc, rect{0, H - t, W, H}, col)
fillRaw(hdc, rect{0, 0, t, H}, col)
fillRaw(hdc, rect{W - t, 0, W, H}, col)
}
// flyLayer paints the content onto a flat color and returns its pixels.
func flyLayer(screen uintptr, w, h int32, base uintptr, draw func(hdc uintptr, W, H int32)) []uint32 {
mem, _, _ := pCreateCompatibleDC.Call(screen)
defer pDeleteDC.Call(mem)
bmi := bitmapInfoHeader{Width: w, Height: -h, Planes: 1, BitCount: 32}
bmi.Size = uint32(unsafe.Sizeof(bmi))
var bits unsafe.Pointer
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0, uintptr(unsafe.Pointer(&bits)), 0, 0)
if bmp == 0 || bits == nil {
return nil
}
defer pDeleteObject.Call(bmp)
old, _, _ := pSelectObject.Call(mem, bmp)
defer pSelectObject.Call(mem, old)
fillRaw(mem, rect{0, 0, w, h}, base)
draw(mem, w, h)
pGdiFlush.Call()
out := make([]uint32, int(w)*int(h))
copy(out, unsafe.Slice((*uint32)(bits), len(out)))
return out
}
// flyRender paints one panel and puts it on the screen.
func flyRender(hwnd uintptr, draw func(hdc uintptr, W, H int32)) {
if hwnd == 0 {
return
}
if v, _, _ := pIsWindowVisible.Call(hwnd); v == 0 {
return
}
var rc rect
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&rc)))
W, H := rc.Right-rc.Left, rc.Bottom-rc.Top
if W <= 0 || H <= 0 {
return
}
const ss = 2
screen, _, _ := pGetDC.Call(0)
defer pReleaseDC.Call(0, screen)
saved := scale
scale *= ss
wxMakeFonts()
onBlack := flyLayer(screen, W*ss, H*ss, rgb(0, 0, 0), draw)
onWhite := flyLayer(screen, W*ss, H*ss, rgb(255, 255, 255), draw)
scale = saved
n := int(W) * int(H)
if len(onBlack) != n*ss*ss || len(onWhite) != len(onBlack) {
return
}
mem, _, _ := pCreateCompatibleDC.Call(screen)
defer pDeleteDC.Call(mem)
bmi := bitmapInfoHeader{Width: W, Height: -H, Planes: 1, BitCount: 32}
bmi.Size = uint32(unsafe.Sizeof(bmi))
var bits unsafe.Pointer
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0, uintptr(unsafe.Pointer(&bits)), 0, 0)
if bmp == 0 || bits == nil {
return
}
defer pDeleteObject.Call(bmp)
old, _, _ := pSelectObject.Call(mem, bmp)
defer pSelectObject.Call(mem, old)
pix := unsafe.Slice((*uint32)(bits), n)
a := flyBgAlpha()
bgR, bgG, bgB := uint32(28)*a/255, uint32(28)*a/255, uint32(34)*a/255 // colBack at its see-through level
stride := int(W) * ss
for i := range pix {
x, y := i%int(W), i/int(W)
var br, bg, bb, wr, wg, wb uint32
for dy := 0; dy < ss; dy++ {
for dx := 0; dx < ss; dx++ {
k := (y*ss+dy)*stride + x*ss + dx
c, w := onBlack[k], onWhite[k]
br += c >> 16 & 0xFF
bg += c >> 8 & 0xFF
bb += c & 0xFF
wr += w >> 16 & 0xFF
wg += w >> 8 & 0xFF
wb += w & 0xFF
}
}
const cnt = ss * ss
br, bg, bb, wr, wg, wb = br/cnt, bg/cnt, bb/cnt, wr/cnt, wg/cnt, wb/cnt
d := (sub0(wr, br) + sub0(wg, bg) + sub0(wb, bb)) / 3
fa := 255 - min(d, 255) // how solid the content is here
fr, fg, fb := min(br, fa), min(bg, fa), min(bb, fa)
inv := 255 - fa
oa := fa + a*inv/255
pix[i] = oa<<24 | (fr+bgR*inv/255)<<16 | (fg+bgG*inv/255)<<8 | (fb + bgB*inv/255)
}
var wr rect
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
dst := point{wr.Left, wr.Top}
sz := size{W, H}
src := point{0, 0}
blend := blendFunction{Op: 0, Flags: 0, Alpha: 255, Format: 1} // AC_SRC_OVER, AC_SRC_ALPHA
pUpdateLayeredWindow.Call(hwnd, screen,
uintptr(unsafe.Pointer(&dst)), uintptr(unsafe.Pointer(&sz)),
mem, uintptr(unsafe.Pointer(&src)), 0,
uintptr(unsafe.Pointer(&blend)), ulwAlpha)
}
// flyRefresh repaints one of the panels.
func flyRefresh(hwnd uintptr) {
switch hwnd {
case wxHwnd:
flyRender(hwnd, wxDraw)
case newsHwnd:
flyRender(hwnd, newsDraw)
case sysHwnd:
flyRender(hwnd, sysDraw)
}
}
// flyRefreshAll repaints whichever panel is open (after a setting changed).
func flyRefreshAll() {
if wxShown {
flyRefresh(wxHwnd)
}
if newsShown {
flyRefresh(newsHwnd)
}
if sysShown {
flyRefresh(sysHwnd)
}
}
+553
View File
@@ -0,0 +1,553 @@
package main
// The Google Messages flyout: a speech bubble on the bar that opens Messages for
// web (messages.google.com) in a small window above the bar, so you can read and
// answer texts without opening a browser tab.
//
// How it works: MirrorBar starts Microsoft Edge in "app" mode (no tabs, no address
// bar) with its own private profile folder, so the sign-in from pairing your phone
// is remembered and never touches your normal Edge. Edge is already on every
// Windows 11 PC, so there is nothing to install. The window is kept just off the
// edge of the screen while the flyout is closed; clicking the bubble slides it
// above the bar, clicking anywhere else slides it away again. Because the page
// keeps running, the unread number in its window title can be shown on the bubble.
//
// Messages for web only works while the phone is on and connected; that is how
// Google built it, not something MirrorBar can change.
import (
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"syscall"
"time"
"unsafe"
)
const (
gmURL = "https://messages.google.com/web/conversations"
gmW = 780.0 // flyout size, in 96 dpi units
gmH = 580.0
gmTimerID = 3 // on the main window: watches for clicks outside the flyout
gmParkX = -32000
gmParkY = -32000
gmAutoDelay = 20 * time.Second // wait this long after start before opening Messages in the background
gmLaunchMax = 45 * time.Second // give up looking for the window after this long
gmSwpNoSize = 0x0001
gmSwpNoMove = 0x0002
gmSwpNoZOrder = 0x0004
gmSwpFrameChanged = 0x0020
gmSwShowNoActive = 4
gmWsExAppWindow = 0x00040000
gmGaRootOwner = 3
)
var (
pIsWindow = user32.NewProc("IsWindow")
pWindowFromPoint = user32.NewProc("WindowFromPoint")
pGetAncestor = user32.NewProc("GetAncestor")
pSetWindowLongPtr = user32.NewProc("SetWindowLongPtrW")
pSetWindowPlace = user32.NewProc("SetWindowPlacement")
)
var (
gmHwnd uintptr
gmPid uint32
gmShown bool
gmPrevBtn bool
gmPrevFg uintptr
gmShownAt time.Time
gmLaunching bool
gmLaunchedAt time.Time
gmWantOpen bool // the bubble was clicked while the window was still starting
gmAutoTried bool
gmUnread int
gmEnumCb uintptr
gmFound uintptr
gmLogged = map[string]bool{}
gmLoggedN int
)
type gmPlacementT struct {
Length uint32
Flags uint32
ShowCmd uint32
MinPos point
MaxPos point
Normal rect
}
// ---------- the button on the bar ----------
func drawGMIcon(hdc uintptr, r rect) {
if !layerFg {
return
}
col := iconColor()
cx, cy := center(r)
e := px(1)
l, t, rt, b := cx-px(6.5), cy-px(5.5), cx+px(6.5), cy+px(3)
fillRaw(hdc, rect{l, t, rt, t + e}, col)
fillRaw(hdc, rect{l, b - e, rt, b}, col)
fillRaw(hdc, rect{l, t, l + e, b}, col)
fillRaw(hdc, rect{rt - e, t, rt, b}, col)
// the little tail at the bottom left
polyline(hdc, []point{{cx - px(3.5), b}, {cx - px(3.5), cy + px(6)}, {cx - px(0.5), b}}, e, col)
// two lines of "text" in the bubble
fillRaw(hdc, rect{cx - px(4), cy - px(3), cx + px(4), cy - px(3) + e}, col)
fillRaw(hdc, rect{cx - px(4), cy - px(0.5), cx + px(1.5), cy - px(0.5) + e}, col)
if gmUnread > 0 {
br, bg, bb := styleColor(235, 70, 70)
bx, by, rad := cx+px(6.5), cy-px(5.5), px(5)
circleRaw(hdc, bx, by, rad, rgb(br, bg, bb))
txt := strconv.Itoa(gmUnread)
if gmUnread > 9 {
txt = "9+"
}
f := makeFont(px(8), 700)
old, _, _ := pSelectObject.Call(hdc, f)
pSetBkMode.Call(hdc, transparent)
pSetTextColor.Call(hdc, rgb(255, 255, 255))
drawText(hdc, txt, rect{bx - rad, by - rad, bx + rad + 1, by + rad + 1})
pSelectObject.Call(hdc, old)
pDeleteObject.Call(f)
}
}
// ---------- finding and starting the browser window ----------
func gmProfileDir() string { return filepath.Join(dataDir(), "messages") }
func gmProfileExists() bool {
_, err := os.Stat(filepath.Join(gmProfileDir(), "Local State"))
return err == nil
}
// gmBrowserPath is Edge (always there on Windows 11), or Chrome if Edge is gone.
func gmBrowserPath() string {
type cand struct{ env, vendor, app, exe string }
for _, c := range []cand{
{"ProgramFiles(x86)", "Microsoft", "Edge", "msedge.exe"},
{"ProgramFiles", "Microsoft", "Edge", "msedge.exe"},
{"LOCALAPPDATA", "Microsoft", "Edge", "msedge.exe"},
{"ProgramFiles", "Google", "Chrome", "chrome.exe"},
{"ProgramFiles(x86)", "Google", "Chrome", "chrome.exe"},
{"LOCALAPPDATA", "Google", "Chrome", "chrome.exe"},
} {
base := os.Getenv(c.env)
if base == "" {
continue
}
p := filepath.Join(base, c.vendor, c.app, "Application", c.exe)
if _, err := os.Stat(p); err == nil {
return p
}
}
return ""
}
// gmLaunch starts the app window. Started in the background it opens minimized
// and is never given focus, so it does not interrupt whatever is being typed.
func gmLaunch(visible bool) bool {
exe := gmBrowserPath()
if exe == "" {
return false
}
prof := gmProfileDir()
if err := os.MkdirAll(prof, 0o755); err != nil {
return false
}
args := []string{
exe,
"--app=" + gmURL,
"--user-data-dir=" + prof,
"--no-first-run",
"--no-default-browser-check",
// keep the page awake while its window is parked off the screen
"--disable-features=CalculateNativeWinOcclusion",
"--disable-renderer-backgrounding",
"--disable-background-timer-throttling",
"--disable-backgrounding-occluded-windows",
}
parts := make([]string, len(args))
for i, a := range args {
parts[i] = syscall.EscapeArg(a)
}
si := syscall.StartupInfo{Flags: 1} // STARTF_USESHOWWINDOW
si.Cb = uint32(unsafe.Sizeof(si))
si.ShowWindow = 7 // SW_SHOWMINNOACTIVE
if visible {
si.ShowWindow = 1 // SW_SHOWNORMAL
}
var pi syscall.ProcessInformation
err := syscall.CreateProcess(u16(exe), u16(strings.Join(parts, " ")), nil, nil, false, 0, nil, nil, &si, &pi)
if err != nil {
return false
}
gmPid = pi.ProcessId
syscall.CloseHandle(pi.Process)
syscall.CloseHandle(pi.Thread)
gmLaunching = true
gmLaunchedAt = time.Now()
gmWantOpen = visible
return true
}
func gmWindowTitle(hwnd uintptr) string {
var tb [512]uint16
n, _, _ := pGetWindowText.Call(hwnd, uintptr(unsafe.Pointer(&tb[0])), 512)
return syscall.UTF16ToString(tb[:n])
}
// gmTitleMatch is true for the app window's title ("Messages for web", maybe
// with a count in front) and false for ordinary browser windows.
func gmTitleMatch(t string) bool {
l := strings.ToLower(t)
if strings.Contains(l, "microsoft edge") || strings.Contains(l, "google chrome") {
return false
}
return strings.Contains(l, "messages")
}
func gmEnumProc(hwnd, lparam uintptr) uintptr {
var cls [64]uint16
n, _, _ := pGetClassName.Call(hwnd, uintptr(unsafe.Pointer(&cls[0])), 64)
if syscall.UTF16ToString(cls[:n]) != "Chrome_WidgetWin_1" {
return 1
}
if !gmTitleMatch(gmWindowTitle(hwnd)) {
return 1
}
var pid uint32
pGetWindowThreadProcessId.Call(hwnd, uintptr(unsafe.Pointer(&pid)))
if gmPid != 0 && pid == gmPid {
gmFound = hwnd
return 0 // exactly the window we started
}
if gmFound == 0 {
gmFound = hwnd
}
return 1
}
func gmFindWindow() uintptr {
if gmEnumCb == 0 {
gmEnumCb = syscall.NewCallback(gmEnumProc)
}
gmFound = 0
pEnumWindows.Call(gmEnumCb, 0)
return gmFound
}
func gmWindowOK() bool {
if gmHwnd == 0 {
return false
}
ok, _, _ := pIsWindow.Call(gmHwnd)
return ok != 0
}
// gmAdopt takes charge of the window once it exists: it stays out of the app
// list and Alt+Tab, and sits off screen until the bubble is clicked.
func gmAdopt(h uintptr) {
gmHwnd = h
var pid uint32
pGetWindowThreadProcessId.Call(h, uintptr(unsafe.Pointer(&pid)))
if pid != 0 {
gmPid = pid
}
ex, _, _ := pGetWindowLongPtr.Call(h, neg(-20))
want := (ex | wsExToolWindow) &^ gmWsExAppWindow
if want != ex {
pSetWindowLongPtr.Call(h, neg(-20), want)
pSetWindowPos.Call(h, 0, 0, 0, 0, 0, gmSwpNoMove|gmSwpNoSize|gmSwpNoZOrder|swpNoActivate|gmSwpFrameChanged)
}
gmLaunching = false
if gmWantOpen {
gmWantOpen = false
gmShow()
} else {
gmPark()
}
}
// ---------- moving the window ----------
func gmSize() (int32, int32) {
sw, sh := screenSize()
cw := min(px(gmW), sw-px(16))
ch := min(px(gmH), sh-px(24))
return cw, ch
}
// gmMove puts the window at x, y, w, h. A minimized window is first brought back
// to that spot without taking focus.
func gmMove(x, y, w, h int32, topmost, activate bool) {
if !gmWindowOK() {
return
}
if z, _, _ := pIsZoomed.Call(gmHwnd); z != 0 {
pShowWindow.Call(gmHwnd, swRestore)
}
if ic, _, _ := pIsIconic.Call(gmHwnd); ic != 0 {
cmd := uint32(gmSwShowNoActive)
if activate {
cmd = swRestore
}
wp := gmPlacementT{ShowCmd: cmd, Normal: rect{x, y, x + w, y + h}}
wp.Length = uint32(unsafe.Sizeof(wp))
pSetWindowPlace.Call(gmHwnd, uintptr(unsafe.Pointer(&wp)))
}
after := ^uintptr(1) // HWND_NOTOPMOST
if topmost {
after = hwndTopmost
}
var flags uintptr
if !activate {
flags = swpNoActivate
}
pSetWindowPos.Call(gmHwnd, after, uintptr(x), uintptr(y), uintptr(w), uintptr(h), flags|swpShowWindow)
}
func gmPark() {
cw, ch := gmSize()
gmMove(gmParkX, gmParkY, cw, ch, false, false)
}
// gmPlace is where the flyout goes: above a horizontal bar, to the left of a
// vertical one, centered on the bubble and always on the screen.
func gmPlace() (x, y, w, h int32) {
cw, ch := gmSize()
ar := trayAnchor(trayGM)
var wr rect
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
sw, sh := screenSize()
space := px(8)
if vertical {
x = wr.Left - cw - space
if x < 0 {
x = wr.Right + space
}
y = (ar.Top+ar.Bottom)/2 - ch/2
} else {
x = (ar.Left+ar.Right)/2 - cw/2
y = wr.Top - ch - space
if y < 0 {
y = wr.Bottom + space
}
}
return clampI(x, 0, sw-cw), clampI(y, 0, sh-ch), cw, ch
}
func gmFocus() {
// This program just received the click, so Windows lets it hand the focus on.
pSetForegroundWindow.Call(gmHwnd)
}
// ---------- open, close, click ----------
func gmToggle() {
if !showGM {
return
}
if gmShown {
gmHide()
return
}
previewHide()
weatherHide() // one panel at a time
newsHide()
sysHide()
if gmWindowOK() {
gmShow()
return
}
gmHwnd = 0
if gmLaunching {
gmWantOpen = true // it is still starting; open it the moment it exists
return
}
if !gmLaunch(true) {
shellOpen(gmURL, "") // no Edge or Chrome found: use the default browser
}
}
func gmShow() {
if !gmWindowOK() {
return
}
fg, _, _ := pGetForegroundWindow.Call()
if fg != gmHwnd {
gmPrevFg = fg
}
gmShown = true
gmPrevBtn = true // ignore a button that is still held from the click that opened this
gmShownAt = time.Now()
x, y, w, h := gmPlace()
gmMove(x, y, w, h, true, true)
gmFocus()
pSetTimer.Call(hwndMain, gmTimerID, 80, 0)
}
func gmHide() {
if !gmShown {
return
}
gmShown = false
pKillTimer.Call(hwndMain, gmTimerID)
if !gmWindowOK() {
return
}
fg, _, _ := pGetForegroundWindow.Call()
gmPark()
if fg == gmHwnd && gmPrevFg != 0 && gmPrevFg != hwndMain && gmPrevFg != gmHwnd {
if ok, _, _ := pIsWindow.Call(gmPrevFg); ok != 0 {
pSetForegroundWindow.Call(gmPrevFg) // give the keyboard back to what you were doing
}
}
}
// gmClose shuts the Messages window down (right-click, "Close Messages").
func gmClose() {
gmHide()
if gmWindowOK() {
pPostMessage.Call(gmHwnd, wmClose, 0, 0)
}
gmHwnd = 0
gmLaunching = false
gmWantOpen = false
gmAutoTried = true // do not bring it back by itself
gmUnread = 0
}
func gmShutdown() {
pKillTimer.Call(hwndMain, gmTimerID)
if gmWindowOK() {
pPostMessage.Call(gmHwnd, wmClose, 0, 0)
}
gmHwnd = 0
}
// gmPoll runs every 80 ms while the flyout is open and closes it when a mouse
// button goes down anywhere outside it (the bubble itself is left alone, so
// clicking it can close the flyout).
func gmPoll() {
if !gmShown {
return
}
if !gmWindowOK() {
gmShown = false
pKillTimer.Call(hwndMain, gmTimerID)
return
}
l, _, _ := pGetAsyncKeyState.Call(vkLButton)
r, _, _ := pGetAsyncKeyState.Call(vkRButton)
down := (l|r)&0x8000 != 0
if down && !gmPrevBtn && time.Since(gmShownAt) > 300*time.Millisecond {
var cp point
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
var fr rect
pGetWindowRect.Call(gmHwnd, uintptr(unsafe.Pointer(&fr)))
inside := inRect(fr, cp)
if !inside {
// a dialog or menu that belongs to the Messages window counts as inside
h, _, _ := pWindowFromPoint.Call(uintptr(uint32(cp.X)) | uintptr(uint32(cp.Y))<<32)
if h != 0 {
root, _, _ := pGetAncestor.Call(h, gmGaRootOwner)
inside = root == gmHwnd
}
}
if !inside && !inRect(trayAnchor(trayGM), cp) {
gmHide()
}
}
gmPrevBtn = down
}
// ---------- the background check ----------
var gmCountRe = regexp.MustCompile(`[\(\[](\d{1,3})\+?[\)\]]`)
func gmParseUnread(title string) int {
m := gmCountRe.FindStringSubmatch(title)
if m == nil {
return 0
}
n, _ := strconv.Atoi(m[1])
return n
}
// gmLogTitle keeps the first few different window titles in titles.txt next to
// the Messages profile, so the unread badge can be tuned if Google words it
// differently than expected. It stops after 25 so it never grows.
func gmLogTitle(t string) {
if t == "" || gmLogged[t] || gmLoggedN >= 25 {
return
}
gmLogged[t] = true
gmLoggedN++
f, err := os.OpenFile(filepath.Join(dataDir(), "messages-titles.txt"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return
}
defer f.Close()
if len(t) > 80 {
t = t[:80]
}
_, _ = f.WriteString(time.Now().Format("2006-01-02 15:04:05") + "\t" + t + "\n")
}
// gmTick runs from the bar's 250 ms timer. It starts Messages in the background
// once you have paired a phone, notices when the window goes away, and reads
// the unread count from the window title. Returns true when the bar needs a
// repaint.
func gmTick(tick int) (changed bool) {
defer func() {
if r := recover(); r != nil {
changed = false // optional feature; never take the bar down with it
}
}()
if !showGM {
return false
}
if gmHwnd != 0 && !gmWindowOK() {
gmHwnd = 0
gmShown = false
pKillTimer.Call(hwndMain, gmTimerID)
changed = gmUnread != 0
gmUnread = 0
}
if gmHwnd == 0 {
switch {
case gmLaunching:
if h := gmFindWindow(); h != 0 {
gmAdopt(h)
} else if time.Since(gmLaunchedAt) > gmLaunchMax {
gmLaunching = false
gmWantOpen = false
}
case !gmAutoTried && time.Since(startedAt) > gmAutoDelay:
gmAutoTried = true
if h := gmFindWindow(); h != 0 {
gmAdopt(h) // left over from an earlier run of MirrorBar
} else if gmProfileExists() {
gmLaunch(false)
}
}
}
if gmHwnd != 0 && tick%8 == 0 {
t := gmWindowTitle(gmHwnd)
gmLogTitle(t)
if n := gmParseUnread(t); n != gmUnread {
gmUnread = n
changed = true
}
}
return changed
}
+9 -1
View File
@@ -462,7 +462,7 @@ func restoreAll() {
// ---------- open windows ----------
func collectWindow(hwnd uintptr) {
if hwnd == hwndMain {
if hwnd == hwndMain || (gmHwnd != 0 && hwnd == gmHwnd) {
return
}
vis, _, _ := pIsWindowVisible.Call(hwnd)
@@ -974,6 +974,10 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
return 0
case wmTimer:
if wparam == gmTimerID {
gmPoll()
return 0
}
if wparam == previewTimerID {
previewTick()
return 0
@@ -981,6 +985,9 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
hideTaskbar()
tick++
changed := refreshApps(tick%16 == 0)
if gmTick(tick) {
changed = true
}
if tick%4 == 0 && refreshStatus(tick%16 == 0) {
changed = true
}
@@ -1190,6 +1197,7 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
weatherShutdown()
newsShutdown()
sysShutdown()
gmShutdown()
abd := appBarData{Hwnd: hwnd}
appBar(abmRemove, &abd)
pKillTimer.Call(hwnd, timerID)
+5 -5
View File
@@ -65,7 +65,7 @@ func newsInit(inst uintptr) {
wc.Size = uint32(unsafe.Sizeof(wc))
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
newsHwnd, _, _ = pCreateWindowEx.Call(
wsExToolWindow|wsExTopmost|wsExNoActivate,
wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
uintptr(unsafe.Pointer(className)),
uintptr(unsafe.Pointer(u16(""))),
wsPopup,
@@ -119,6 +119,7 @@ func newsToggle() {
previewHide()
weatherHide() // one panel at a time
sysHide()
gmHide()
newsRefresh(false)
newsShown = true
newsPrevBtn = true // ignore a button that is still held from the click that opened this
@@ -168,7 +169,7 @@ func newsPlace() {
lh = newsHead + float64(newsVisible)*newsRow + newsFoot
}
flyPlace(newsHwnd, trayAnchor(trayNews), px(newsW), px(lh))
pInvalidateRect.Call(newsHwnd, 0, 1)
flyRefresh(newsHwnd)
}
// newsDone runs when a download finishes.
@@ -202,7 +203,7 @@ func newsPoll() {
}
if h != newsHover {
newsHover = h
pInvalidateRect.Call(newsHwnd, 0, 0)
flyRefresh(newsHwnd)
}
}
@@ -248,8 +249,7 @@ func newsClick(x, y int32) {
func newsDraw(hdc uintptr, W, H int32) {
u := px
fillRaw(hdc, rect{0, 0, W, H}, iconColor()) // the outline follows the tray icon color
fillRaw(hdc, rect{u(1), u(1), W - u(1), H - u(1)}, colBack)
flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
pad := u(14)
s := newsSnapshot()
+1 -2
View File
@@ -37,8 +37,7 @@ func radarAdvance() {
}
rdHold = 0
rdIdx = (rdIdx + 1) % n
rc := rect{px(14), px(226), px(14 + 312), px(226 + 150)}
pInvalidateRect.Call(wxHwnd, uintptr(unsafe.Pointer(&rc)), 0)
flyRefresh(wxHwnd)
}
func radarBox(hdc uintptr, r rect) {
+2
View File
@@ -237,6 +237,8 @@ func renderLayer(screen uintptr, w, h int32, fills, fg bool, base uintptr) []uin
drawNewsIcon(memV, r)
case traySys:
drawSysIcon(memV, r)
case trayGM:
drawGMIcon(memV, r)
}
}
pGdiFlush.Call()
+19 -7
View File
@@ -71,6 +71,8 @@ const (
idShowWeather = 213
idShowNews = 214
idShowSys = 215
idPanelFade = 216
idShowGM = 217
)
var (
@@ -81,7 +83,7 @@ var (
ctlAlpha, ctlAlphaValue, ctlLogo, ctlClock, ctlTrayIcons, ctlStyle uintptr
ctlVertical, ctlAutostart uintptr
ctlZip, ctlZipStatus uintptr
ctlShowWeather, ctlShowNews, ctlShowSys uintptr
ctlShowWeather, ctlShowNews, ctlShowSys, ctlShowGM, ctlPanelFade uintptr
zipSyncing bool // true while the program itself is filling in the ZIP box
)
@@ -133,7 +135,7 @@ func openSettings() {
settingsFont = makeFont(px(13), 400)
}
r := rect{0, 0, px(400), px(460)}
r := rect{0, 0, px(400), px(516)}
pAdjustWindowRectEx.Call(uintptr(unsafe.Pointer(&r)), wsWindowFrame, 0, 0)
ow, oh := r.Right-r.Left, r.Bottom-r.Top
sw, sh := screenSize()
@@ -183,12 +185,14 @@ func openSettings() {
ctlShowWeather = makeControl(hw, inst, "BUTTON", "Show weather on the bar", bsAutoCheckBox|wsTabStop, 16, 262, 368, 22, idShowWeather)
ctlShowNews = makeControl(hw, inst, "BUTTON", "Show local news on the bar", bsAutoCheckBox|wsTabStop, 16, 290, 368, 22, idShowNews)
ctlShowSys = makeControl(hw, inst, "BUTTON", "Show system stats on the bar", bsAutoCheckBox|wsTabStop, 16, 318, 368, 22, idShowSys)
ctlVertical = makeControl(hw, inst, "BUTTON", "Stand the bar up at the right edge (vertical)", bsAutoCheckBox|wsTabStop, 16, 346, 368, 22, idVertical)
ctlAutostart = makeControl(hw, inst, "BUTTON", "Start MirrorBar when I sign in", bsAutoCheckBox|wsTabStop, 16, 374, 368, 22, idAutostart)
ctlShowGM = makeControl(hw, inst, "BUTTON", "Show Google Messages on the bar", bsAutoCheckBox|wsTabStop, 16, 346, 368, 22, idShowGM)
ctlPanelFade = makeControl(hw, inst, "BUTTON", "Panels match the bar's transparency", bsAutoCheckBox|wsTabStop, 16, 374, 368, 22, idPanelFade)
ctlVertical = makeControl(hw, inst, "BUTTON", "Stand the bar up at the right edge (vertical)", bsAutoCheckBox|wsTabStop, 16, 402, 368, 22, idVertical)
ctlAutostart = makeControl(hw, inst, "BUTTON", "Start MirrorBar when I sign in", bsAutoCheckBox|wsTabStop, 16, 430, 368, 22, idAutostart)
makeControl(hw, inst, "BUTTON", "Reset position", bsPushButton|wsTabStop, 16, 414, 116, 28, idResetPos)
makeControl(hw, inst, "BUTTON", "Reset bar width", bsPushButton|wsTabStop, 140, 414, 116, 28, idResetWidth)
makeControl(hw, inst, "BUTTON", "Close", bsDefPushButton|wsTabStop, 292, 414, 92, 28, idClose)
makeControl(hw, inst, "BUTTON", "Reset position", bsPushButton|wsTabStop, 16, 470, 116, 28, idResetPos)
makeControl(hw, inst, "BUTTON", "Reset bar width", bsPushButton|wsTabStop, 140, 470, 116, 28, idResetWidth)
makeControl(hw, inst, "BUTTON", "Close", bsDefPushButton|wsTabStop, 292, 470, 92, 28, idClose)
hwndSettings = hw
settingsSync()
@@ -210,6 +214,8 @@ func settingsSync() {
pSendMessage.Call(ctlShowWeather, bmSetCheck, boolWP(showWeather), 0)
pSendMessage.Call(ctlShowNews, bmSetCheck, boolWP(showNews), 0)
pSendMessage.Call(ctlShowSys, bmSetCheck, boolWP(showSys), 0)
pSendMessage.Call(ctlShowGM, bmSetCheck, boolWP(showGM), 0)
pSendMessage.Call(ctlPanelFade, bmSetCheck, boolWP(flyMatchBar), 0)
pSendMessage.Call(ctlVertical, bmSetCheck, boolWP(vertical), 0)
pSendMessage.Call(ctlAutostart, bmSetCheck, boolWP(autostartEnabled()), 0)
@@ -289,6 +295,7 @@ func settingsCommand(id, note uintptr) {
}
saveColors()
redraw(hwndMain)
flyRefreshAll()
case idStyle:
if note != cbnSelChange {
return
@@ -309,6 +316,10 @@ func settingsCommand(id, note uintptr) {
setShowNews(checked(ctlShowNews))
case idShowSys:
setShowSys(checked(ctlShowSys))
case idShowGM:
setShowGM(checked(ctlShowGM))
case idPanelFade:
setFlyMatchBar(checked(ctlPanelFade))
case idVertical:
vertical = checked(ctlVertical)
saveOrient()
@@ -343,6 +354,7 @@ func settingsProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
bgAlpha = n
pSetWindowText.Call(ctlAlphaValue, uintptr(unsafe.Pointer(u16(strconv.Itoa(bgAlpha*100/255)+"%"))))
redraw(hwndMain)
flyRefreshAll()
}
if wparam&0xFFFF == tbEndTrack {
saveAlpha()
+7 -7
View File
@@ -66,7 +66,7 @@ func sysInit(inst uintptr) {
wc.Size = uint32(unsafe.Sizeof(wc))
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
sysHwnd, _, _ = pCreateWindowEx.Call(
wsExToolWindow|wsExTopmost|wsExNoActivate,
wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
uintptr(unsafe.Pointer(className)),
uintptr(unsafe.Pointer(u16(""))),
wsPopup,
@@ -91,7 +91,7 @@ func sysProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
case wmTimer:
if wparam == sysRefreshTimerID {
sysRows = sysGather() // uptime and memory move
pInvalidateRect.Call(sysHwnd, 0, 0)
flyRefresh(sysHwnd)
return 0
}
sysPoll()
@@ -137,6 +137,7 @@ func sysToggle() {
previewHide()
weatherHide() // one panel at a time
newsHide()
gmHide()
sysRows = sysGather()
sysShown = true
sysPrevBtn = true // ignore a button that is still held from the click that opened this
@@ -172,7 +173,7 @@ func sysPlace() {
}
lh := sysHead + float64(len(sysRows))*sysRow_ + sysFoot
flyPlace(sysHwnd, trayAnchor(traySys), px(sysW), px(lh))
pInvalidateRect.Call(sysHwnd, 0, 1)
flyRefresh(sysHwnd)
}
// sysRowAt is the line under a height in the panel (real pixels), or -1.
@@ -214,7 +215,7 @@ func sysPoll() {
changed = true
}
if changed {
pInvalidateRect.Call(sysHwnd, 0, 0)
flyRefresh(sysHwnd)
}
}
@@ -225,7 +226,7 @@ func sysCopy(text, what string) {
sysCopied = "Copy failed"
}
sysCopiedAt = time.Now()
pInvalidateRect.Call(sysHwnd, 0, 0)
flyRefresh(sysHwnd)
}
func sysClick(x, y int32) {
@@ -242,8 +243,7 @@ func sysClick(x, y int32) {
func sysDraw(hdc uintptr, W, H int32) {
u := px
fillRaw(hdc, rect{0, 0, W, H}, iconColor()) // the outline follows the tray icon color
fillRaw(hdc, rect{u(1), u(1), W - u(1), H - u(1)}, colBack)
flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
pad := u(14)
line := uintptr(dtLeft | dtVCenter | dtSingleLine | dtEndEllipsis)
+28 -2
View File
@@ -23,6 +23,7 @@ const (
trayWeather // added after the others so saved orders from older versions still mean the same thing
trayNews
traySys
trayGM // Google Messages
)
const (
@@ -51,6 +52,8 @@ const (
menuNewsZipID = 29
menuSysID = 34
menuSysCopyID = 35
menuGMID = 36
menuGMCloseID = 37
)
var (
@@ -128,6 +131,11 @@ func trayItemsAt(x, clientH int32) []trayItem {
continue
}
w = px(36)
case trayGM:
if !showGM {
continue
}
w = px(36)
case trayChevron:
w = px(28)
}
@@ -321,6 +329,8 @@ func drawTray(hdc uintptr, w, h int32) {
drawNewsIcon(hdc, it.r)
case traySys:
drawSysIcon(hdc, it.r)
case trayGM:
drawGMIcon(hdc, it.r)
}
}
}
@@ -605,6 +615,8 @@ func trayClick(kind int) {
newsToggle()
case traySys:
sysToggle()
case trayGM:
gmToggle()
case trayChevron:
// If the hidden icons are already showing, a second click closes them. Sending
// Win+B and Enter again would instead press Enter on the highlighted icon.
@@ -699,6 +711,10 @@ func addTrayMenu(add func(flags uintptr, id uintptr, text string), sep func(), k
add(0, menuSysID, "Show system stats")
add(0, menuSysCopyID, "Copy system stats")
sep()
case trayGM:
add(0, menuGMID, "Show Messages")
add(0, menuGMCloseID, "Close Messages (stop checking for texts)")
sep()
}
}
@@ -725,6 +741,13 @@ func handleTrayCommand(cmd uintptr) bool {
if !sysShown {
sysToggle()
}
case menuGMID:
if !gmShown {
gmToggle()
}
case menuGMCloseID:
gmClose()
redraw(hwndMain)
case menuSysCopyID:
if clipboardSet(sysText(sysGather())) {
sysCopied = "Copied everything"
@@ -747,7 +770,7 @@ func handleTrayCommand(cmd uintptr) bool {
// ---------- the right row can be rearranged too ----------
// trayOrder is the left to right order of the items to the right of center.
var trayOrder = []int{trayClock, trayWeather, trayNews, traySys, trayBattery, trayVolume, trayWifi, trayChevron}
var trayOrder = []int{trayClock, trayWeather, trayNews, traySys, trayGM, trayBattery, trayVolume, trayWifi, trayChevron}
var (
dragTray int // the tray item the mouse went down on, 0 for none
@@ -766,7 +789,7 @@ func loadTrayOrder() {
seen := map[int]bool{}
for _, p := range strings.Split(strings.TrimSpace(string(b)), ",") {
n, err := strconv.Atoi(strings.TrimSpace(p))
if err != nil || n < trayClock || n > traySys || seen[n] {
if err != nil || n < trayClock || n > trayGM || seen[n] {
return
}
seen[n] = true
@@ -794,6 +817,9 @@ func loadTrayOrder() {
if !seen[traySys] {
insertAfter(trayNews, traySys)
}
if !seen[trayGM] {
insertAfter(traySys, trayGM)
}
if len(order) == len(trayOrder) {
trayOrder = order
}