Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag the top window on current screen, not the active window. #8

Closed
developer91234 opened this issue Jul 30, 2023 · 9 comments
Closed
Assignees
Labels
enhancement New feature or request

Comments

@developer91234
Copy link

This is a behavior of latte dock. KDE's new global menu widget also only shows the menu for the active window for the current display, not the menu for the active window on some other display. So tracking by display should in theory be doable.

@luisbocanegra
Copy link
Owner

Currently, the widget uses qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut "Window Move" to start the dragging, unfortunately there is no separate shortcut to drag the window only if is in the current screen.

Someone will have to take a look at what Latte does and try porting that here if possible.

@luisbocanegra luisbocanegra added the enhancement New feature or request label Jul 30, 2023
@luisbocanegra luisbocanegra self-assigned this Feb 7, 2024
@luisbocanegra
Copy link
Owner

Found a way do do this, with a KWin Script (Plasma 6 only). Please ignore the lag, looks like recording two monitors was too much for my IGPU 😆

demo.mp4
  1. It checks where the mouse is and uses that to set the active screen
  2. Loops through the windows and checks they are in the active screen not minimized and other properties
  3. Then we get the window that is higher in the stack and activate it
  4. Finally send the window action and it runs on that window

This will also benefit all other kwin shortcuts that do things with the active window 🥳

It's not yet integrated with the widget code but you can be tested by running a script with the following (update the SCRIPT path):

move-window.sh

#!/bin/env bash

# load the script
echo "running"
SCRIPT="/home/luis/projects/plasma-panel-spacer-extended/moveTopWindow.js"
SCRIPT_NAME="moveTopWindow"
qdbus org.kde.KWin /Scripting org.kde.kwin.Scripting.unloadScript "$SCRIPT_NAME"
script_id=$(qdbus org.kde.KWin /Scripting org.kde.kwin.Scripting.loadScript "${SCRIPT}" "$SCRIPT_NAME")

# run
qdbus org.kde.KWin /Scripting/Script"$script_id" org.kde.kwin.Script.run
sleep 1
qdbus org.kde.KWin /Scripting/Script"$script_id" org.kde.kwin.Script.stop

moveTopWindow.js

const windows = workspace.windowList();
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
var windowToMove
let stackOrder = -1

var currentScreen = workspace.screenAt(workspace.cursorPos)
for (var i = 0; i < windows.length; i++) {
  if (windows[i].output === currentScreen && !windows[i].desktopWindow && windows[i].normalWindow && !windows[i].minimized && windows[i].moveable && !windows[i].hidden) {
    print("@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
    print(windows[i].caption);
    print(windows[i].resourceName);
    print(windows[i].resourceClass);
    print(windows[i].stackingOrder);
    if (windows[i].stackingOrder > stackOrder) {
      windowToMove = windows[i]
    }
    stackOrder = windows[i].stackingOrder
  }
}
resut = ("Dragging: " + windowToMove.caption + "|" + windowToMove.resourceName + "|" + windowToMove.resourceClass + "|" + windowToMove.stackingOrder + "|" + windowToMove.output.name)
print("MOVE")
print(resut)
workspace.activeWindow = windowToMove
workspace.slotWindowMove()
callDBus("org.kde.plasmashell", "/org/kde/osdService", "org.kde.osdService", "showText", "window", resut);

@ShayBox
Copy link

ShayBox commented Apr 17, 2024

Any ETA on this being merged? since #19 has been fixed, this and #18 are the only things I need to completely replace LatteDock and have a working top-bar again.

EDIT: It seems #19 hasn't been fixed in 1.5.4, I still have to let go to start moving the window. A release hasn't been made yet.

@luisbocanegra
Copy link
Owner

Will publish a release with #19 tomorrow.

For dragging the top window I have a working version already, just need to also activate the top window for all the other shortcuts that need it (e.g. close window and many others)

@luisbocanegra
Copy link
Owner

luisbocanegra commented Apr 18, 2024

This should now work on main with the following shortcuts:

  • kwin ExposeClass
  • kwin Decrease Opacity
  • kwin Increase Opacity
  • kwin InvertWindow
  • kwin Kill Window
  • kwin Setup Window Shortcut
  • kwin Switch Window Down
  • kwin Switch Window Left
  • kwin Switch Window Right
  • kwin Switch Window Up
  • kwin Toggle Window Raise/Lower
  • kwin Walk Through Windows of Current Application
  • kwin Window Above Other Windows
  • kwin Window Below Other Windows
  • kwin Window Close
  • kwin Window Fullscreen
  • kwin Window Grow
  • kwin Window Lower
  • kwin Window Maximize
  • kwin Window Minimize
  • kwin Window Move
  • kwin Window No Border
  • kwin Window On All Desktops
  • kwin Window One Desktop
  • kwin Window One Screen
  • kwin Window Operations Menu
  • kwin Window Pack
  • kwin Window Quick Tile
  • kwin Window Raise
  • kwin Window Resize
  • kwin Window Shade
  • kwin Window Shrink
  • kwin Window to

@luisbocanegra
Copy link
Owner

@ShayBox
Copy link

ShayBox commented Apr 18, 2024

It works great! Perfect replacement for Latte-Dock and great for replicating the Gnome/Unity top bar behavior!

@ShayBox
Copy link

ShayBox commented Apr 21, 2024

One issue with this approach is that if you have a window pinned to top, it will always grab that window. I'm not sure this can be solved with a script only plasmoid though, it would have to involve writing C++ code.

@luisbocanegra
Copy link
Owner

Hmmm maybe I could:

  1. Keep track of the last active window on each screen and try to activate that
  2. If the last window is no longer there look for another active window
  3. If that doesn't exist either then grab the top one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants