func (m *Manager) newAccessPoint(devPath, apPath dbus.ObjectPath) (ap *accessPoint, err error) { nmAp, err := nmNewAccessPoint(apPath) if err != nil { return } ap = &accessPoint{ nmAp: nmAp, devPath: devPath, Path: apPath, } ap.updateProps() if len(ap.Ssid) == 0 { err = fmt.Errorf("ignore hidden access point") return } // connect properties changed signals ap.nmAp.ConnectPropertiesChanged(func(properties map[string]dbus.Variant) { if !m.isAccessPointExists(apPath) { return } m.accessPointsLock.Lock() defer m.accessPointsLock.Unlock() ap.updateProps() apJSON, _ := marshalJSON(ap) dbus.Emit(m, "AccessPointPropertiesChanged", string(devPath), apJSON) }) apJSON, _ := marshalJSON(ap) dbus.Emit(m, "AccessPointAdded", string(devPath), apJSON) return }
func grabKeyboardAndMouse(m *Manager) { if m == nil { return } //go func() { X, err := xgbutil.NewConn() if err != nil { logger.Info("Get New Connection Failed:", err) return } keybind.Initialize(X) mousebind.Initialize(X) err = keybind.GrabKeyboard(X, X.RootWin()) if err != nil { logger.Info("Grab Keyboard Failed:", err) return } grabAllMouseButton(X) xevent.ButtonPressFun( func(X *xgbutil.XUtil, e xevent.ButtonPressEvent) { dbus.Emit(m, "KeyReleaseEvent", "") ungrabAllMouseButton(X) keybind.UngrabKeyboard(X) logger.Info("Button Press Event") xevent.Quit(X) }).Connect(X, X.RootWin()) xevent.KeyPressFun( func(X *xgbutil.XUtil, e xevent.KeyPressEvent) { value := parseKeyEnvent(X, e.State, e.Detail) pressKeyStr = value dbus.Emit(m, "KeyPressEvent", value) }).Connect(X, X.RootWin()) xevent.KeyReleaseFun( func(X *xgbutil.XUtil, e xevent.KeyReleaseEvent) { if strings.ToLower(pressKeyStr) == "super_l" || strings.ToLower(pressKeyStr) == "super_r" { pressKeyStr = "Super" } dbus.Emit(m, "KeyReleaseEvent", pressKeyStr) pressKeyStr = "" ungrabAllMouseButton(X) keybind.UngrabKeyboard(X) logger.Infof("Key: %s\n", pressKeyStr) xevent.Quit(X) }).Connect(X, X.RootWin()) xevent.Main(X) //}() }
func (self *Launcher) RequestUninstall(id string, purge bool) { go func(id ItemId) { logger.Warning("uninstall", id) err := self.itemManager.UninstallItem(id, purge, time.Minute*20) if err == nil { dbus.Emit(self, "UninstallSuccess", id) return } dbus.Emit(self, "UninstallFailed", id, err.Error()) }(ItemId(id)) }
func (self *Launcher) RequestRemoveFromDesktop(id string) bool { itemId := ItemId(id) if filepath.IsAbs(id) { dbus.Emit(self, "RemoveFromDesktopFailed", itemId, "app id is expected") return false } if err := self.itemManager.RemoveItemFromDesktop(itemId); err != nil { dbus.Emit(self, "RemoveFromDesktopFailed", itemId, err.Error()) return false } dbus.Emit(self, "RemoveFromDesktopSuccess", itemId) return true }
func (m *DockedAppManager) Dock(id, title, icon, cmd string) bool { idElement := m.findItem(id) if idElement != nil { logger.Info(id, "is already docked.") return false } id = strings.ToLower(id) idElement = m.findItem(id) if idElement != nil { logger.Info(id, "is already docked.") return false } logger.Debug("id", id, "title", title, "cmd", cmd) desktopID := guess_desktop_id(id) if desktopID == "" { m.items.PushBack(id) if e := createScratchFile(id, title, icon, cmd); e != nil { logger.Warning("create scratch file failed:", e) return false } } else { id = trimDesktop(desktopID) m.items.PushBack(id) } dbus.Emit(m, "Docked", id) app := ENTRY_MANAGER.runtimeApps[id] if app != nil { app.buildMenu() } return true }
func (media *MediaMount) listenGSettings() { media.settings.Connect("changed::autorun-x-content-ignore", func(s *gio.Settings, key string) { dbus.Emit(media, "MediaActionChanged") }) media.settings.Connect("changed::autorun-x-content-open-folder", func(s *gio.Settings, key string) { dbus.Emit(media, "MediaActionChanged") }) media.settings.Connect("changed::autorun-x-content-start-app", func(s *gio.Settings, key string) { dbus.Emit(media, "MediaActionChanged") }) }
func (m *TrayManager) addTrayIcon(xid xproto.Window) { m.checkValid() for _, id := range m.TrayIcons { if xproto.Window(id) == xid { return } } if d, err := damage.NewDamageId(TrayXU.Conn()); err != nil { return } else { m.dmageInfo[xid] = d if err := damage.CreateChecked(TrayXU.Conn(), d, xproto.Drawable(xid), damage.ReportLevelRawRectangles).Check(); err != nil { logger.Debug("DamageCreate Failed:", err) return } } composite.RedirectWindow(TrayXU.Conn(), xid, composite.RedirectAutomatic) m.TrayIcons = append(m.TrayIcons, uint32(xid)) icon := xwindow.New(TrayXU, xid) icon.Listen(xproto.EventMaskVisibilityChange | damage.Notify | xproto.EventMaskStructureNotify) icon.Change(xproto.CwBackPixel, 0) name, err := ewmh.WmNameGet(TrayXU, xid) if err != nil { logger.Debug("WmNameGet failed:", err, xid) } m.nameInfo[xid] = name m.notifyInfo[xid] = true dbus.Emit(m, "Added", uint32(xid)) logger.Infof("Added try icon: \"%s\"(%d)", name, uint32(xid)) }
func triggerSigErr(pid uint32, action, reason string) { if _m == nil { return } dbus.Emit(_m, "Error", pid, action, reason) }
func (m *EntryProxyerManager) registerEntry(name string) { if !isEntryNameValid(name) { return } logger.Debugf("register entry: %s", name) entryId, ok := getEntryId(name) if !ok { return } logger.Debugf("register entry id: %s", entryId) entry, err := NewEntryProxyer(entryId) if err != nil { logger.Warningf("register entry failed: %v", err) return } err = dbus.InstallOnSession(entry) if err != nil { logger.Warningf("register entry failed: %v", err) return } m.Entries = append(m.Entries, entry) dbus.Emit(m, "Added", dbus.ObjectPath(entry.GetDBusInfo().ObjectPath)) logger.Infof("register entry success: %s", name) }
func (m *TrayManager) RetryManager() { m.Unmanage() m.Manage() for _, icon := range m.TrayIcons { dbus.Emit(m, "Added", icon) } }
func (m *TrayManager) handleTrayDamage(xid xproto.Window) { if m.notifyInfo[xid] { if md5 := icon2md5(xid); !md5Equal(m.md5Info[xid], md5) { m.md5Info[xid] = md5 dbus.Emit(m, "Changed", uint32(xid)) logger.Debugf("handleTrayDamage: %s(%d) changed (%v)", m.nameInfo[xid], xid, md5) } } }
func (a *agent) createPendingKey(connectionData map[string]map[string]dbus.Variant, keyId mapKey) chan string { autoConnect := nmGeneralGetConnectionAutoconnect(keyId.path) connectionId := getSettingConnectionId(connectionData) logger.Debug("createPendingKey:", keyId, connectionId, autoConnect) a.pendingKeys[keyId] = make(chan string) dbus.Emit(manager, "NeedSecrets", string(keyId.path), keyId.name, connectionId, autoConnect) return a.pendingKeys[keyId] }
func (self *Launcher) MarkLaunched(id string) { err := self.itemManager.MarkLaunched(ItemId(id)) if err != nil { logger.Info(err) return } dbus.Emit(self, "NewAppLaunched", ItemId(id)) }
func (c *config) setDeviceEnabled(devPath dbus.ObjectPath, enabled bool) { devConfig, err := c.getDeviceConfigForPath(devPath) if err != nil { return } devConfig.Enabled = enabled dbus.Emit(manager, "DeviceEnabled", string(devPath), enabled) c.save() }
func (m *Manager) handleUserDeleted(list []string) { var paths = m.UserList for _, p := range list { m.uninstallUser(p) paths = deleteStrFromList(p, paths) dbus.Emit(m, "UserDeleted", p) } m.setPropUserList(paths) }
func (ss *ScreenSaver) loop() { for { e, err := ss.xu.Conn().WaitForEvent() if err != nil { continue } switch ee := e.(type) { case screensaver.NotifyEvent: switch ee.State { case screensaver.StateCycle: dbus.Emit(ss, "CycleActive") case screensaver.StateOn: dbus.Emit(ss, "IdleOn") case screensaver.StateOff: dbus.Emit(ss, "IdleOff") } } } }
func (dapp *DefaultApps) handleMimeFileChanged(ev *fsnotify.FileEvent) { if ev == nil { return } if ev.IsDelete() { if dapp.watcher != nil { dapp.watcher.ResetFileListWatch() } } else { dbus.Emit(dapp, "DefaultAppChanged") } }
func (m *Manager) ejectVolume(uuid string, volume *gio.Volume) { volume.Eject(gio.MountUnmountFlagsNone, nil, gio.AsyncReadyCallback( func(o *gobject.Object, res *gio.AsyncResult) { if volume == nil || volume.Object.C == nil { return } _, err := volume.EjectFinish(res) if err != nil { dbus.Emit(m, "Error", uuid, err.Error()) } })) }
func (m *Manager) unmountMount(uuid string, mount *gio.Mount) { mount.Unmount(gio.MountUnmountFlagsNone, nil, gio.AsyncReadyCallback( func(o *gobject.Object, res *gio.AsyncResult) { if mount == nil || mount.Object.C == nil { return } _, err := mount.UnmountFinish(res) if err != nil { dbus.Emit(m, "Error", uuid, err.Error()) } })) }
func (m *TrayManager) removeTrayIcon(xid xproto.Window) { delete(m.dmageInfo, xid) delete(m.nameInfo, xid) delete(m.notifyInfo, xid) delete(m.md5Info, xid) var newIcons []uint32 for _, id := range m.TrayIcons { if id != uint32(xid) { newIcons = append(newIcons, id) } } m.TrayIcons = newIcons dbus.Emit(m, "Removed", uint32(xid)) }
func (m *HideStateManager) ToggleShow() { logger.Info("cancel ToggleShow on ToggleShow") m.CancelToggleShow() if m.state == HideStateHidden || m.state == HideStateHidding { dbus.Emit(m, "ChangeState", TriggerShow) } else if m.state == HideStateShown || m.state == HideStateShowing { dbus.Emit(m, "ChangeState", TriggerHide) } m.toggleShowTimer = time.After(time.Second * 3) go func() { select { case <-m.toggleShowTimer: logger.Info("ToggleShow is done") m.toggleShowTimer = nil m.UpdateState() case <-m.cleanToggleShowChan: logger.Info("ToggleShow is cancelled") return } }() }
func (s *ConnectionSession) setProps() { s.setPropType() s.setPropAllowDelete() s.setPropAvailableVirtualSections() s.setPropAvailableSections() s.setPropAvailableKeys() s.setPropErrors() // notify connection data changed at end, for that this was used // by font-end to update widget value that with proeprty // "alwaysUpdate", which should only update value when visible, so // it depends on "AvailableSections" and "AvailableKeys" dbus.Emit(s, "ConnectionDataChanged") }
func NewSetting(core SettingCoreInterface) (*Setting, error) { if core == nil { return nil, errors.New("get failed") } s := &Setting{ core: core, } s.listenSettingChange(CategoryDisplayModeKey, func(setting *gio.Settings, key string) { _newValue := int64(setting.GetEnum(key)) newValue := CategoryDisplayMode(_newValue) s.lock.Lock() defer s.lock.Unlock() if newValue != s.categoryDisplayMode { s.categoryDisplayMode = newValue dbus.Emit(s, "CategoryDisplayModeChanged", _newValue) } }) s.listenSettingChange(SortMethodkey, func(setting *gio.Settings, key string) { _newValue := int64(setting.GetEnum(key)) newValue := SortMethod(_newValue) s.lock.Lock() defer s.lock.Unlock() if newValue != s.sortMethod { s.sortMethod = newValue dbus.Emit(s, "SortMethodChanged", _newValue) } }) // at least one read operation must be called after signal connected, otherwise, // the signal connection won't work from glib 2.43. // NB: https://github.com/GNOME/glib/commit/8ff5668a458344da22d30491e3ce726d861b3619 s.categoryDisplayMode = CategoryDisplayMode(core.GetEnum(CategoryDisplayModeKey)) s.sortMethod = SortMethod(core.GetEnum(SortMethodkey)) return s, nil }
func (m *Manager) handleUserAdded(list []string) { var paths = m.UserList for _, p := range list { err := m.installUserByPath(p) if err != nil { logger.Errorf("Install user '%s' failed: %v", p, err) continue } paths = append(paths, p) dbus.Emit(m, "UserAdded", p) } m.setPropUserList(paths) }
func (a *XMouseAreaProxyer) connectHandler(callback func(int32, int32, string)) func(x, y int32, id string) { return func(x, y int32, id string) { a.lock.Lock() if !a.idValid || id != a.areaId { if !a.idValid { dbus.Emit(a, "InvalidId") } logger.Debugf("valid: %v, event id: %v, areaId: %v", a.idValid, id, a.areaId) a.lock.Unlock() return } a.lock.Unlock() callback(x, y, id) } }
func (m *Manager) DeviceUnmount(uuid string) (bool, error) { value := m.getDiskCache(uuid) if value == nil { var reason = fmt.Sprintf("Unmount failed: invalid id '%s'", uuid) dbus.Emit(m, "Error", uuid, reason) return false, fmt.Errorf(reason) } switch value.Type { case diskTypeMount: mount := value.Obj.(*gio.Mount) m.unmountMount(uuid, mount) } return true, nil }
func (lang *LangSelector) handleLocaleChanged(ok bool, reason string) error { if !ok || lang.LocaleState != LocaleStateChanging { return ErrLocaleChangeFailed } err := writeUserLocale(lang.CurrentLocale) if err != nil { return err } err = i18n_dependency.InstallDependentPackages(lang.CurrentLocale) if err != nil { lang.logger.Warning(err) } dbus.Emit(lang, "Changed", lang.CurrentLocale) return nil }
func (m *EntryProxyerManager) unregisterEntry(name string) { if !isEntryNameValid(name) { return } logger.Debugf("unregister entry: %s", name) entryId, ok := getEntryId(name) if !ok { return } logger.Debugf("unregister entry id: %s", entryId) // find the index index := -1 var entry *EntryProxyer = nil for i, e := range m.Entries { if e.entryId == entryId { index = i entry = e break } } if index < 0 { logger.Warningf("slice out of bounds, entry len: %d, index: %d", len(m.Entries), index) return } logger.Debugf("entry len: %d, index: %d", len(m.Entries), index) if entry != nil { dbus.UnInstallObject(entry) } // remove the entry from slice copy(m.Entries[index:], m.Entries[index+1:]) m.Entries[len(m.Entries)-1] = nil m.Entries = m.Entries[:len(m.Entries)-1] dbus.Emit(m, "Removed", entry.Id) logger.Infof("unregister entry success: %s", name) }
func (self *Launcher) Search(key string) { close(self.cancelSearchingChan) self.cancelSearchingChan = make(chan struct{}) go func() { resultChan := make(chan SearchResult) transaction, err := NewSearchTransaction(self.pinyinObj, resultChan, self.cancelSearchingChan, 0) if err != nil { return } dataSet := self.itemManager.GetAllItems() go func() { transaction.Search(key, dataSet) close(resultChan) }() select { case <-self.cancelSearchingChan: return default: resultMap := map[ItemId]SearchResult{} for result := range resultChan { resultMap[result.Id] = result } var res SearchResultList for _, data := range resultMap { res = append(res, data) } sort.Sort(res) itemIds := []ItemId{} for _, data := range res { itemIds = append(itemIds, data.Id) } dbus.Emit(self, "SearchDone", itemIds) } }() }
func (m *DockedAppManager) doUndock(id string) bool { removeItem := m.findItem(id) if removeItem == nil { logger.Warning("not find docked app:", id) return false } logger.Info("Undock", id) logger.Info("Remove", m.items.Remove(removeItem)) m.core.SetStrv(DockedApps, m.toSlice()) gio.SettingsSync() os.Remove(filepath.Join(scratchDir, id+".desktop")) os.Remove(filepath.Join(scratchDir, id+".sh")) os.Remove(filepath.Join(scratchDir, id+".png")) dbus.Emit(m, "Undocked", removeItem.Value.(string)) app := ENTRY_MANAGER.runtimeApps[id] if app != nil { app.buildMenu() } return true }