Initial Implementation for coordinate switching

This commit is contained in:
danielsuss 2025-06-12 14:29:34 +01:00
parent 653e4badeb
commit f0daa312d0
10 changed files with 326 additions and 9 deletions

View File

@ -0,0 +1,12 @@
{
"permissions": {
"allow": [
"Bash(rg:*)",
"Bash(g++:*)",
"Bash(cmake:*)",
"Bash(sudo apt:*)",
"Bash(sudo apt install:*)"
],
"deny": []
}
}

View File

@ -40,7 +40,10 @@ Action::Action() :
m_SwitchDirection(switchLeft),
m_LockCursorMode(lockCursorToggle),
m_ActiveOnRelease(false),
m_HasScreens(false)
m_HasScreens(false),
m_hasCustomPosition(false),
m_customX(0),
m_customY(0)
{
}
@ -87,6 +90,12 @@ QString Action::text() const
case switchToScreen:
text += "(";
text += switchScreenName();
if (hasCustomPosition()) {
text += ",";
text += QString::number(customX());
text += ",";
text += QString::number(customY());
}
text += ")";
break;
@ -133,6 +142,9 @@ void Action::loadSettings(QSettings& settings)
setLockCursorMode(settings.value("lockCursorToScreen", lockCursorToggle).toInt());
setActiveOnRelease(settings.value("activeOnRelease", false).toBool());
setHaveScreens(settings.value("hasScreens", false).toBool());
setHasCustomPosition(settings.value("hasCustomPosition", false).toBool());
setCustomX(settings.value("customX", 0).toInt());
setCustomY(settings.value("customY", 0).toInt());
}
void Action::saveSettings(QSettings& settings) const
@ -153,6 +165,9 @@ void Action::saveSettings(QSettings& settings) const
settings.setValue("lockCursorToScreen", lockCursorMode());
settings.setValue("activeOnRelease", activeOnRelease());
settings.setValue("hasScreens", haveScreens());
settings.setValue("hasCustomPosition", hasCustomPosition());
settings.setValue("customX", customX());
settings.setValue("customY", customY());
}
QTextStream& operator<<(QTextStream& outStream, const Action& action)

View File

@ -72,6 +72,15 @@ class Action
bool haveScreens() const { return m_HasScreens; }
void setHaveScreens(bool b) { m_HasScreens = b; }
bool hasCustomPosition() const { return m_hasCustomPosition; }
void setHasCustomPosition(bool b) { m_hasCustomPosition = b; }
int customX() const { return m_customX; }
void setCustomX(int x) { m_customX = x; }
int customY() const { return m_customY; }
void setCustomY(int y) { m_customY = y; }
private:
KeySequence m_KeySequence;
int m_Type;
@ -81,6 +90,9 @@ class Action
int m_LockCursorMode;
bool m_ActiveOnRelease;
bool m_HasScreens;
bool m_hasCustomPosition;
int m_customX;
int m_customY;
static const char* m_ActionTypeNames[];
static const char* m_SwitchDirectionNames[];

View File

@ -73,6 +73,11 @@ ActionDialog::ActionDialog(QWidget* parent, ServerConfig& config, Hotkey& hotkey
idx++;
}
}
// Initialize coordinate controls
m_pCheckBoxCustomPosition->setChecked(m_Action.hasCustomPosition());
m_pSpinBoxX->setValue(m_Action.customX());
m_pSpinBoxY->setValue(m_Action.customY());
}
void ActionDialog::accept()
@ -94,6 +99,23 @@ void ActionDialog::accept()
m_Action.setLockCursorMode(m_pComboLockCursorToScreen->currentIndex());
m_Action.setActiveOnRelease(m_pRadioHotkeyReleased->isChecked());
// Save coordinate settings only for switchToScreen action
if (m_pButtonGroupType->checkedId() == Action::switchToScreen) {
m_Action.setHasCustomPosition(m_pCheckBoxCustomPosition->isChecked());
if (m_pCheckBoxCustomPosition->isChecked()) {
m_Action.setCustomX(m_pSpinBoxX->value());
m_Action.setCustomY(m_pSpinBoxY->value());
} else {
m_Action.setCustomX(0);
m_Action.setCustomY(0);
}
} else {
// Clear custom position for other action types
m_Action.setHasCustomPosition(false);
m_Action.setCustomX(0);
m_Action.setCustomY(0);
}
QDialog::accept();
}

View File

@ -142,6 +142,96 @@
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout">
<item>
<widget class="QCheckBox" name="m_pCheckBoxCustomPosition">
<property name="text">
<string>Set specific position</string>
</property>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="m_pLabelX">
<property name="text">
<string>X:</string>
</property>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="m_pSpinBoxX">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="m_pLabelY">
<property name="text">
<string>Y:</string>
</property>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="m_pSpinBoxY">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
@ -588,5 +678,85 @@
</hint>
</hints>
</connection>
<connection>
<sender>m_pRadioSwitchToScreen</sender>
<signal>toggled(bool)</signal>
<receiver>m_pCheckBoxCustomPosition</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>148</x>
<y>291</y>
</hint>
<hint type="destinationlabel">
<x>148</x>
<y>310</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_pCheckBoxCustomPosition</sender>
<signal>toggled(bool)</signal>
<receiver>m_pLabelX</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>148</x>
<y>310</y>
</hint>
<hint type="destinationlabel">
<x>50</x>
<y>330</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_pCheckBoxCustomPosition</sender>
<signal>toggled(bool)</signal>
<receiver>m_pSpinBoxX</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>148</x>
<y>310</y>
</hint>
<hint type="destinationlabel">
<x>100</x>
<y>330</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_pCheckBoxCustomPosition</sender>
<signal>toggled(bool)</signal>
<receiver>m_pLabelY</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>148</x>
<y>310</y>
</hint>
<hint type="destinationlabel">
<x>150</x>
<y>330</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_pCheckBoxCustomPosition</sender>
<signal>toggled(bool)</signal>
<receiver>m_pSpinBoxY</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>148</x>
<y>310</y>
</hint>
<hint type="destinationlabel">
<x>200</x>
<y>330</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -1141,8 +1141,8 @@ void Config::parseAction(ConfigReadContext& s, const std::string& name,
*/
else if (name == "switchToScreen") {
if (args.size() != 1) {
throw XConfigRead(s, "syntax for action: switchToScreen(name)");
if (args.size() != 1 && args.size() != 3) {
throw XConfigRead(s, "syntax for action: switchToScreen(name[,x,y])");
}
std::string screen = args[0];
@ -1153,8 +1153,20 @@ void Config::parseAction(ConfigReadContext& s, const std::string& name,
throw XConfigRead(s, "unknown screen name in switchToScreen");
}
if (args.size() == 3) {
// Parse coordinates
int x, y;
try {
x = std::stoi(args[1]);
y = std::stoi(args[2]);
} catch (const std::exception&) {
throw XConfigRead(s, "invalid coordinates in switchToScreen");
}
action = new InputFilter::SwitchToScreenAction(m_events, screen, x, y);
} else {
action = new InputFilter::SwitchToScreenAction(m_events, screen);
}
}
else if (name == "toggleScreen") {
action = new InputFilter::ToggleScreenAction(m_events);

View File

@ -322,6 +322,20 @@ InputFilter::LockCursorToScreenAction::perform(const Event& event)
InputFilter::SwitchToScreenAction::SwitchToScreenAction(IEventQueue* events,
const std::string& screen) :
m_screen(screen),
m_hasCustomPosition(false),
m_x(0),
m_y(0),
m_events(events)
{
// do nothing
}
InputFilter::SwitchToScreenAction::SwitchToScreenAction(IEventQueue* events,
const std::string& screen, int x, int y) :
m_screen(screen),
m_hasCustomPosition(true),
m_x(x),
m_y(y),
m_events(events)
{
// do nothing
@ -332,15 +346,38 @@ std::string InputFilter::SwitchToScreenAction::getScreen() const
return m_screen;
}
bool InputFilter::SwitchToScreenAction::hasCustomPosition() const
{
return m_hasCustomPosition;
}
int InputFilter::SwitchToScreenAction::getX() const
{
return m_x;
}
int InputFilter::SwitchToScreenAction::getY() const
{
return m_y;
}
InputFilter::Action*
InputFilter::SwitchToScreenAction::clone() const
{
return new SwitchToScreenAction(*this);
if (m_hasCustomPosition) {
return new SwitchToScreenAction(m_events, m_screen, m_x, m_y);
} else {
return new SwitchToScreenAction(m_events, m_screen);
}
}
std::string InputFilter::SwitchToScreenAction::format() const
{
if (m_hasCustomPosition) {
return barrier::string::sprintf("switchToScreen(%s,%d,%d)", m_screen.c_str(), m_x, m_y);
} else {
return barrier::string::sprintf("switchToScreen(%s)", m_screen.c_str());
}
}
void
@ -356,8 +393,12 @@ InputFilter::SwitchToScreenAction::perform(const Event& event)
}
// send event
Server::SwitchToScreenInfo* info =
Server::SwitchToScreenInfo::alloc(screen);
Server::SwitchToScreenInfo* info;
if (m_hasCustomPosition) {
info = Server::SwitchToScreenInfo::alloc(screen, m_x, m_y);
} else {
info = Server::SwitchToScreenInfo::alloc(screen);
}
m_events->addEvent(Event(m_events->forServer().switchToScreen(),
event.getTarget(), info,
Event::kDeliverImmediately));

View File

@ -153,8 +153,12 @@ public:
class SwitchToScreenAction : public Action {
public:
SwitchToScreenAction(IEventQueue* events, const std::string& screen);
SwitchToScreenAction(IEventQueue* events, const std::string& screen, int x, int y);
std::string getScreen() const;
bool hasCustomPosition() const;
int getX() const;
int getY() const;
// Action overrides
virtual Action* clone() const;
@ -163,6 +167,9 @@ public:
private:
std::string m_screen;
bool m_hasCustomPosition;
int m_x;
int m_y;
IEventQueue* m_events;
};

View File

@ -1404,8 +1404,14 @@ Server::handleSwitchToScreenEvent(const Event& event, void*)
LOG((CLOG_DEBUG1 "screen \"%s\" not active", info->m_screen));
}
else {
if (info->m_hasCustomPosition) {
// Switch to specific coordinates
switchScreen(index->second, info->m_x, info->m_y, false);
} else {
// Use default behavior - jump to last cursor position
jumpToScreen(index->second);
}
}
}
void
@ -2329,6 +2335,22 @@ Server::SwitchToScreenInfo::alloc(const std::string& screen)
SwitchToScreenInfo* info =
(SwitchToScreenInfo*)malloc(sizeof(SwitchToScreenInfo) +
screen.size());
info->m_hasCustomPosition = false;
info->m_x = 0;
info->m_y = 0;
strcpy(info->m_screen, screen.c_str());
return info;
}
Server::SwitchToScreenInfo*
Server::SwitchToScreenInfo::alloc(const std::string& screen, SInt32 x, SInt32 y)
{
SwitchToScreenInfo* info =
(SwitchToScreenInfo*)malloc(sizeof(SwitchToScreenInfo) +
screen.size());
info->m_hasCustomPosition = true;
info->m_x = x;
info->m_y = y;
strcpy(info->m_screen, screen.c_str());
return info;
}

View File

@ -63,8 +63,12 @@ public:
class SwitchToScreenInfo {
public:
static SwitchToScreenInfo* alloc(const std::string& screen);
static SwitchToScreenInfo* alloc(const std::string& screen, SInt32 x, SInt32 y);
public:
bool m_hasCustomPosition;
SInt32 m_x;
SInt32 m_y;
// this is a C-string; this type is a variable size structure
char m_screen[1];
};