Coder Social home page Coder Social logo

Comments (14)

fanlushuai avatar fanlushuai commented on September 17, 2024 1

Yes. everything goes well. Thanks again.

from windows-desktop-switcher.

fanlushuai avatar fanlushuai commented on September 17, 2024 1

Use proces name as pop notification for pin or unpin seem more clear than window tile.

_GetCurrentWindowProcess() {
WinGet, ProcessName, ProcessName, A
; MsgBox, %ProcessName%
return ProcessName
}

from windows-desktop-switcher.

Elijas avatar Elijas commented on September 17, 2024

Hi, glad you've found it useful!

Solution

Yes, I have added this functionality to my private version of the script, all you need is to add these lines and you'll be able to use Capslock + h for example, to pin the window on all desktops

global IsPinnedWindowProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "IsPinnedWindow", "Ptr")
global PinWindowProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "PinWindow", "Ptr")
global UnPinWindowProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "UnPinWindow", "Ptr")
global IsPinnedAppProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "IsPinnedApp", "Ptr")
global PinAppProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "PinApp", "Ptr")
global UnPinAppProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "UnPinApp", "Ptr")

capslock & g::OnTogglePinOnTopPress()
capslock & h::OnTogglePinAppPress()
capslock & j::OnTogglePinWindowPress()

_GetCurrentWindowID() {
    WinGet, activeHwnd, ID, A
    return activeHwnd
}

_GetCurrentWindowTitle() {
    WinGetTitle, activeHwnd, A
    return activeHwnd
}

OnTogglePinOnTopPress() {
        _notif(_TruncateString(_GetCurrentWindowTitle(), 100), "Toggled 'Pin On Top'")
	Winset, Alwaysontop, , A
}

OnTogglePinWindowPress() {
    windowID := _GetCurrentWindowID()
    windowTitle := _GetCurrentWindowTitle()
    if (_GetIsWindowPinned(windowID)) {
        _UnpinWindow(windowID)
        _ShowTooltipForUnpinnedWindow(windowTitle)
    }
    else {
        _PinWindow(windowID)
        _ShowTooltipForPinnedWindow(windowTitle)
    }
}

OnTogglePinAppPress() {
    windowID := _GetCurrentWindowID()
    windowTitle := _GetCurrentWindowTitle()
    if (_GetIsAppPinned(windowID)) {
        _UnpinApp(windowID)
        _ShowTooltipForUnpinnedApp(windowTitle)
    }
    else {
        _PinApp(windowID)
        _ShowTooltipForPinnedApp(windowTitle)
    }
}

_PinWindow(windowID:="") {
    _CallWindowProc(PinWindowProc, windowID)
}

_UnpinWindow(windowID:="") {
    _CallWindowProc(UnpinWindowProc, windowID)
}

_GetIsWindowPinned(windowID:="") {
    return _CallWindowProc(IsPinnedWindowProc, windowID)
}

_PinApp(windowID:="") {
    _CallWindowProc(PinAppProc, windowID)
}

_UnpinApp(windowID:="") {
    _CallWindowProc(UnpinAppProc, windowID)
}

_GetIsAppPinned(windowID:="") {
    return _CallWindowProc(IsPinnedAppProc, windowID)
}

_CallWindowProc(proc, window:="") {
    if (window == "") {
        window := _GetCurrentWindowID()
    }
    return DllCall(proc, UInt, window)
}

_notif(txt, title:="") {
    HideTrayTip()
    TrayTip, %title%, %txt%, 1
}

HideTrayTip() {
    TrayTip  ; Attempt to hide it the normal way.
    if SubStr(A_OSVersion,1,3) = "10." {
        Menu Tray, NoIcon
        Sleep 200  ; It may be necessary to adjust this sleep.
        Menu Tray, Icon
    }
}
_ShowTooltipForPinnedWindow(windowTitle) {
    _notif(_TruncateString(windowTitle, 100), "Pinned Window")
}

_ShowTooltipForUnpinnedWindow(windowTitle) {
    _notif(_TruncateString(windowTitle, 100), "Unpinned Window")
}

_ShowTooltipForPinnedApp(windowTitle) {
    _notif(_TruncateString(windowTitle, 100), "Pinned App")
}

_ShowTooltipForUnpinnedApp(windowTitle) {
    _notif(_TruncateString(windowTitle, 100), "Unpinned App")
}

_TruncateString(string:="", n:=10) {
    return (StrLen(string) > n ? SubStr(string, 1, n-3) . "..." : string)
}

from windows-desktop-switcher.

fanlushuai avatar fanlushuai commented on September 17, 2024

Well done!

I have test it,but met the error:

Error: Call to nonexistent function
Specifically:_GetCurrentWindowID()
……
……

from windows-desktop-switcher.

Elijas avatar Elijas commented on September 17, 2024

Thanks!
I added the missing function to the previous comment.
I also removed this line windowTitle := _GetCurrentWindowTitle()

from windows-desktop-switcher.

fanlushuai avatar fanlushuai commented on September 17, 2024

Error: Call to nonexistent function _CallWindowProc
Add this
_CallWindowProc(proc, window:="") {
if (window == "") {
window := _GetCurrentWindowID()
}
return DllCall(proc, UInt, window)
}

from windows-desktop-switcher.

fanlushuai avatar fanlushuai commented on September 17, 2024

Yeach. Popup notification can make the status more clean. It is really a good idea !

Very happy for your sharing ,if you does not matter

from windows-desktop-switcher.

Elijas avatar Elijas commented on September 17, 2024

Added it:)

from windows-desktop-switcher.

fanlushuai avatar fanlushuai commented on September 17, 2024

_GetCurrentWindowTitle() {
WinGetTitle, activeHwnd, A
return activeHwnd
}

from windows-desktop-switcher.

Elijas avatar Elijas commented on September 17, 2024

_GetCurrentWindowTitle() {
WinGetTitle, activeHwnd, A
return activeHwnd
}

You're right)

Does everything work now ?

from windows-desktop-switcher.

fanlushuai avatar fanlushuai commented on September 17, 2024

Except for pop notification for pin or unpin operation, switch backgroud with desktop can make switch more clear .

AutoAssociateBackgroundWithDesktop := false
BackgroundPicPaths := ["C:\Users\A\Pictures\VDPic\day.jpg", "C:\Users\A\Pictures\VDPic\snow.jpg", "C:\Users\A\Pictures\VDPic\sex.jpg", "C:\Users\A\Pictures\VDPic\cool.jpg"]


……

changeBackgroundWithDesktopId()
{
    global CurrentDesktop, BackgroundPicPaths, AutoAssociateBackgroundWithDesktop
    filePath := BackgroundPicPaths[CurrentDesktop]
    if (AutoAssociateBackgroundWithDesktop and filePath and FileExist(filePath)) {
        DllCall("SystemParametersInfo", UInt, 0x14, UInt, 0, Str, filePath, UInt, 1)
   }
}

from windows-desktop-switcher.

marium0505 avatar marium0505 commented on September 17, 2024

@Elijas
This is awesome, but I some of them doesn't seem to work.
The OnTogglePinOnTopPress function works fine, but neitherOnTogglePinAppPress nor OnTogglePinWindowPress seem to work for me.

Does anyone else have issues with the two functions as well? And does someone know a resolution? I would really love to be able to use those two lasts functions.

from windows-desktop-switcher.

javjim avatar javjim commented on September 17, 2024

@Elijas
This is awesome, but I some of them doesn't seem to work.
The OnTogglePinOnTopPress function works fine, but neitherOnTogglePinAppPress nor OnTogglePinWindowPress seem to work for me.

Does anyone else have issues with the two functions as well? And does someone know a resolution? I would really love to be able to use those two lasts functions.

Agree with you, only togglePin works for me, the other 2 don't work, and would love the functionality...

from windows-desktop-switcher.

ib4 avatar ib4 commented on September 17, 2024

@Elijas This is awesome, but I some of them doesn't seem to work. The OnTogglePinOnTopPress function works fine, but neitherOnTogglePinAppPress nor OnTogglePinWindowPress seem to work for me.

Does anyone else have issues with the two functions as well? And does someone know a resolution? I would really love to be able to use those two lasts functions.

I know it's an old issue, but I got it to work when I moved the six "global" statements up to the "DLL" section where the other "global" statements are.

from windows-desktop-switcher.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.