Skip to content

Commit

Permalink
Go fullscreen by dbus
Browse files Browse the repository at this point in the history
  • Loading branch information
quite authored and multani committed Nov 28, 2011
1 parent 183c39c commit c839888
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.rst
Expand Up @@ -61,6 +61,9 @@ Currently, the following things have been changed since the Berlios's version:


This is the `refactor-launcher` branch. This is the `refactor-launcher` branch.


* "Daniel <quite@hack.org>" added support to toggle fullscreen status from the
command line.



Personal todo list Personal todo list
------------------ ------------------
Expand Down
13 changes: 8 additions & 5 deletions sonata/cli.py
Expand Up @@ -22,7 +22,7 @@ def parse(self, argv):
Separates options and arguments from the given argument list, Separates options and arguments from the given argument list,
checks their validity.""" checks their validity."""


# toggle and popup need d-bus and don't always need gui # toggle and popup and fullscreen need d-bus and don't always need gui
# version and help don't need anything and exit without gui # version and help don't need anything and exit without gui
# hidden and visible are only applicable when gui is launched # hidden and visible are only applicable when gui is launched
# profile and no-start don't need anything # profile and no-start don't need anything
Expand All @@ -47,8 +47,10 @@ def parse(self, argv):
help=_("popup song notification (requires D-Bus)")) help=_("popup song notification (requires D-Bus)"))
parser.add_option("-t", "--toggle", dest="toggle", parser.add_option("-t", "--toggle", dest="toggle",
action="store_true", action="store_true",
help=_(('toggles whether the app is minimized to the ' help=_("toggles whether the app is minimized to the tray or visible (requires D-Bus)"))
'tray or visible (requires D-Bus)'))) parser.add_option("-f", "--fullscreen", dest="fullscreen",
action="store_true",
help=_("go fullscreen (requires D-Bus)"))
parser.add_option("-n", "--no-start", dest="start", parser.add_option("-n", "--no-start", dest="start",
action="store_false", action="store_false",
help=_("don't start app if D-Bus commands fail")) help=_("don't start app if D-Bus commands fail"))
Expand All @@ -65,7 +67,7 @@ def parse(self, argv):


if options.toggle: if options.toggle:
options.start_visibility = True options.start_visibility = True
if options.popup and options.start_visibility is None: if options.popup or options.fullscreen and options.start_visibility is None:
options.start_visibility = False options.start_visibility = False
self.start_visibility = options.start_visibility self.start_visibility = options.start_visibility
self.arg_profile = options.profile self.arg_profile = options.profile
Expand All @@ -76,14 +78,15 @@ def parse(self, argv):
else: else:
parser.error(_("unknown command %s") % cmd) parser.error(_("unknown command %s") % cmd)


if options.toggle or options.popup: if options.toggle or options.popup or options.fullscreen:
import dbus_plugin as dbus import dbus_plugin as dbus
if not dbus.using_dbus(): if not dbus.using_dbus():
print _("toggle and popup options require D-Bus. Aborting.") print _("toggle and popup options require D-Bus. Aborting.")
sys.exit(1) sys.exit(1)


dbus.execute_remote_commands(options.toggle, dbus.execute_remote_commands(options.toggle,
options.popup, options.popup,
options.fullscreen,
options.start) options.start)


def execute_cmds(self): def execute_cmds(self):
Expand Down
14 changes: 11 additions & 3 deletions sonata/dbus_plugin.py
Expand Up @@ -12,7 +12,7 @@
Example usage: Example usage:
import dbus_plugin as dbus import dbus_plugin as dbus
self.dbus_service = dbus.SonataDBus(self.dbus_show, self.dbus_toggle, self.dbus_service = dbus.SonataDBus(self.dbus_show, self.dbus_toggle,
self.dbus_popup) self.dbus_popup, self.dbus_fullscreen)
dbus.start_dbus_interface(toggle_arg, popup_arg) dbus.start_dbus_interface(toggle_arg, popup_arg)
dbus.init_gnome_mediakeys(self.mpd_pp, self.mpd_stop, self.mpd_prev, dbus.init_gnome_mediakeys(self.mpd_pp, self.mpd_stop, self.mpd_prev,
self.mpd_next) self.mpd_next)
Expand Down Expand Up @@ -106,14 +106,17 @@ def get_session_bus():
raise raise




def execute_remote_commands(toggle=False, popup=False, start=False): def execute_remote_commands(toggle=False, popup=False, fullscreen=False,
start=False):
try: try:
bus = get_session_bus() bus = get_session_bus()
obj = bus.get_object('org.MPD', '/org/MPD/Sonata') obj = bus.get_object('org.MPD', '/org/MPD/Sonata')
if toggle: if toggle:
obj.toggle(dbus_interface='org.MPD.SonataInterface') obj.toggle(dbus_interface='org.MPD.SonataInterface')
if popup: if popup:
obj.popup(dbus_interface='org.MPD.SonataInterface') obj.popup(dbus_interface='org.MPD.SonataInterface')
if fullscreen:
obj.fullscreen(dbus_interface='org.MPD.SonataInterface')
sys.exit() sys.exit()
except Exception: except Exception:
print _("Failed to execute remote commands.") print _("Failed to execute remote commands.")
Expand Down Expand Up @@ -158,10 +161,11 @@ def start_dbus_interface():


class SonataDBus(dbus.service.Object): class SonataDBus(dbus.service.Object):


def __init__(self, dbus_show, dbus_toggle, dbus_popup): def __init__(self, dbus_show, dbus_toggle, dbus_popup, dbus_fullscreen):
self.dbus_show = dbus_show self.dbus_show = dbus_show
self.dbus_toggle = dbus_toggle self.dbus_toggle = dbus_toggle
self.dbus_popup = dbus_popup self.dbus_popup = dbus_popup
self.dbus_fullscreen = dbus_fullscreen
session_bus = get_session_bus() session_bus = get_session_bus()
bus_name = dbus.service.BusName('org.MPD', bus=session_bus) bus_name = dbus.service.BusName('org.MPD', bus=session_bus)
object_path = '/org/MPD/Sonata' object_path = '/org/MPD/Sonata'
Expand All @@ -178,3 +182,7 @@ def toggle(self):
@dbus.service.method('org.MPD.SonataInterface') @dbus.service.method('org.MPD.SonataInterface')
def popup(self): def popup(self):
self.dbus_popup() self.dbus_popup()

@dbus.service.method('org.MPD.SonataInterface')
def fullscreen(self):
self.dbus_fullscreen()
6 changes: 5 additions & 1 deletion sonata/main.py
Expand Up @@ -134,7 +134,8 @@ def __init__(self, args, window=None, _sugar=False):
try: try:
self.dbus_service = dbus.SonataDBus(self.dbus_show, self.dbus_service = dbus.SonataDBus(self.dbus_show,
self.dbus_toggle, self.dbus_toggle,
self.dbus_popup) self.dbus_popup,
self.dbus_fullscreen)
except Exception: except Exception:
pass pass
dbus.start_dbus_interface() dbus.start_dbus_interface()
Expand Down Expand Up @@ -3563,5 +3564,8 @@ def dbus_toggle(self):
def dbus_popup(self): def dbus_popup(self):
self.on_currsong_notify(force_popup=True) self.on_currsong_notify(force_popup=True)


def dbus_fullscreen(self):
self.fullscreen_cover_art(None)

def main(self): def main(self):
gtk.main() gtk.main()

0 comments on commit c839888

Please sign in to comment.