Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddfd5a375b | ||
|
|
ed8a7cf275 |
@@ -11,6 +11,7 @@ The real taskbar is hidden and a see-through pill takes its place. The pill is a
|
||||
- Right-click and choose "Switch to vertical" to stand it up and down against the right edge of the screen.
|
||||
- Right-click an app icon for the normal window options (Restore, Move, Size, Minimize, Maximize, Close) plus Open new window and Open file location.
|
||||
- Drag the app icons and the Windows logo along the left row to reorder them. The logo remembers its spot; the app order lasts until MirrorBar restarts.
|
||||
- Drag the clock, battery, volume, wifi and hidden-icons arrow along the right row to reorder them. That order is remembered.
|
||||
- Smooth, outline-free icons and text, even when the pill is see-through.
|
||||
- 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).
|
||||
- Background see-through level: Clear, Light, Medium or Solid.
|
||||
|
||||
@@ -1000,10 +1000,14 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
} else if idx := appIndexAt(hwnd, x); idx >= 0 {
|
||||
dragSeq, dragIsStart, dragStart, dragActive = seqOfApp(idx), false, x, false
|
||||
pSetCapture.Call(hwnd)
|
||||
} else if k := trayAt(hwnd, x); k != 0 {
|
||||
dragTray, dragTrayStart, dragTrayActive = k, x, false
|
||||
pSetCapture.Call(hwnd)
|
||||
}
|
||||
return 0
|
||||
case wmCaptureChanged:
|
||||
endIconDrag()
|
||||
dragTray, dragTrayActive = 0, false
|
||||
return 0
|
||||
case wmMouseMove:
|
||||
x := alongClient(lparam)
|
||||
@@ -1025,6 +1029,19 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
if dragTray != 0 {
|
||||
if !dragTrayActive && abs32(x-dragTrayStart) > px(5) {
|
||||
dragTrayActive = true
|
||||
}
|
||||
if dragTrayActive {
|
||||
if t := trayKindAt(hwnd, x); t != 0 && t != dragTray {
|
||||
moveTray(dragTray, t)
|
||||
}
|
||||
hoverStart, hoverApp, hoverTray = false, -1, dragTray
|
||||
redraw(hwnd)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
overStart := inStart(hwnd, x)
|
||||
overApp := appIndexAt(hwnd, x)
|
||||
overTray := trayAt(hwnd, x)
|
||||
@@ -1064,10 +1081,19 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
activateApp(idx)
|
||||
}
|
||||
redraw(hwnd)
|
||||
} else if dragTray != 0 {
|
||||
// A press on a tray item: a click if it never moved, otherwise the drag ends here.
|
||||
k, wasDrag := dragTray, dragTrayActive
|
||||
dragTray, dragTrayActive = 0, false
|
||||
pReleaseCapture.Call()
|
||||
if wasDrag {
|
||||
saveTrayOrder()
|
||||
} else {
|
||||
trayClick(k)
|
||||
}
|
||||
redraw(hwnd)
|
||||
} else if inStart(hwnd, x) {
|
||||
tapWinKey()
|
||||
} else if k := trayAt(hwnd, x); k != 0 {
|
||||
trayClick(k)
|
||||
}
|
||||
return 0
|
||||
case wmRButtonUp:
|
||||
@@ -1176,6 +1202,7 @@ func main() {
|
||||
loadAlpha()
|
||||
loadPos()
|
||||
loadStartSlot()
|
||||
loadTrayOrder()
|
||||
loadOrient()
|
||||
|
||||
hdc, _, _ := pGetDC.Call(0)
|
||||
|
||||
@@ -5,6 +5,8 @@ package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
@@ -85,17 +87,24 @@ type trayItem struct {
|
||||
func trayItems(clientW, clientH int32) []trayItem {
|
||||
x := clientW / 2
|
||||
var out []trayItem
|
||||
add := func(kind int, w int32) {
|
||||
for _, kind := range trayOrder {
|
||||
var w int32
|
||||
switch kind {
|
||||
case trayClock:
|
||||
w = clockWidth()
|
||||
case trayBattery:
|
||||
if battPct < 0 {
|
||||
continue // this PC has no battery
|
||||
}
|
||||
w = px(36)
|
||||
case trayVolume, trayWifi:
|
||||
w = px(36)
|
||||
case trayChevron:
|
||||
w = px(28)
|
||||
}
|
||||
out = append(out, trayItem{kind, rect{x, 0, x + w, clientH}})
|
||||
x += w
|
||||
}
|
||||
add(trayClock, clockWidth())
|
||||
if battPct >= 0 {
|
||||
add(trayBattery, px(36))
|
||||
}
|
||||
add(trayVolume, px(36))
|
||||
add(trayWifi, px(36))
|
||||
add(trayChevron, px(28))
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -662,3 +671,85 @@ func handleTrayCommand(cmd uintptr) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ---------- 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, trayBattery, trayVolume, trayWifi, trayChevron}
|
||||
|
||||
var (
|
||||
dragTray int // the tray item the mouse went down on, 0 for none
|
||||
dragTrayStart int32 // where along the bar the mouse went down
|
||||
dragTrayActive bool // true once the mouse has moved far enough to count as a drag
|
||||
)
|
||||
|
||||
func trayOrderFile() string { return filepath.Join(dataDir(), "trayorder.txt") }
|
||||
|
||||
func loadTrayOrder() {
|
||||
b, err := os.ReadFile(trayOrderFile())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var order []int
|
||||
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 > trayChevron || seen[n] {
|
||||
return
|
||||
}
|
||||
seen[n] = true
|
||||
order = append(order, n)
|
||||
}
|
||||
if len(order) == len(trayOrder) {
|
||||
trayOrder = order
|
||||
}
|
||||
}
|
||||
|
||||
func saveTrayOrder() {
|
||||
parts := make([]string, len(trayOrder))
|
||||
for i, k := range trayOrder {
|
||||
parts[i] = strconv.Itoa(k)
|
||||
}
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
_ = os.WriteFile(trayOrderFile(), []byte(strings.Join(parts, ",")), 0o644)
|
||||
}
|
||||
|
||||
// trayKindAt is the tray item under a spot along the bar, clamped to the ends
|
||||
// of the right row.
|
||||
func trayKindAt(hwnd uintptr, x int32) int {
|
||||
w, h := clientSize(hwnd)
|
||||
items := trayItems(w, h)
|
||||
if len(items) == 0 {
|
||||
return 0
|
||||
}
|
||||
if x < items[0].r.Left {
|
||||
return items[0].kind
|
||||
}
|
||||
if x >= items[len(items)-1].r.Right {
|
||||
return items[len(items)-1].kind
|
||||
}
|
||||
for _, it := range items {
|
||||
if x >= it.r.Left && x < it.r.Right {
|
||||
return it.kind
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// moveTray puts one item where another one is, shifting the rest.
|
||||
func moveTray(kind, target int) {
|
||||
from, to := -1, -1
|
||||
for i, k := range trayOrder {
|
||||
if k == kind {
|
||||
from = i
|
||||
}
|
||||
if k == target {
|
||||
to = i
|
||||
}
|
||||
}
|
||||
if from < 0 || to < 0 || from == to {
|
||||
return
|
||||
}
|
||||
rest := append(append([]int{}, trayOrder[:from]...), trayOrder[from+1:]...)
|
||||
trayOrder = append(append(append([]int{}, rest[:to]...), kind), rest[to:]...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user