Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c94e74451f | ||
|
|
807befdd53 | ||
|
|
7e5cf13afe | ||
|
|
9e6b24268f | ||
|
|
ecde38f9e8 |
@@ -8,6 +8,7 @@ The real taskbar is hidden and a see-through pill takes its place. The pill is a
|
||||
|
||||
- Transparent pill that is only as wide as what is in it, centered on the screen with a few pixels of space under it.
|
||||
- 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.
|
||||
- Pull the far left end of the pill (the cursor turns into a double arrow) to shrink the empty space on the left. The center line stays put, and the left side stretches back out as you open more apps. Right-click and choose "Reset bar width" to go back to the mirrored look.
|
||||
- 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. MirrorBar remembers the order of your apps and the logo's spot.
|
||||
@@ -15,8 +16,11 @@ The real taskbar is hidden and a see-through pill takes its place. The pill is a
|
||||
- Rest the mouse on an app icon for a moment and a live preview of that window pops up beside the bar (minimized windows show their icon instead). Click the preview to switch to that window.
|
||||
- Right-click an app icon and choose "Pin to MirrorBar" to keep it on the bar. A pinned app that isn't running shows as a launcher: click it to start the program, and when its window opens it takes that spot. Pinning works for normal programs; Store apps can't be pinned.
|
||||
- "Open notification center" is in the right-click menu.
|
||||
- Drag files from Explorer onto an app icon and that program opens them, running or pinned.
|
||||
- "MirrorBar settings..." in the right-click menu opens one window for background opacity, the three colors, icon style, vertical mode, start with Windows, and resetting the position and width. Changes apply as you make them.
|
||||
- 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).
|
||||
- "Icon style" in the right-click menu: colorized or grayscale. It applies to the app icons and to the logo, clock and tray icons.
|
||||
- Background see-through level: Clear, Light, Medium or Solid.
|
||||
- "Start MirrorBar when I sign in" in the right-click menu.
|
||||
- Scroll over the speaker to change the volume. Click the clock, battery, volume or wifi for the matching Windows panel.
|
||||
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
package main
|
||||
|
||||
// Resizing the left half: the center line (where the Start button and the
|
||||
// clock meet) stays put, but the two halves no longer have to be the same
|
||||
// length. Pull the far left end of the pill (the top end when it stands up) and
|
||||
// the empty space shrinks, down to where the buttons touch. Open more apps and
|
||||
// the left half stretches back out to fit them.
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
menuResetWidthID = 44
|
||||
|
||||
wmSetCursor = 0x0020
|
||||
idcSizeWE = 32644
|
||||
idcSizeNS = 32645
|
||||
)
|
||||
|
||||
var (
|
||||
pSetCursor = user32.NewProc("SetCursor")
|
||||
|
||||
leftPref int32 // 0: mirror the right half (the original look), -1: hug the buttons, else the chosen length
|
||||
resizing bool
|
||||
resizeFrom int32 // where the cursor was along the bar when the drag began
|
||||
resizeLen int32 // the length of the left half when the drag began
|
||||
)
|
||||
|
||||
func widthFile() string { return filepath.Join(dataDir(), "leftwidth.txt") }
|
||||
|
||||
func loadLeftPref() {
|
||||
b, err := os.ReadFile(widthFile())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
switch s := strings.TrimSpace(string(b)); s {
|
||||
case "tight":
|
||||
leftPref = -1
|
||||
case "", "mirror":
|
||||
leftPref = 0
|
||||
default:
|
||||
if n, err := strconv.Atoi(s); err == nil && n > 0 {
|
||||
leftPref = int32(n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func saveLeftPref() {
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
s := "mirror"
|
||||
switch {
|
||||
case leftPref < 0:
|
||||
s = "tight"
|
||||
case leftPref > 0:
|
||||
s = strconv.Itoa(int(leftPref))
|
||||
}
|
||||
_ = os.WriteFile(widthFile(), []byte(s), 0o644)
|
||||
}
|
||||
|
||||
// halfLimit is the longest either half may be.
|
||||
func halfLimit() int32 {
|
||||
sw, _ := screenSize()
|
||||
return sw/2 - px(4)
|
||||
}
|
||||
|
||||
// rightHalf is the length of the right half: the tray items plus a little padding.
|
||||
func rightHalf() int32 {
|
||||
items := trayItemsAt(0, 1)
|
||||
return min(items[len(items)-1].r.Right+px(16), halfLimit())
|
||||
}
|
||||
|
||||
// leftContent is the least the left half needs: Start, every app, and padding.
|
||||
func leftContent() int32 {
|
||||
return startWidth() + int32(len(apps))*px(36) + px(16)
|
||||
}
|
||||
|
||||
// leftHalf is the length of the left half.
|
||||
func leftHalf() int32 {
|
||||
lc := leftContent()
|
||||
var h int32
|
||||
switch {
|
||||
case leftPref < 0:
|
||||
h = lc
|
||||
case leftPref > 0:
|
||||
h = max(lc, leftPref)
|
||||
default:
|
||||
h = max(lc, rightHalf())
|
||||
}
|
||||
return min(h, halfLimit())
|
||||
}
|
||||
|
||||
// axisX is where the center line is, along the bar, measured from its start.
|
||||
func axisX(clientW int32) int32 { return leftHalf() }
|
||||
|
||||
// ---------- the drag handle ----------
|
||||
|
||||
func edgeZone(along int32) bool { return along >= 0 && along < px(10) }
|
||||
|
||||
func cursorAlong() int32 {
|
||||
var p point
|
||||
pGetCursorPos.Call(uintptr(unsafe.Pointer(&p)))
|
||||
if vertical {
|
||||
return p.Y
|
||||
}
|
||||
return p.X
|
||||
}
|
||||
|
||||
// overEdge reports whether the cursor is on the draggable far end of the pill.
|
||||
func overEdge(hwnd uintptr) bool {
|
||||
var p point
|
||||
pGetCursorPos.Call(uintptr(unsafe.Pointer(&p)))
|
||||
var wr rect
|
||||
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||
if p.X < wr.Left || p.X >= wr.Right || p.Y < wr.Top || p.Y >= wr.Bottom {
|
||||
return false
|
||||
}
|
||||
if vertical {
|
||||
return edgeZone(p.Y - wr.Top)
|
||||
}
|
||||
return edgeZone(p.X - wr.Left)
|
||||
}
|
||||
|
||||
func beginResize(hwnd uintptr) {
|
||||
resizing = true
|
||||
resizeFrom = cursorAlong()
|
||||
resizeLen = leftHalf()
|
||||
pSetCapture.Call(hwnd)
|
||||
}
|
||||
|
||||
func moveResize(hwnd uintptr) {
|
||||
newLen := resizeLen - (cursorAlong() - resizeFrom)
|
||||
if newLen <= leftContent()+px(10) {
|
||||
leftPref = -1 // pulled all the way in: hug the buttons
|
||||
} else {
|
||||
leftPref = min(newLen, halfLimit())
|
||||
}
|
||||
redraw(hwnd)
|
||||
}
|
||||
|
||||
func endResize(hwnd uintptr) {
|
||||
resizing = false
|
||||
pReleaseCapture.Call()
|
||||
saveLeftPref()
|
||||
redraw(hwnd)
|
||||
}
|
||||
|
||||
func sizeCursor() uintptr {
|
||||
id := uintptr(idcSizeWE)
|
||||
if vertical {
|
||||
id = idcSizeNS
|
||||
}
|
||||
c, _, _ := pLoadCursor.Call(0, id)
|
||||
return c
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package main
|
||||
|
||||
// Dropping files on an app icon: drag a document (or several) from Explorer
|
||||
// onto an icon on the bar and that program opens them, like the real taskbar
|
||||
// does. Works for running programs and for pinned ones that are closed.
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const wmDropFiles = 0x0233
|
||||
|
||||
var (
|
||||
pDragAcceptFiles = shell32.NewProc("DragAcceptFiles")
|
||||
pDragQueryFile = shell32.NewProc("DragQueryFileW")
|
||||
pDragQueryPoint = shell32.NewProc("DragQueryPoint")
|
||||
pDragFinish = shell32.NewProc("DragFinish")
|
||||
)
|
||||
|
||||
func enableFileDrop(hwnd uintptr) { pDragAcceptFiles.Call(hwnd, 1) }
|
||||
|
||||
// dropFiles handles WM_DROPFILES: work out which icon the files landed on and
|
||||
// start that program with the file names.
|
||||
func dropFiles(hwnd, hdrop uintptr) {
|
||||
defer pDragFinish.Call(hdrop)
|
||||
|
||||
var pt point
|
||||
pDragQueryPoint.Call(hdrop, uintptr(unsafe.Pointer(&pt)))
|
||||
x := pt.X
|
||||
if vertical {
|
||||
x = pt.Y
|
||||
}
|
||||
idx := appIndexAt(hwnd, x)
|
||||
if idx < 0 || idx >= len(apps) {
|
||||
return // dropped on the Start button, the clock or empty bar
|
||||
}
|
||||
exe := apps[idx].exe
|
||||
if exe == "" && apps[idx].hwnd != 0 {
|
||||
exe = windowExePath(apps[idx].hwnd)
|
||||
}
|
||||
if exe == "" {
|
||||
return // Store apps can't be started with a file this way
|
||||
}
|
||||
|
||||
count, _, _ := pDragQueryFile.Call(hdrop, 0xFFFFFFFF, 0, 0)
|
||||
var params []string
|
||||
total := 0
|
||||
for i := uintptr(0); i < count; i++ {
|
||||
n, _, _ := pDragQueryFile.Call(hdrop, i, 0, 0)
|
||||
if n == 0 {
|
||||
continue
|
||||
}
|
||||
buf := make([]uint16, n+1)
|
||||
pDragQueryFile.Call(hdrop, i, uintptr(unsafe.Pointer(&buf[0])), n+1)
|
||||
p := `"` + syscall.UTF16ToString(buf) + `"`
|
||||
if total+len(p) > 30000 { // a command line can't be longer than about 32,000 characters
|
||||
break
|
||||
}
|
||||
total += len(p) + 1
|
||||
params = append(params, p)
|
||||
}
|
||||
if len(params) == 0 {
|
||||
return
|
||||
}
|
||||
shellOpen(exe, strings.Join(params, " "))
|
||||
}
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
package main
|
||||
|
||||
// Icon style: colorized or grayscale. It applies to the app
|
||||
// icons (their pixels are filtered) and to everything MirrorBar draws itself
|
||||
// (the logo, clock, battery, volume, wifi and arrow colors).
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
modeColor = 0
|
||||
modeGray = 1
|
||||
|
||||
menuStyleBase = 160
|
||||
)
|
||||
|
||||
var (
|
||||
pGetIconInfo = user32.NewProc("GetIconInfo")
|
||||
pCreateIconIndirect = user32.NewProc("CreateIconIndirect")
|
||||
pDestroyIcon = user32.NewProc("DestroyIcon")
|
||||
pGetObject = gdi32.NewProc("GetObjectW")
|
||||
pGetDIBits = gdi32.NewProc("GetDIBits")
|
||||
|
||||
iconMode = modeColor
|
||||
styleCache = map[styleKey]uintptr{}
|
||||
)
|
||||
|
||||
type styleKey struct {
|
||||
icon uintptr
|
||||
mode int
|
||||
}
|
||||
|
||||
type iconInfo struct {
|
||||
FIcon int32
|
||||
XHot uint32
|
||||
YHot uint32
|
||||
Mask uintptr
|
||||
Color uintptr
|
||||
}
|
||||
|
||||
type bitmapObj struct {
|
||||
Type int32
|
||||
Width int32
|
||||
Height int32
|
||||
WidthBytes int32
|
||||
Planes uint16
|
||||
BitsPixel uint16
|
||||
Bits uintptr
|
||||
}
|
||||
|
||||
var styleNames = []string{"Colorized", "Grayscale"}
|
||||
|
||||
func styleFile() string { return filepath.Join(dataDir(), "iconstyle.txt") }
|
||||
|
||||
func loadIconMode() {
|
||||
b, err := os.ReadFile(styleFile())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if n, err := strconv.Atoi(strings.TrimSpace(string(b))); err == nil && n >= 0 && n < len(styleNames) {
|
||||
iconMode = n
|
||||
}
|
||||
}
|
||||
|
||||
func saveIconMode() {
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
_ = os.WriteFile(styleFile(), []byte(strconv.Itoa(iconMode)), 0o644)
|
||||
}
|
||||
|
||||
// styleCacheClear throws away the filtered copies of icons.
|
||||
func styleCacheClear() {
|
||||
for _, v := range styleCache {
|
||||
if v != 0 {
|
||||
pDestroyIcon.Call(v)
|
||||
}
|
||||
}
|
||||
styleCache = map[styleKey]uintptr{}
|
||||
}
|
||||
|
||||
// styledIcon is the icon as it should be drawn in the current style.
|
||||
func styledIcon(ic uintptr) uintptr {
|
||||
if ic == 0 || iconMode == modeColor {
|
||||
return ic
|
||||
}
|
||||
k := styleKey{ic, iconMode}
|
||||
if v, ok := styleCache[k]; ok {
|
||||
if v != 0 {
|
||||
return v
|
||||
}
|
||||
return ic
|
||||
}
|
||||
v := makeStyledIcon(ic, iconMode)
|
||||
if len(styleCache) > 300 {
|
||||
styleCacheClear()
|
||||
}
|
||||
styleCache[k] = v
|
||||
if v == 0 {
|
||||
return ic
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// makeStyledIcon returns a filtered copy of an icon, or 0 if it can't be done
|
||||
// (the original is then drawn as it is).
|
||||
func makeStyledIcon(ic uintptr, mode int) (result uintptr) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
result = 0
|
||||
}
|
||||
}()
|
||||
var ii iconInfo
|
||||
r, _, _ := pGetIconInfo.Call(ic, uintptr(unsafe.Pointer(&ii)))
|
||||
if r == 0 {
|
||||
return 0
|
||||
}
|
||||
defer func() {
|
||||
if ii.Mask != 0 {
|
||||
pDeleteObject.Call(ii.Mask)
|
||||
}
|
||||
if ii.Color != 0 {
|
||||
pDeleteObject.Call(ii.Color)
|
||||
}
|
||||
}()
|
||||
if ii.Color == 0 {
|
||||
return 0 // a two-color icon, leave it
|
||||
}
|
||||
var bm bitmapObj
|
||||
pGetObject.Call(ii.Color, unsafe.Sizeof(bm), uintptr(unsafe.Pointer(&bm)))
|
||||
w, h := int(bm.Width), int(bm.Height)
|
||||
if w <= 0 || h <= 0 || w > 512 || h > 512 {
|
||||
return 0
|
||||
}
|
||||
|
||||
hdc, _, _ := pGetDC.Call(0)
|
||||
defer pReleaseDC.Call(0, hdc)
|
||||
bmi := bitmapInfoHeader{Width: int32(w), Height: int32(-h), Planes: 1, BitCount: 32}
|
||||
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
||||
pix := make([]uint32, w*h)
|
||||
n, _, _ := pGetDIBits.Call(hdc, ii.Color, 0, uintptr(h), uintptr(unsafe.Pointer(&pix[0])),
|
||||
uintptr(unsafe.Pointer(&bmi)), 0)
|
||||
if n == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
for i, p := range pix {
|
||||
a := p >> 24
|
||||
cr, cg, cb := p>>16&0xFF, p>>8&0xFF, p&0xFF
|
||||
y := (cr*299 + cg*587 + cb*114) / 1000 // works on premultiplied pixels too
|
||||
pix[i] = a<<24 | y<<16 | y<<8 | y
|
||||
}
|
||||
|
||||
var bits unsafe.Pointer
|
||||
hb, _, _ := pCreateDIBSection.Call(hdc, uintptr(unsafe.Pointer(&bmi)), 0, uintptr(unsafe.Pointer(&bits)), 0, 0)
|
||||
if hb == 0 || bits == nil {
|
||||
return 0
|
||||
}
|
||||
copy(unsafe.Slice((*uint32)(bits), w*h), pix)
|
||||
ni := iconInfo{FIcon: 1, Mask: ii.Mask, Color: hb}
|
||||
nh, _, _ := pCreateIconIndirect.Call(uintptr(unsafe.Pointer(&ni)))
|
||||
pDeleteObject.Call(hb)
|
||||
return nh
|
||||
}
|
||||
|
||||
// styleColor applies the style to a color MirrorBar draws itself.
|
||||
func styleColor(r, g, b int) (int, int, int) {
|
||||
if iconMode == modeGray {
|
||||
y := (r*299 + g*587 + b*114) / 1000
|
||||
return y, y, y
|
||||
}
|
||||
return r, g, b
|
||||
}
|
||||
|
||||
func addStyleMenu(menu uintptr) {
|
||||
sub, _, _ := pCreatePopupMenu.Call()
|
||||
for i, name := range styleNames {
|
||||
var flags uintptr
|
||||
if i == iconMode {
|
||||
flags = mfChecked
|
||||
}
|
||||
pAppendMenu.Call(sub, flags, uintptr(menuStyleBase+i), uintptr(unsafe.Pointer(u16(name))))
|
||||
}
|
||||
pAppendMenu.Call(menu, mfPopup, sub, uintptr(unsafe.Pointer(u16("Icon style"))))
|
||||
}
|
||||
|
||||
func handleStyleCommand(cmd uintptr) bool {
|
||||
if cmd < menuStyleBase || cmd >= menuStyleBase+uintptr(len(styleNames)) {
|
||||
return false
|
||||
}
|
||||
iconMode = int(cmd - menuStyleBase)
|
||||
saveIconMode()
|
||||
styleCacheClear()
|
||||
return true
|
||||
}
|
||||
@@ -551,18 +551,11 @@ func screenSize() (int32, int32) {
|
||||
return int32(w), int32(h)
|
||||
}
|
||||
|
||||
// pillWidth is the width the bar needs: the wider of the two halves, doubled so
|
||||
// the bar stays a mirror image around the center, plus a little padding.
|
||||
// pillWidth is the width the bar needs: the left half plus the right half. By
|
||||
// default the left half is as long as the right one (a mirror image); pulling
|
||||
// the far left end changes that (see barwidth.go).
|
||||
func pillWidth() int32 {
|
||||
sw, _ := screenSize()
|
||||
left := startWidth() + int32(len(apps))*px(36)
|
||||
items := trayItems(0, 1)
|
||||
right := items[len(items)-1].r.Right
|
||||
half := max(left, right) + px(16)
|
||||
if limit := sw/2 - px(4); half > limit {
|
||||
half = limit
|
||||
}
|
||||
return half * 2
|
||||
return leftHalf() + rightHalf()
|
||||
}
|
||||
|
||||
// barGap is the space left under the pill so it stands off the screen edge.
|
||||
@@ -724,7 +717,7 @@ func drawAppGlyph(hdc uintptr, r rect, a appWin) {
|
||||
isz := px(16) // the small taskbar icon size
|
||||
if a.icon != 0 {
|
||||
cx, cy := center(r)
|
||||
pDrawIconEx.Call(hdc, uintptr(cx-isz/2), uintptr(cy-isz/2), a.icon, uintptr(isz), uintptr(isz), 0, 0, diNormal)
|
||||
pDrawIconEx.Call(hdc, uintptr(cx-isz/2), uintptr(cy-isz/2), styledIcon(a.icon), uintptr(isz), uintptr(isz), 0, 0, diNormal)
|
||||
} else if rs := []rune(a.title); len(rs) > 0 {
|
||||
pSetBkMode.Call(hdc, transparent)
|
||||
pSetTextColor.Call(hdc, rgb(245, 245, 245))
|
||||
@@ -866,6 +859,7 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
addTrayMenu(add, sep, trayKind)
|
||||
}
|
||||
|
||||
add(0, menuSettingsID, "MirrorBar settings...")
|
||||
add(0, menuNotifyID, "Open notification center")
|
||||
sep()
|
||||
for i, l := range alphaLevels {
|
||||
@@ -888,6 +882,7 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
posFlags = mfGrayed
|
||||
}
|
||||
add(posFlags, menuResetPosID, "Reset position to bottom center")
|
||||
add(0, menuResetWidthID, "Reset bar width")
|
||||
var autoFlags uintptr
|
||||
if autostartEnabled() {
|
||||
autoFlags = mfChecked
|
||||
@@ -916,6 +911,10 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
pDestroyWindow.Call(hwnd)
|
||||
case cmd == menuResetPosID:
|
||||
resetPos(hwnd)
|
||||
case cmd == menuResetWidthID:
|
||||
leftPref = 0
|
||||
saveLeftPref()
|
||||
redraw(hwnd)
|
||||
case handleColorCommand(cmd):
|
||||
redraw(hwnd)
|
||||
case cmd == menuOrientID:
|
||||
@@ -936,6 +935,8 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
unpinApp(exe)
|
||||
refreshApps(false)
|
||||
redraw(hwnd)
|
||||
case cmd == menuSettingsID:
|
||||
openSettings()
|
||||
case cmd == menuNotifyID:
|
||||
openNotifications()
|
||||
case cmd == menuFileLocID && exe != "":
|
||||
@@ -952,6 +953,7 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
saveAlpha()
|
||||
redraw(hwnd)
|
||||
}
|
||||
settingsSync()
|
||||
}
|
||||
|
||||
func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
@@ -997,6 +999,10 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
case wmLButtonDown:
|
||||
previewSuppress()
|
||||
x := alongClient(lparam)
|
||||
if edgeZone(x) {
|
||||
beginResize(hwnd)
|
||||
return 0
|
||||
}
|
||||
if inStart(hwnd, x) {
|
||||
dragSeq, dragIsStart, dragStart, dragActive = slot(), true, x, false
|
||||
pSetCapture.Call(hwnd)
|
||||
@@ -1009,10 +1015,15 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
}
|
||||
return 0
|
||||
case wmCaptureChanged:
|
||||
resizing = false
|
||||
endIconDrag()
|
||||
dragTray, dragTrayActive = 0, false
|
||||
return 0
|
||||
case wmMouseMove:
|
||||
if resizing {
|
||||
moveResize(hwnd)
|
||||
return 0
|
||||
}
|
||||
x := alongClient(lparam)
|
||||
if dragSeq >= 0 && dragSeq <= len(apps) {
|
||||
if !dragActive && abs32(x-dragStart) > px(5) {
|
||||
@@ -1073,6 +1084,10 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
}
|
||||
return 0
|
||||
case wmLButtonUp:
|
||||
if resizing {
|
||||
endResize(hwnd)
|
||||
return 0
|
||||
}
|
||||
x := alongClient(lparam)
|
||||
if dragSeq >= 0 {
|
||||
// A press on the Start button or an app icon: a click if it never moved, otherwise the drag ends here.
|
||||
@@ -1109,6 +1124,9 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
showMenu(hwnd, appIndexAt(hwnd, x), trayAt(hwnd, x))
|
||||
previewBlock(false)
|
||||
return 0
|
||||
case wmDropFiles:
|
||||
dropFiles(hwnd, wparam)
|
||||
return 0
|
||||
case wmMouseWheel:
|
||||
// Scrolling over the volume icon changes the volume. The wheel
|
||||
// position arrives in screen coordinates, so make it relative to the bar.
|
||||
@@ -1125,10 +1143,16 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
var wr rect
|
||||
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||
x := alongScreen(lparam, wr)
|
||||
if inStart(hwnd, x) || appIndexAt(hwnd, x) >= 0 || trayAt(hwnd, x) != 0 {
|
||||
if edgeZone(x) || inStart(hwnd, x) || appIndexAt(hwnd, x) >= 0 || trayAt(hwnd, x) != 0 {
|
||||
return htClient
|
||||
}
|
||||
return htCaption
|
||||
case wmSetCursor:
|
||||
// The far end of the pill shows the resize arrow.
|
||||
if resizing || (uint16(lparam&0xFFFF) == htClient && overEdge(hwnd)) {
|
||||
pSetCursor.Call(sizeCursor())
|
||||
return 1
|
||||
}
|
||||
case wmNcLButtonDblClk:
|
||||
return 0 // a double click on the drag area must not maximize the pill
|
||||
case wmNcRButtonUp:
|
||||
@@ -1216,8 +1240,10 @@ func main() {
|
||||
loadStartSlot()
|
||||
loadTrayOrder()
|
||||
loadOrient()
|
||||
loadLeftPref()
|
||||
loadPinned()
|
||||
loadOrderKeys()
|
||||
loadIconMode()
|
||||
|
||||
hdc, _, _ := pGetDC.Call(0)
|
||||
dpi, _, _ := pGetDeviceCaps.Call(hdc, logPixelsX)
|
||||
@@ -1271,6 +1297,7 @@ func main() {
|
||||
}
|
||||
hwndMain = hwnd
|
||||
previewInit(inst)
|
||||
enableFileDrop(hwnd)
|
||||
refreshAutostartPath()
|
||||
|
||||
// Hotkey: Ctrl+Alt+Q exits and restores.
|
||||
@@ -1305,6 +1332,11 @@ func main() {
|
||||
if int32(r) <= 0 {
|
||||
break
|
||||
}
|
||||
if hwndSettings != 0 {
|
||||
if handled, _, _ := pIsDialogMessage.Call(hwndSettings, uintptr(unsafe.Pointer(&m))); handled != 0 {
|
||||
continue
|
||||
}
|
||||
}
|
||||
pTranslateMessage.Call(uintptr(unsafe.Pointer(&m)))
|
||||
pDispatchMessage.Call(uintptr(unsafe.Pointer(&m)))
|
||||
}
|
||||
|
||||
@@ -333,6 +333,9 @@ func refreshApps(refreshIcons bool) bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
styleCacheClear() // icon handles can be reused by other icons
|
||||
}
|
||||
apps = next
|
||||
return changed
|
||||
}
|
||||
|
||||
@@ -128,17 +128,20 @@ func pillPos(pw, ph int32) (int32, int32) {
|
||||
return defaultPos(pw, ph)
|
||||
}
|
||||
sw, sh := screenSize()
|
||||
x := clampI(customCX-pw/2, 0, sw-pw)
|
||||
y := clampI(customY-ph/2, 0, sh-ph)
|
||||
return x, y
|
||||
l := leftHalf() // the center line stays at the remembered spot
|
||||
if vertical {
|
||||
return clampI(customCX-pw/2, 0, sw-pw), clampI(customY-l, 0, sh-ph)
|
||||
}
|
||||
return clampI(customCX-l, 0, sw-pw), clampI(customY-ph/2, 0, sh-ph)
|
||||
}
|
||||
|
||||
func defaultPos(pw, ph int32) (int32, int32) {
|
||||
sw, sh := screenSize()
|
||||
l := leftHalf() // the center line sits at the middle of the screen
|
||||
if vertical {
|
||||
return sw - pw - barGap(), (sh - ph) / 2
|
||||
return sw - pw - barGap(), sh/2 - l
|
||||
}
|
||||
return (sw - pw) / 2, sh - ph - barGap()
|
||||
return sw/2 - l, sh - ph - barGap()
|
||||
}
|
||||
|
||||
// finishDrag runs when a drag ends: remember the new spot, or snap back to the
|
||||
@@ -152,7 +155,12 @@ func finishDrag(hwnd uintptr) {
|
||||
resetPos(hwnd)
|
||||
return
|
||||
}
|
||||
customPos, customCX, customY = true, (wr.Left+wr.Right)/2, (wr.Top+wr.Bottom)/2
|
||||
l := leftHalf()
|
||||
if vertical {
|
||||
customPos, customCX, customY = true, (wr.Left+wr.Right)/2, wr.Top+l
|
||||
} else {
|
||||
customPos, customCX, customY = true, wr.Left+l, (wr.Top+wr.Bottom)/2
|
||||
}
|
||||
savePos()
|
||||
if appbarOn {
|
||||
// A floating bar no longer reserves screen space.
|
||||
@@ -249,7 +257,7 @@ func appOfSeq(t int) int {
|
||||
func rowLayout(clientW, clientH int32) []rect {
|
||||
n := int32(len(apps))
|
||||
sl := int32(slot())
|
||||
cx := clientW / 2
|
||||
cx := axisX(clientW)
|
||||
bw := px(36)
|
||||
if n > 0 {
|
||||
avail := cx - startWidth() - px(8)
|
||||
|
||||
+2
-2
@@ -122,7 +122,7 @@ func previewPaint(hwnd uintptr) {
|
||||
isz := px(16)
|
||||
if pvIcon != 0 {
|
||||
y := pvTitleR.Top + (pvTitleR.Bottom-pvTitleR.Top-isz)/2
|
||||
pDrawIconEx.Call(hdc, uintptr(pvTitleR.Left), uintptr(y), pvIcon, uintptr(isz), uintptr(isz), 0, 0, diNormal)
|
||||
pDrawIconEx.Call(hdc, uintptr(pvTitleR.Left), uintptr(y), styledIcon(pvIcon), uintptr(isz), uintptr(isz), 0, 0, diNormal)
|
||||
}
|
||||
pSetBkMode.Call(hdc, transparent)
|
||||
pSetTextColor.Call(hdc, rgb(240, 240, 245))
|
||||
@@ -136,7 +136,7 @@ func previewPaint(hwnd uintptr) {
|
||||
big := px(48)
|
||||
cx := (pvThumbR.Left + pvThumbR.Right) / 2
|
||||
cy := (pvThumbR.Top + pvThumbR.Bottom) / 2
|
||||
pDrawIconEx.Call(hdc, uintptr(cx-big/2), uintptr(cy-big/2), pvIcon, uintptr(big), uintptr(big), 0, 0, diNormal)
|
||||
pDrawIconEx.Call(hdc, uintptr(cx-big/2), uintptr(cy-big/2), styledIcon(pvIcon), uintptr(big), uintptr(big), 0, 0, diNormal)
|
||||
}
|
||||
pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
||||
}
|
||||
|
||||
@@ -71,7 +71,8 @@ func colorOf(i int) uintptr {
|
||||
i = 0
|
||||
}
|
||||
c := palette[i]
|
||||
return rgb(c.r, c.g, c.b)
|
||||
r, g, b := styleColor(c.r, c.g, c.b)
|
||||
return rgb(r, g, b)
|
||||
}
|
||||
|
||||
func logoColor() uintptr { return colorOf(logoIdx) }
|
||||
@@ -130,6 +131,7 @@ func addColorMenus(menu uintptr) {
|
||||
build(menuLogoColorBase, logoIdx, "Windows logo color")
|
||||
build(menuClockColorBase, clockIdx, "Clock color")
|
||||
build(menuIconColorBase, iconIdx, "Tray icon color")
|
||||
addStyleMenu(menu)
|
||||
}
|
||||
|
||||
func handleColorCommand(cmd uintptr) bool {
|
||||
@@ -141,6 +143,8 @@ func handleColorCommand(cmd uintptr) bool {
|
||||
clockIdx = int(cmd - menuClockColorBase)
|
||||
case cmd >= menuIconColorBase && cmd < menuIconColorBase+n:
|
||||
iconIdx = int(cmd - menuIconColorBase)
|
||||
case handleStyleCommand(cmd):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
+286
@@ -0,0 +1,286 @@
|
||||
package main
|
||||
|
||||
// The settings window: everything the right-click menu can change, in one
|
||||
// place. It opens from "MirrorBar settings..." in the menu. Changes apply the
|
||||
// moment you make them, and the window stays in step if the menu is used too.
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
pSendMessage = user32.NewProc("SendMessageW")
|
||||
pSetWindowText = user32.NewProc("SetWindowTextW")
|
||||
pIsDialogMessage = user32.NewProc("IsDialogMessageW")
|
||||
pAdjustWindowRectEx = user32.NewProc("AdjustWindowRectEx")
|
||||
pInitCommonControls = syscall.NewLazyDLL("comctl32.dll").NewProc("InitCommonControlsEx")
|
||||
)
|
||||
|
||||
const (
|
||||
menuSettingsID = 45
|
||||
|
||||
wmCommand = 0x0111
|
||||
wmHScroll = 0x0114
|
||||
wmSetFont = 0x0030
|
||||
|
||||
wsChild = 0x40000000
|
||||
wsTabStop = 0x00010000
|
||||
wsVScroll = 0x00200000
|
||||
wsWindowFrame = 0x00C80000 // caption, system menu, border: a plain window that can't be resized
|
||||
bsPushButton = 0x0000
|
||||
bsDefPushButton = 0x0001
|
||||
bsAutoCheckBox = 0x0003
|
||||
cbsDropDownList = 0x0003
|
||||
tbsNoTicks = 0x0010
|
||||
|
||||
bmGetCheck = 0x00F0
|
||||
bmSetCheck = 0x00F1
|
||||
cbAddString = 0x0143
|
||||
cbGetCurSel = 0x0147
|
||||
cbSetCurSel = 0x014E
|
||||
tbmGetPos = 0x0400
|
||||
tbmSetPos = 0x0405
|
||||
tbmSetRange = 0x0406
|
||||
|
||||
cbnSelChange = 1
|
||||
tbEndTrack = 8
|
||||
colorBtnFace = 15
|
||||
|
||||
idAlpha = 200
|
||||
idAlphaValue = 201
|
||||
idLogo = 202
|
||||
idClock = 203
|
||||
idTrayIcons = 204
|
||||
idStyle = 205
|
||||
idVertical = 206
|
||||
idAutostart = 207
|
||||
idResetPos = 208
|
||||
idResetWidth = 209
|
||||
idClose = 210
|
||||
)
|
||||
|
||||
var (
|
||||
hwndSettings uintptr
|
||||
settingsClass bool
|
||||
settingsFont uintptr
|
||||
|
||||
ctlAlpha, ctlAlphaValue, ctlLogo, ctlClock, ctlTrayIcons, ctlStyle uintptr
|
||||
ctlVertical, ctlAutostart uintptr
|
||||
)
|
||||
|
||||
func boolWP(b bool) uintptr {
|
||||
if b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// makeControl creates one child control; sizes are in 96 dpi units.
|
||||
func makeControl(parent, inst uintptr, class, text string, style uintptr, x, y, w, h int, id uintptr) uintptr {
|
||||
hw, _, _ := pCreateWindowEx.Call(0,
|
||||
uintptr(unsafe.Pointer(u16(class))), uintptr(unsafe.Pointer(u16(text))),
|
||||
style|wsChild|wsVisible,
|
||||
uintptr(px(float64(x))), uintptr(px(float64(y))), uintptr(px(float64(w))), uintptr(px(float64(h))),
|
||||
parent, id, inst, 0)
|
||||
if hw != 0 && settingsFont != 0 {
|
||||
pSendMessage.Call(hw, wmSetFont, settingsFont, 1)
|
||||
}
|
||||
return hw
|
||||
}
|
||||
|
||||
func openSettings() {
|
||||
if hwndSettings != 0 {
|
||||
pShowWindow.Call(hwndSettings, swRestore)
|
||||
pSetForegroundWindow.Call(hwndSettings)
|
||||
settingsSync()
|
||||
return
|
||||
}
|
||||
inst, _, _ := pGetModuleHandle.Call(0)
|
||||
className := u16("MirrorBarSettings")
|
||||
if !settingsClass {
|
||||
cursor, _, _ := pLoadCursor.Call(0, idcArrow)
|
||||
wc := wndClassEx{
|
||||
WndProc: syscall.NewCallback(settingsProc),
|
||||
Instance: inst,
|
||||
Cursor: cursor,
|
||||
Background: colorBtnFace + 1,
|
||||
ClassName: className,
|
||||
}
|
||||
wc.Size = uint32(unsafe.Sizeof(wc))
|
||||
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
||||
icc := struct{ Size, Classes uint32 }{8, 0x4} // ICC_BAR_CLASSES: the slider
|
||||
pInitCommonControls.Call(uintptr(unsafe.Pointer(&icc)))
|
||||
settingsClass = true
|
||||
}
|
||||
if settingsFont == 0 {
|
||||
settingsFont = makeFont(px(13), 400)
|
||||
}
|
||||
|
||||
r := rect{0, 0, px(400), px(330)}
|
||||
pAdjustWindowRectEx.Call(uintptr(unsafe.Pointer(&r)), wsWindowFrame, 0, 0)
|
||||
ow, oh := r.Right-r.Left, r.Bottom-r.Top
|
||||
sw, sh := screenSize()
|
||||
hw, _, _ := pCreateWindowEx.Call(0,
|
||||
uintptr(unsafe.Pointer(className)), uintptr(unsafe.Pointer(u16("MirrorBar settings"))),
|
||||
wsWindowFrame,
|
||||
uintptr(max(0, (sw-ow)/2)), uintptr(max(0, (sh-oh)/2)), uintptr(ow), uintptr(oh),
|
||||
0, 0, inst, 0)
|
||||
if hw == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
label := func(text string, y int) {
|
||||
makeControl(hw, inst, "STATIC", text, 0, 16, y+4, 150, 20, 0)
|
||||
}
|
||||
combo := func(y int, id uintptr) uintptr {
|
||||
return makeControl(hw, inst, "COMBOBOX", "", cbsDropDownList|wsVScroll|wsTabStop, 170, y, 214, 200, id)
|
||||
}
|
||||
|
||||
label("Background opacity", 16)
|
||||
ctlAlpha = makeControl(hw, inst, "msctls_trackbar32", "", tbsNoTicks|wsTabStop, 166, 14, 170, 28, idAlpha)
|
||||
ctlAlphaValue = makeControl(hw, inst, "STATIC", "", 0, 344, 20, 44, 20, idAlphaValue)
|
||||
pSendMessage.Call(ctlAlpha, tbmSetRange, 1, uintptr(3|255<<16))
|
||||
|
||||
label("Windows logo color", 60)
|
||||
ctlLogo = combo(60, idLogo)
|
||||
label("Clock color", 96)
|
||||
ctlClock = combo(96, idClock)
|
||||
label("Tray icon color", 132)
|
||||
ctlTrayIcons = combo(132, idTrayIcons)
|
||||
label("Icon style", 168)
|
||||
ctlStyle = combo(168, idStyle)
|
||||
for _, c := range []uintptr{ctlLogo, ctlClock, ctlTrayIcons} {
|
||||
for _, p := range palette {
|
||||
pSendMessage.Call(c, cbAddString, 0, uintptr(unsafe.Pointer(u16(p.name))))
|
||||
}
|
||||
}
|
||||
for _, n := range styleNames {
|
||||
pSendMessage.Call(ctlStyle, cbAddString, 0, uintptr(unsafe.Pointer(u16(n))))
|
||||
}
|
||||
|
||||
ctlVertical = makeControl(hw, inst, "BUTTON", "Stand the bar up at the right edge (vertical)", bsAutoCheckBox|wsTabStop, 16, 214, 368, 22, idVertical)
|
||||
ctlAutostart = makeControl(hw, inst, "BUTTON", "Start MirrorBar when I sign in", bsAutoCheckBox|wsTabStop, 16, 242, 368, 22, idAutostart)
|
||||
|
||||
makeControl(hw, inst, "BUTTON", "Reset position", bsPushButton|wsTabStop, 16, 284, 116, 28, idResetPos)
|
||||
makeControl(hw, inst, "BUTTON", "Reset bar width", bsPushButton|wsTabStop, 140, 284, 116, 28, idResetWidth)
|
||||
makeControl(hw, inst, "BUTTON", "Close", bsDefPushButton|wsTabStop, 292, 284, 92, 28, idClose)
|
||||
|
||||
hwndSettings = hw
|
||||
settingsSync()
|
||||
pShowWindow.Call(hw, 1)
|
||||
pSetForegroundWindow.Call(hw)
|
||||
}
|
||||
|
||||
// settingsSync makes every control show the current setting.
|
||||
func settingsSync() {
|
||||
if hwndSettings == 0 {
|
||||
return
|
||||
}
|
||||
pSendMessage.Call(ctlAlpha, tbmSetPos, 1, uintptr(bgAlpha))
|
||||
pSetWindowText.Call(ctlAlphaValue, uintptr(unsafe.Pointer(u16(strconv.Itoa(bgAlpha*100/255)+"%"))))
|
||||
pSendMessage.Call(ctlLogo, cbSetCurSel, uintptr(logoIdx), 0)
|
||||
pSendMessage.Call(ctlClock, cbSetCurSel, uintptr(clockIdx), 0)
|
||||
pSendMessage.Call(ctlTrayIcons, cbSetCurSel, uintptr(iconIdx), 0)
|
||||
pSendMessage.Call(ctlStyle, cbSetCurSel, uintptr(iconMode), 0)
|
||||
pSendMessage.Call(ctlVertical, bmSetCheck, boolWP(vertical), 0)
|
||||
pSendMessage.Call(ctlAutostart, bmSetCheck, boolWP(autostartEnabled()), 0)
|
||||
}
|
||||
|
||||
func comboChoice(c uintptr) int {
|
||||
r, _, _ := pSendMessage.Call(c, cbGetCurSel, 0, 0)
|
||||
return int(int32(r))
|
||||
}
|
||||
|
||||
func checked(c uintptr) bool {
|
||||
r, _, _ := pSendMessage.Call(c, bmGetCheck, 0, 0)
|
||||
return r == 1
|
||||
}
|
||||
|
||||
func settingsCommand(id, note uintptr) {
|
||||
switch id {
|
||||
case 1, 2: // Enter and Esc
|
||||
pDestroyWindow.Call(hwndSettings)
|
||||
case idClose:
|
||||
pDestroyWindow.Call(hwndSettings)
|
||||
case idLogo, idClock, idTrayIcons:
|
||||
if note != cbnSelChange {
|
||||
return
|
||||
}
|
||||
switch id {
|
||||
case idLogo:
|
||||
if i := comboChoice(ctlLogo); i >= 0 {
|
||||
logoIdx = i
|
||||
}
|
||||
case idClock:
|
||||
if i := comboChoice(ctlClock); i >= 0 {
|
||||
clockIdx = i
|
||||
}
|
||||
case idTrayIcons:
|
||||
if i := comboChoice(ctlTrayIcons); i >= 0 {
|
||||
iconIdx = i
|
||||
}
|
||||
}
|
||||
saveColors()
|
||||
redraw(hwndMain)
|
||||
case idStyle:
|
||||
if note != cbnSelChange {
|
||||
return
|
||||
}
|
||||
if i := comboChoice(ctlStyle); i >= 0 && i < len(styleNames) {
|
||||
iconMode = i
|
||||
saveIconMode()
|
||||
styleCacheClear()
|
||||
redraw(hwndMain)
|
||||
}
|
||||
case idVertical:
|
||||
vertical = checked(ctlVertical)
|
||||
saveOrient()
|
||||
resetPos(hwndMain)
|
||||
case idAutostart:
|
||||
setAutostart(checked(ctlAutostart))
|
||||
settingsSync()
|
||||
case idResetPos:
|
||||
resetPos(hwndMain)
|
||||
case idResetWidth:
|
||||
leftPref = 0
|
||||
saveLeftPref()
|
||||
redraw(hwndMain)
|
||||
}
|
||||
}
|
||||
|
||||
func settingsProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
result = 0
|
||||
}
|
||||
}()
|
||||
switch uint32(m) {
|
||||
case wmCommand:
|
||||
settingsCommand(wparam&0xFFFF, wparam>>16&0xFFFF)
|
||||
return 0
|
||||
case wmHScroll:
|
||||
if lparam == ctlAlpha && ctlAlpha != 0 {
|
||||
pos, _, _ := pSendMessage.Call(ctlAlpha, tbmGetPos, 0, 0)
|
||||
n := int(pos)
|
||||
if n >= 3 && n <= 255 && n != bgAlpha {
|
||||
bgAlpha = n
|
||||
pSetWindowText.Call(ctlAlphaValue, uintptr(unsafe.Pointer(u16(strconv.Itoa(bgAlpha*100/255)+"%"))))
|
||||
redraw(hwndMain)
|
||||
}
|
||||
if wparam&0xFFFF == tbEndTrack {
|
||||
saveAlpha()
|
||||
}
|
||||
}
|
||||
return 0
|
||||
case wmClose:
|
||||
pDestroyWindow.Call(hwnd)
|
||||
return 0
|
||||
case wmDestroy:
|
||||
hwndSettings = 0
|
||||
return 0
|
||||
}
|
||||
r, _, _ := pDefWindowProc.Call(hwnd, m, wparam, lparam)
|
||||
return r
|
||||
}
|
||||
@@ -85,7 +85,11 @@ type trayItem struct {
|
||||
}
|
||||
|
||||
func trayItems(clientW, clientH int32) []trayItem {
|
||||
x := clientW / 2
|
||||
return trayItemsAt(axisX(clientW), clientH)
|
||||
}
|
||||
|
||||
// trayItemsAt lays the right-hand items out rightward from x.
|
||||
func trayItemsAt(x, clientH int32) []trayItem {
|
||||
var out []trayItem
|
||||
for _, kind := range trayOrder {
|
||||
var w int32
|
||||
|
||||
Reference in New Issue
Block a user