-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move windows between monitors with mouse
- Loading branch information
Showing
21 changed files
with
307 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/nativeMain/kotlin/de/atennert/lcarswm/events/ButtonReleaseHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package de.atennert.lcarswm.events | ||
|
||
import de.atennert.lcarswm.log.Logger | ||
import de.atennert.lcarswm.mouse.MoveWindowManager | ||
import de.atennert.lcarswm.system.api.InputApi | ||
import de.atennert.lcarswm.window.WindowFocusHandler | ||
import de.atennert.lcarswm.window.WindowList | ||
import xlib.ButtonRelease | ||
import xlib.XEvent | ||
|
||
class ButtonReleaseHandler( | ||
private val logger: Logger, | ||
private val moveWindowManager: MoveWindowManager | ||
) : XEventHandler { | ||
override val xEventType = ButtonRelease | ||
|
||
override fun handleEvent(event: XEvent): Boolean { | ||
val windowId = event.xbutton.window | ||
val subWindowId = event.xbutton.subwindow | ||
logger.logDebug("ButtonReleaseHandler::handleEvent::windowId: $windowId, sub window: $subWindowId, x y: ${event.xbutton.x} ${event.xbutton.y} (${event.xbutton.x_root} ${event.xbutton.y_root})") | ||
|
||
moveWindowManager.release() | ||
return false | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/nativeMain/kotlin/de/atennert/lcarswm/events/MotionNotifyHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package de.atennert.lcarswm.events | ||
|
||
import de.atennert.lcarswm.log.Logger | ||
import de.atennert.lcarswm.mouse.MoveWindowManager | ||
import de.atennert.lcarswm.system.api.InputApi | ||
import de.atennert.lcarswm.window.WindowFocusHandler | ||
import de.atennert.lcarswm.window.WindowList | ||
import xlib.* | ||
|
||
class MotionNotifyHandler( | ||
private val logger: Logger, | ||
private val moveWindowManager: MoveWindowManager | ||
) : XEventHandler { | ||
override val xEventType = MotionNotify | ||
|
||
override fun handleEvent(event: XEvent): Boolean { | ||
val windowId = event.xmotion.window | ||
val subWindowId = event.xmotion.subwindow | ||
logger.logDebug("MotionNotifyHandler::handleEvent::windowId: $windowId, sub window: $subWindowId, x y: ${event.xmotion.x} ${event.xmotion.y} (${event.xmotion.x_root} ${event.xmotion.y_root})") | ||
|
||
moveWindowManager.move(event.xmotion.x_root, event.xmotion.y_root) | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/nativeMain/kotlin/de/atennert/lcarswm/mouse/MoveWindowManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package de.atennert.lcarswm.mouse | ||
|
||
import de.atennert.lcarswm.ScreenMode | ||
import de.atennert.lcarswm.log.Logger | ||
import de.atennert.lcarswm.monitor.Monitor | ||
import de.atennert.lcarswm.monitor.MonitorObserver | ||
import de.atennert.lcarswm.window.FramedWindow | ||
import de.atennert.lcarswm.window.WindowCoordinator | ||
|
||
class MoveWindowManager( | ||
private val logger: Logger, | ||
private val windowCoordinator: WindowCoordinator | ||
) : MonitorObserver { | ||
|
||
private var monitors = emptyList<Monitor>() | ||
|
||
private lateinit var lastWindowMonitor: Monitor | ||
|
||
private var targetWindow: FramedWindow? = null | ||
|
||
fun press(window: FramedWindow, x: Int, y: Int) { | ||
targetWindow?.let { | ||
logger.logWarning("MoveWindowManager::press::apparently there was a window moving in process for ${it.id}.") | ||
} | ||
|
||
targetWindow = window | ||
lastWindowMonitor = getMonitor(x, y) ?: return | ||
} | ||
|
||
fun move(x: Int, y: Int) { | ||
targetWindow?.let { | ||
val newMonitor = getMonitor(x, y) ?: return | ||
if (newMonitor.id != lastWindowMonitor.id) { | ||
windowCoordinator.moveWindowToMonitor(it.id, newMonitor) | ||
lastWindowMonitor = newMonitor | ||
} | ||
} | ||
} | ||
|
||
fun release() { | ||
targetWindow = null | ||
} | ||
|
||
private fun getMonitor(x: Int, y: Int): Monitor? { | ||
try { | ||
return monitors.first { it.isOnMonitor(x, y) } | ||
} catch (e: Exception) { | ||
logger.logError(e.toString()) | ||
return null | ||
} | ||
} | ||
|
||
override fun toggleScreenMode(newScreenMode: ScreenMode) {} | ||
|
||
override fun updateMonitors(monitors: List<Monitor>) { | ||
this.monitors = monitors | ||
logger.logDebug("MoveWindowManager::updateMonitors::$monitors") | ||
|
||
// cancel moving the window | ||
targetWindow?.let { | ||
logger.logWarning("MoveWindowManager::updateMonitors::cancel moving of ${it.id}") | ||
} | ||
targetWindow = null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.