Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddfd5a375b | ||
|
|
ed8a7cf275 | ||
|
|
cab30fb5d3 | ||
|
|
171afe6605 |
@@ -10,6 +10,8 @@ The real taskbar is hidden and a see-through pill takes its place. The pill is a
|
|||||||
- Drag it anywhere by its background. It remembers where you put it. Right-click and choose "Reset position to bottom center" to send it home.
|
- Drag it anywhere by its background. It remembers where you put it. Right-click and choose "Reset position to bottom center" to send it home.
|
||||||
- Right-click and choose "Switch to vertical" to stand it up and down against the right edge of the screen.
|
- 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.
|
- 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.
|
- 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).
|
- 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.
|
- Background see-through level: Clear, Light, Medium or Solid.
|
||||||
|
|||||||
@@ -634,29 +634,17 @@ func positionBar(hwnd uintptr) {
|
|||||||
// too many to fit, the buttons shrink to a minimum width and the oldest run
|
// too many to fit, the buttons shrink to a minimum width and the oldest run
|
||||||
// off the left edge.
|
// off the left edge.
|
||||||
func appRects(clientW, clientH int32) []rect {
|
func appRects(clientW, clientH int32) []rect {
|
||||||
n := int32(len(apps))
|
if len(apps) == 0 {
|
||||||
if n == 0 {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
right := clientW/2 - startWidth()
|
row := rowLayout(clientW, clientH)
|
||||||
avail := right - px(8)
|
rects := make([]rect, len(apps))
|
||||||
bw := px(36)
|
for i := range rects {
|
||||||
if avail/n < bw {
|
rects[i] = row[seqOfApp(i)]
|
||||||
bw = avail / n
|
|
||||||
}
|
|
||||||
if bw < px(24) {
|
|
||||||
bw = px(24)
|
|
||||||
}
|
|
||||||
rects := make([]rect, n)
|
|
||||||
for i := int32(0); i < n; i++ {
|
|
||||||
r := right - i*bw
|
|
||||||
rects[i] = rect{r - bw, 0, r, clientH}
|
|
||||||
}
|
}
|
||||||
return rects
|
return rects
|
||||||
}
|
}
|
||||||
|
|
||||||
// clientSize is the size of the bar in the horizontal layout (length, thickness),
|
|
||||||
// whichever way the real window is turned.
|
|
||||||
func clientSize(hwnd uintptr) (int32, int32) {
|
func clientSize(hwnd uintptr) (int32, int32) {
|
||||||
var rc rect
|
var rc rect
|
||||||
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&rc)))
|
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&rc)))
|
||||||
@@ -793,9 +781,9 @@ func premul(c uint32, a uint32) uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func inStart(hwnd uintptr, x int32) bool {
|
func inStart(hwnd uintptr, x int32) bool {
|
||||||
w, _ := clientSize(hwnd)
|
w, h := clientSize(hwnd)
|
||||||
cx := w / 2
|
r := startRect(w, h)
|
||||||
return x >= cx-startWidth() && x < cx
|
return x >= r.Left && x < r.Right
|
||||||
}
|
}
|
||||||
|
|
||||||
func tapWinKey() {
|
func tapWinKey() {
|
||||||
@@ -1004,8 +992,56 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
pDestroyWindow.Call(hwnd)
|
pDestroyWindow.Call(hwnd)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
|
case wmLButtonDown:
|
||||||
|
x := alongClient(lparam)
|
||||||
|
if inStart(hwnd, x) {
|
||||||
|
dragSeq, dragIsStart, dragStart, dragActive = slot(), true, x, false
|
||||||
|
pSetCapture.Call(hwnd)
|
||||||
|
} 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:
|
case wmMouseMove:
|
||||||
x := alongClient(lparam)
|
x := alongClient(lparam)
|
||||||
|
if dragSeq >= 0 && dragSeq <= len(apps) {
|
||||||
|
if !dragActive && abs32(x-dragStart) > px(5) {
|
||||||
|
dragActive = true
|
||||||
|
}
|
||||||
|
if dragActive {
|
||||||
|
if t := seqAt(hwnd, x); t >= 0 && t != dragSeq {
|
||||||
|
moveSeq(dragSeq, t)
|
||||||
|
dragSeq = t
|
||||||
|
}
|
||||||
|
hoverStart = dragIsStart
|
||||||
|
hoverApp = -1
|
||||||
|
if !dragIsStart {
|
||||||
|
hoverApp = appOfSeq(dragSeq)
|
||||||
|
}
|
||||||
|
redraw(hwnd)
|
||||||
|
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)
|
overStart := inStart(hwnd, x)
|
||||||
overApp := appIndexAt(hwnd, x)
|
overApp := appIndexAt(hwnd, x)
|
||||||
overTray := trayAt(hwnd, x)
|
overTray := trayAt(hwnd, x)
|
||||||
@@ -1032,14 +1068,33 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
return 0
|
return 0
|
||||||
case wmLButtonUp:
|
case wmLButtonUp:
|
||||||
x := alongClient(lparam)
|
x := alongClient(lparam)
|
||||||
if inStart(hwnd, x) {
|
if dragSeq >= 0 {
|
||||||
|
// A press on the Start button or an app icon: a click if it never moved, otherwise the drag ends here.
|
||||||
|
seq, wasStart, wasDrag := dragSeq, dragIsStart, dragActive
|
||||||
|
endIconDrag()
|
||||||
|
pReleaseCapture.Call()
|
||||||
|
if wasDrag {
|
||||||
|
saveStartSlot()
|
||||||
|
} else if wasStart {
|
||||||
tapWinKey()
|
tapWinKey()
|
||||||
} else if idx := appIndexAt(hwnd, x); idx >= 0 {
|
} else if idx := appOfSeq(seq); idx >= 0 && idx < len(apps) {
|
||||||
activateApp(idx)
|
activateApp(idx)
|
||||||
|
}
|
||||||
redraw(hwnd)
|
redraw(hwnd)
|
||||||
} else if k := trayAt(hwnd, x); k != 0 {
|
} 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)
|
trayClick(k)
|
||||||
}
|
}
|
||||||
|
redraw(hwnd)
|
||||||
|
} else if inStart(hwnd, x) {
|
||||||
|
tapWinKey()
|
||||||
|
}
|
||||||
return 0
|
return 0
|
||||||
case wmRButtonUp:
|
case wmRButtonUp:
|
||||||
x := alongClient(lparam)
|
x := alongClient(lparam)
|
||||||
@@ -1146,6 +1201,8 @@ func main() {
|
|||||||
|
|
||||||
loadAlpha()
|
loadAlpha()
|
||||||
loadPos()
|
loadPos()
|
||||||
|
loadStartSlot()
|
||||||
|
loadTrayOrder()
|
||||||
loadOrient()
|
loadOrient()
|
||||||
|
|
||||||
hdc, _, _ := pGetDC.Call(0)
|
hdc, _, _ := pGetDC.Call(0)
|
||||||
|
|||||||
@@ -180,3 +180,146 @@ func resetPos(hwnd uintptr) {
|
|||||||
}
|
}
|
||||||
positionBar(hwnd)
|
positionBar(hwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- the left row: Start button and app icons, all draggable ----------
|
||||||
|
|
||||||
|
var (
|
||||||
|
pSetCapture = user32.NewProc("SetCapture")
|
||||||
|
pReleaseCapture = user32.NewProc("ReleaseCapture")
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
wmLButtonDown = 0x0201
|
||||||
|
wmCaptureChanged = 0x0215
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
startSlot int // where the Start button sits in the left row (0 is against the center line)
|
||||||
|
dragSeq = -1 // row position of the item the mouse went down on, -1 for none
|
||||||
|
dragIsStart bool // the item being pressed is the Start button
|
||||||
|
dragStart int32 // where along the bar the mouse went down
|
||||||
|
dragActive bool // true once the mouse has moved far enough to count as a drag
|
||||||
|
)
|
||||||
|
|
||||||
|
func startSlotFile() string { return filepath.Join(dataDir(), "startslot.txt") }
|
||||||
|
|
||||||
|
func loadStartSlot() {
|
||||||
|
b, err := os.ReadFile(startSlotFile())
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if n, err := strconv.Atoi(strings.TrimSpace(string(b))); err == nil && n >= 0 {
|
||||||
|
startSlot = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveStartSlot() {
|
||||||
|
_ = os.MkdirAll(dataDir(), 0o755)
|
||||||
|
_ = os.WriteFile(startSlotFile(), []byte(strconv.Itoa(startSlot)), 0o644)
|
||||||
|
}
|
||||||
|
|
||||||
|
func endIconDrag() {
|
||||||
|
dragSeq = -1
|
||||||
|
dragIsStart = false
|
||||||
|
dragActive = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// slot is the Start button's position, kept within the row.
|
||||||
|
func slot() int {
|
||||||
|
return max(0, min(startSlot, len(apps)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// The row is the Start button plus every app, from the center line leftward.
|
||||||
|
// A "row position" counts those items; app i sits at seqOfApp(i).
|
||||||
|
func seqOfApp(i int) int {
|
||||||
|
if i < slot() {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
return i + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func appOfSeq(t int) int {
|
||||||
|
if t < slot() {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
return t - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// rowLayout gives the rectangle of every row position (Start included).
|
||||||
|
func rowLayout(clientW, clientH int32) []rect {
|
||||||
|
n := int32(len(apps))
|
||||||
|
sl := int32(slot())
|
||||||
|
cx := clientW / 2
|
||||||
|
bw := px(36)
|
||||||
|
if n > 0 {
|
||||||
|
avail := cx - startWidth() - px(8)
|
||||||
|
if avail/n < bw {
|
||||||
|
bw = avail / n
|
||||||
|
}
|
||||||
|
if bw < px(24) {
|
||||||
|
bw = px(24)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rects := make([]rect, n+1)
|
||||||
|
x := cx
|
||||||
|
for k := int32(0); k <= n; k++ {
|
||||||
|
wd := bw
|
||||||
|
if k == sl {
|
||||||
|
wd = startWidth()
|
||||||
|
}
|
||||||
|
rects[k] = rect{x - wd, 0, x, clientH}
|
||||||
|
x -= wd
|
||||||
|
}
|
||||||
|
return rects
|
||||||
|
}
|
||||||
|
|
||||||
|
func startRect(clientW, clientH int32) rect {
|
||||||
|
return rowLayout(clientW, clientH)[slot()]
|
||||||
|
}
|
||||||
|
|
||||||
|
// seqAt is the row position under a spot along the bar, clamped to the ends.
|
||||||
|
func seqAt(hwnd uintptr, x int32) int {
|
||||||
|
w, h := clientSize(hwnd)
|
||||||
|
rects := rowLayout(w, h)
|
||||||
|
if x >= rects[0].Right {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if x < rects[len(rects)-1].Left {
|
||||||
|
return len(rects) - 1
|
||||||
|
}
|
||||||
|
for k, r := range rects {
|
||||||
|
if x >= r.Left && x < r.Right {
|
||||||
|
return k
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
// moveSeq moves one item of the row to another position, shifting the rest.
|
||||||
|
func moveSeq(from, to int) {
|
||||||
|
n := len(apps)
|
||||||
|
if from == to || from < 0 || to < 0 || from > n || to > n {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sl := slot()
|
||||||
|
seq := make([]int, 0, n+1) // -1 stands for the Start button, otherwise an app index
|
||||||
|
for k := 0; k <= n; k++ {
|
||||||
|
if k == sl {
|
||||||
|
seq = append(seq, -1)
|
||||||
|
} else {
|
||||||
|
seq = append(seq, appOfSeq(k))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v := seq[from]
|
||||||
|
rest := append(append([]int{}, seq[:from]...), seq[from+1:]...)
|
||||||
|
seq = append(append(append([]int{}, rest[:to]...), v), rest[to:]...)
|
||||||
|
next := make([]appWin, 0, n)
|
||||||
|
for k, a := range seq {
|
||||||
|
if a == -1 {
|
||||||
|
startSlot = k
|
||||||
|
} else {
|
||||||
|
next = append(next, apps[a])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
apps = next
|
||||||
|
}
|
||||||
|
|||||||
@@ -172,8 +172,7 @@ func renderLayer(screen uintptr, w, h int32, fills, fg bool, base uintptr) []uin
|
|||||||
defer pSelectObject.Call(mem, old)
|
defer pSelectObject.Call(mem, old)
|
||||||
|
|
||||||
fillRaw(mem, rect{0, 0, w, h}, base)
|
fillRaw(mem, rect{0, 0, w, h}, base)
|
||||||
cx := w / 2
|
sr := startRect(w, h)
|
||||||
sr := rect{cx - startWidth(), 0, cx, h}
|
|
||||||
if hoverStart {
|
if hoverStart {
|
||||||
fill(mem, sr, rgb(58, 58, 68))
|
fill(mem, sr, rgb(58, 58, 68))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
@@ -85,17 +87,24 @@ type trayItem struct {
|
|||||||
func trayItems(clientW, clientH int32) []trayItem {
|
func trayItems(clientW, clientH int32) []trayItem {
|
||||||
x := clientW / 2
|
x := clientW / 2
|
||||||
var out []trayItem
|
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}})
|
out = append(out, trayItem{kind, rect{x, 0, x + w, clientH}})
|
||||||
x += w
|
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
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,3 +671,85 @@ func handleTrayCommand(cmd uintptr) bool {
|
|||||||
}
|
}
|
||||||
return true
|
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