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

Implement GET_BINDING_STATE message #200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion i3ipc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__author_email__, __license__, __copyright__)

from .replies import (BarConfigReply, CommandReply, ConfigReply, OutputReply, TickReply,
VersionReply, WorkspaceReply, SeatReply, InputReply)
VersionReply, WorkspaceReply, SeatReply, InputReply, BindingStateReply)
from .events import (BarconfigUpdateEvent, BindingEvent, BindingInfo, OutputEvent, ShutdownEvent,
WindowEvent, TickEvent, ModeEvent, WorkspaceEvent, InputEvent, Event)
from .con import Con
Expand Down
2 changes: 2 additions & 0 deletions i3ipc/_private/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MessageType(Enum):
GET_BINDING_MODES = 8
GET_CONFIG = 9
SEND_TICK = 10
GET_BINDING_STATE = 12
# sway-specific command types
GET_INPUTS = 100
GET_SEATS = 101
Expand All @@ -30,6 +31,7 @@ class ReplyType(Enum):
BINDING_MODES = 8
GET_CONFIG = 9
TICK = 10
BINDING_STATE = 12


class EventType(Enum):
Expand Down
12 changes: 11 additions & 1 deletion i3ipc/aio/connection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .._private import PubSub, MessageType, EventType, Synchronizer
from ..replies import (BarConfigReply, CommandReply, ConfigReply, OutputReply, TickReply,
VersionReply, WorkspaceReply, SeatReply, InputReply)
VersionReply, WorkspaceReply, SeatReply, InputReply, BindingStateReply)
from ..events import (IpcBaseEvent, BarconfigUpdateEvent, BindingEvent, OutputEvent, ShutdownEvent,
WindowEvent, TickEvent, ModeEvent, WorkspaceEvent, InputEvent, Event)
from .. import con
Expand Down Expand Up @@ -682,6 +682,16 @@ async def send_tick(self, payload: str = "") -> TickReply:
data = json.loads(data)
return TickReply(data)

async def get_binding_state(self) -> BindingStateReply:
"""Gets the name of the currently active binding mode.

:returns: A class containing the name of the currently active binding mode.
:rtype: :class:`i3ipc.BindingStateReply`
"""
data = await self._message(MessageType.GET_BINDING_STATE, '')
data = json.loads(data)
return BindingStateReply(data)

async def get_inputs(self) -> List[InputReply]:
"""(sway only) Gets the inputs connected to the compositor.

Expand Down
12 changes: 11 additions & 1 deletion i3ipc/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .con import Con
from .replies import (BarConfigReply, CommandReply, ConfigReply, OutputReply, TickReply,
VersionReply, WorkspaceReply, SeatReply, InputReply)
VersionReply, WorkspaceReply, SeatReply, InputReply, BindingStateReply)
from .events import (IpcBaseEvent, BarconfigUpdateEvent, BindingEvent, OutputEvent, ShutdownEvent,
WindowEvent, TickEvent, ModeEvent, WorkspaceEvent, InputEvent, Event)
from ._private import PubSub, MessageType, EventType, Synchronizer
Expand Down Expand Up @@ -349,6 +349,16 @@ def send_tick(self, payload: str = "") -> TickReply:
data = json.loads(data)
return TickReply(data)

def get_binding_state(self) -> BindingStateReply:
"""Gets the name of the currently active binding mode.

:returns: A class containing the name of the currently active binding mode.
:rtype: :class:`i3ipc.BindingStateReply`
"""
data = self._message(MessageType.GET_BINDING_STATE, '')
data = json.loads(data)
return BindingStateReply(data)

def _subscribe(self, events):
events_obj = []
if events & EventType.WORKSPACE.value:
Expand Down
15 changes: 15 additions & 0 deletions i3ipc/replies.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,21 @@ class TickReply(_BaseReply):
]


class BindingStateReply(_BaseReply):
"""A reply to the ``GET_BINDING_STATE`` message.

.. seealso:: https://i3wm.org/docs/ipc.html#_binding_state_reply

:ivar name: Name of the currently active binding mode.
:vartype name: str
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""
_members = [
('name', str),
]


class InputReply(_BaseReply):
"""(sway only) A reply to ``GET_INPUTS`` message.

Expand Down
18 changes: 18 additions & 0 deletions test/aio/test_get_binding_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from .ipctest import IpcTest
import i3ipc

import pytest


class TestBindingState(IpcTest):
@pytest.mark.asyncio
async def test_binding_state(self, i3):
binding_state = await i3.get_binding_state()
assert isinstance(binding_state, i3ipc.BindingStateReply)

await i3.command('mode default')
binding_state = await i3.get_binding_state()
assert binding_state.name == 'default'
await i3.command('mode resize')
binding_state = await i3.get_binding_state()
assert binding_state.name == 'resize'
15 changes: 15 additions & 0 deletions test/test_get_binding_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from ipctest import IpcTest
import i3ipc


class TestBindingState(IpcTest):
def test_binding_state(self, i3):
binding_state = i3.get_binding_state()
assert isinstance(binding_state, i3ipc.BindingStateReply)

i3.command('mode "default"')
binding_state = i3.get_binding_state()
assert binding_state.name == 'default'
i3.command('mode "resize"')
binding_state = i3.get_binding_state()
assert binding_state.name == 'resize'