diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | data/org.ayatana.indicator.rotation_lock | 3 | ||||
-rw-r--r-- | src/main.cpp | 22 | ||||
-rw-r--r-- | src/rotation-lock.cpp | 49 |
4 files changed, 65 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e2eca2..6cff765 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,7 @@ find_package(PkgConfig REQUIRED) # glib... set(GLIB_MINIMUM 2.36) pkg_check_modules(SERVICE_DEPS REQUIRED + libayatana-common>=0.9.3 gio-unix-2.0>=${GLIB_MINIMUM} glib-2.0>=${GLIB_MINIMUM} gudev-1.0 diff --git a/data/org.ayatana.indicator.rotation_lock b/data/org.ayatana.indicator.rotation_lock index 7297e12..050f1a0 100644 --- a/data/org.ayatana.indicator.rotation_lock +++ b/data/org.ayatana.indicator.rotation_lock @@ -8,3 +8,6 @@ ObjectPath=/org/ayatana/indicator/rotation_lock/phone [phone_greeter] ObjectPath=/org/ayatana/indicator/rotation_lock/phone + +[desktop] +ObjectPath=/org/ayatana/indicator/rotation_lock/desktop diff --git a/src/main.cpp b/src/main.cpp index aaa069d..004b21d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,11 @@ #include <locale.h> +extern "C" +{ + #include <ayatana/common/utils.h> +} + int main(int /*argc*/, char** /*argv*/) { @@ -58,13 +63,16 @@ main(int /*argc*/, char** /*argv*/) exporters.push_back(exporter); } - // We need the ADBD handler running, - // even though it doesn't have an indicator component yet - static constexpr char const * ADB_SOCKET_PATH {"/dev/socket/adbd"}; - static constexpr char const * PUBLIC_KEYS_FILENAME {"/data/misc/adb/adb_keys"}; - auto usb_monitor = std::make_shared<GUDevUsbMonitor>(); - auto greeter = std::make_shared<Greeter>(); - UsbManager usb_manager {ADB_SOCKET_PATH, PUBLIC_KEYS_FILENAME, usb_monitor, greeter}; + if (ayatana_common_utils_is_lomiri()) + { + // We need the ADBD handler running, + // even though it doesn't have an indicator component yet + static constexpr char const * ADB_SOCKET_PATH {"/dev/socket/adbd"}; + static constexpr char const * PUBLIC_KEYS_FILENAME {"/data/misc/adb/adb_keys"}; + auto usb_monitor = std::make_shared<GUDevUsbMonitor>(); + auto greeter = std::make_shared<Greeter>(); + UsbManager usb_manager {ADB_SOCKET_PATH, PUBLIC_KEYS_FILENAME, usb_monitor, greeter}; + } // let's go! g_main_loop_run(loop); diff --git a/src/rotation-lock.cpp b/src/rotation-lock.cpp index 5cbbc60..a7d1f12 100644 --- a/src/rotation-lock.cpp +++ b/src/rotation-lock.cpp @@ -21,6 +21,11 @@ #include <glib/gi18n.h> +extern "C" +{ + #include <ayatana/common/utils.h> +} + class RotationLockIndicator::Impl { public: @@ -29,8 +34,15 @@ public: m_settings(g_settings_new(m_schema_name)), m_action_group(create_action_group()) { - // build the rotation lock icon - auto icon = g_themed_icon_new_with_default_fallbacks(m_rotation_lock_icon_name); + // build the icon + const char *rotation_lock_icon_name {"orientation-lock"}; + + if (!ayatana_common_utils_is_lomiri()) + { + rotation_lock_icon_name = "display"; + } + + auto icon = g_themed_icon_new_with_default_fallbacks(rotation_lock_icon_name); auto icon_deleter = [](GIcon* o){g_object_unref(G_OBJECT(o));}; m_icon.reset(icon, icon_deleter); @@ -39,6 +51,11 @@ public: std::shared_ptr<GMenuModel> phone_menu (create_phone_menu(), menu_model_deleter); m_phone = std::make_shared<SimpleProfile>("phone", phone_menu); update_phone_header(); + + // build the desktop profile + std::shared_ptr<GMenuModel> desktop_menu (create_desktop_menu(), menu_model_deleter); + m_desktop = std::make_shared<SimpleProfile>("desktop", desktop_menu); + update_desktop_header(); } ~Impl() @@ -57,6 +74,7 @@ public: { std::vector<std::shared_ptr<Profile>> ret; ret.push_back(m_phone); + ret.push_back(m_desktop); return ret; } @@ -130,6 +148,21 @@ private: return G_MENU_MODEL(menu); } + GMenuModel* create_desktop_menu() + { + GMenu* menu; + GMenuItem* menu_item; + + menu = g_menu_new(); + + menu_item = g_menu_item_new(_("Rotation Lock"), "indicator.rotation-lock"); + g_menu_item_set_attribute(menu_item, "x-ayatana-type", "s", "org.ayatana.indicator.switch"); + g_menu_append_item(menu, menu_item); + g_object_unref(menu_item); + + return G_MENU_MODEL(menu); + } + void update_phone_header() { Header h; @@ -140,6 +173,16 @@ private: m_phone->header().set(h); } + void update_desktop_header() + { + Header h; + h.title = _("Rotation"); + h.a11y = h.title; + h.is_visible = TRUE; + h.icon = m_icon; + m_desktop->header().set(h); + } + /*** **** ***/ @@ -149,10 +192,10 @@ private: #else static constexpr char const * m_schema_name {"org.ayatana.display"}; #endif - static constexpr char const * m_rotation_lock_icon_name {"orientation-lock"}; GSettings* m_settings = nullptr; GSimpleActionGroup* m_action_group = nullptr; std::shared_ptr<SimpleProfile> m_phone; + std::shared_ptr<SimpleProfile> m_desktop; std::shared_ptr<GIcon> m_icon; }; |