Ejemplo n.º 1
0
func (audio *Audio) setupMediaKeyMonitor() {
	mediaKeyManager, err := keybinding.NewMediaKey("com.deepin.daemon.KeyBinding", "/com/deepin/daemon/MediaKey")
	__keepMediakeyManagerAlive = mediaKeyManager
	if err != nil {
		logger.Error("Can't create com.deepin.daemon.Keybinding! mediakey support will be disabled", err)
	}

	mediaKeyManager.ConnectAudioMute(func(pressed bool) {
		if !pressed {
			sink := audio.GetDefaultSink()
			if sink == nil {
				logger.Error("Default Sink is nil", audio.DefaultSink)
				return
			}
			sink.SetMute(!sink.Mute)
		}
	})
	mediaKeyManager.ConnectAudioUp(func(pressed bool) {
		if !pressed {
			sink := audio.GetDefaultSink()
			if sink == nil {
				logger.Error("Default Sink is nil", audio.DefaultSink)
				return
			}
			if sink.Volume > 1 {
				logger.Warning("ignore add volume bigger than 100% when use MediaKey")
				return
			}
			playFeedbackWithDevice(sink.Name)

			if sink.Mute {
				sink.SetMute(false)
			}

			nv := sink.Volume + 0.1
			if nv > 1 {
				nv = 1
			}
			sink.SetVolume(nv, true)
		}
	})
	mediaKeyManager.ConnectAudioDown(func(pressed bool) {
		if !pressed {
			sink := audio.GetDefaultSink()
			if sink == nil {
				logger.Info("Default Sink is nil", audio.DefaultSink)
				return
			}
			if sink.Mute {
				sink.SetMute(false)
			}
			nv := sink.Volume - 0.1
			if nv < 0 {
				nv = 0
			}
			sink.SetVolume(nv, true)
			playFeedbackWithDevice(sink.Name)
		}
	})
}
Ejemplo n.º 2
0
func initializeLibs() error {
	var err error
	upower, err = libupower.NewUpower(UPOWER_BUS_NAME, "/org/freedesktop/UPower")
	if err != nil {
		logger.Warning("create dbus upower failed:", err)
		return err
	}
	login1, err = liblogin1.NewManager("org.freedesktop.login1", "/org/freedesktop/login1")
	if err != nil {
		logger.Warning("create dbus login1 failed:", err)
		finalizeLibs()
		return err
	}
	mediaKey, err = libkeybinding.NewMediaKey("com.deepin.daemon.KeyBinding", "/com/deepin/daemon/MediaKey")
	if err != nil {
		logger.Warning("create dbus mediaKey failed:", err)
		finalizeLibs()
		return err
	}
	notifier, err = libnotifications.NewNotifier("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
	if err != nil {
		logger.Warning("Can't build org.freedesktop.Notficaations:", err)
		finalizeLibs()
		return err
	}
	player, err = libsound.NewSound("com.deepin.api.Sound", "/com/deepin/api/Sound")
	if err != nil {
		logger.Warning("Can't build com.deepin.api.Sound:", err)
		finalizeLibs()
		return err
	}

	power = NewPower()
	return nil
}
Ejemplo n.º 3
0
func initDBusIFC() error {
	var err error

	dbusObj, err = libdbus.NewDBusDaemon("org.freedesktop.DBus",
		"/")
	if err != nil {
		logger.Error("New DBusDaemon Failed: ", err)
		return err
	}

	mediaKeyObj, err = libkeybind.NewMediaKey(
		"com.deepin.daemon.KeyBinding",
		"/com/deepin/daemon/MediaKey")
	if err != nil {
		logger.Error("New MediaKey Object Failed: ", err)
		return err
	}

	loginObj, err = liblogin1.NewManager("org.freedesktop.login1",
		"/org/freedesktop/login1")
	if err != nil {
		logger.Error("New Login1 Manager Failed: ", err)
		return err
	}

	return nil
}