aboutsummaryrefslogtreecommitdiff
path: root/src/service.cpp
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2024-07-16 08:52:18 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2024-07-16 08:52:18 +0200
commitd99008b235f98492128c9a1b19b4bb7b1a324720 (patch)
tree1558c68f4bf69efc1d924753be23df0b119daee5 /src/service.cpp
parent490a62b1b93bbe5d4939db45c659f94a4bd62113 (diff)
parent362422cad3f13f270f1c50d7c6d2010c5ad2f542 (diff)
downloadayatana-indicator-display-d99008b235f98492128c9a1b19b4bb7b1a324720.tar.gz
ayatana-indicator-display-d99008b235f98492128c9a1b19b4bb7b1a324720.tar.bz2
ayatana-indicator-display-d99008b235f98492128c9a1b19b4bb7b1a324720.zip
Merge branch 'tari01-pr/panic-warning'
Attributes GH PR #102: https://github.com/AyatanaIndicators/ayatana-indicator-display/pull/102
Diffstat (limited to 'src/service.cpp')
-rw-r--r--src/service.cpp269
1 files changed, 140 insertions, 129 deletions
diff --git a/src/service.cpp b/src/service.cpp
index 82afe51..43bf9d6 100644
--- a/src/service.cpp
+++ b/src/service.cpp
@@ -77,72 +77,77 @@ public:
if (!this->bTest)
{
- Display *pDisplay = XOpenDisplay (NULL);
+ // Check if we are on Wayland
+ const gchar *sWayland = g_getenv ("WAYLAND_DISPLAY");
+ this->bXsctUnsupported = (sWayland != NULL);
+ //~Check if we are on Wayland
- if (!pDisplay)
+ // Check if we are in a virtual environment
+ if (!this->bXsctUnsupported)
{
- g_error ("Panic: Failed to open X display");
+ Display *pDisplay = XOpenDisplay (NULL);
- return;
- }
+ if (!pDisplay)
+ {
+ g_warning ("Panic: Failed to open X display while checking for virtual environment");
+ }
+ else
+ {
+ guint nScreen = DefaultScreen (pDisplay);
+ Window pWindow = RootWindow (pDisplay, nScreen);
+ XRRScreenResources *pResources = XRRGetScreenResources (pDisplay, pWindow);
- guint nScreen = DefaultScreen (pDisplay);
- Window pWindow = RootWindow (pDisplay, nScreen);
- XRRScreenResources *pResources = XRRGetScreenResources (pDisplay, pWindow);
+ if (!pResources)
+ {
+ g_warning ("Panic: Failed to get screen resources while checking for virtual environment");
+ XCloseDisplay (pDisplay);
+ }
+ else
+ {
+ RROutput nOutputPrimary = XRRGetOutputPrimary (pDisplay, pWindow);
+ XRROutputInfo *pOutputInfo = XRRGetOutputInfo (pDisplay, pResources, nOutputPrimary);
+ GRegex *pRegex = NULL;
+ GError *pError = NULL;
- if (!pResources)
- {
- g_error ("Panic: Failed to get screen resources");
- XCloseDisplay (pDisplay);
+ #if GLIB_CHECK_VERSION(2, 73, 0)
+ pRegex = g_regex_new (".*virtual.*", G_REGEX_CASELESS, G_REGEX_MATCH_DEFAULT, &pError);
+ #else
+ pRegex = g_regex_new (".*virtual.*", G_REGEX_CASELESS, (GRegexMatchFlags) 0, &pError);
+ #endif
- return;
- }
+ if (!pError)
+ {
+ #if GLIB_CHECK_VERSION(2, 73, 0)
+ gboolean bMatch = g_regex_match (pRegex, pOutputInfo->name, G_REGEX_MATCH_DEFAULT, NULL);
+ #else
+ gboolean bMatch = g_regex_match (pRegex, pOutputInfo->name, (GRegexMatchFlags) 0, NULL);
+ #endif
- RROutput nOutputPrimary = XRRGetOutputPrimary (pDisplay, pWindow);
- XRROutputInfo *pOutputInfo = XRRGetOutputInfo (pDisplay, pResources, nOutputPrimary);
- GRegex *pRegex = NULL;
- GError *pError = NULL;
+ if (bMatch)
+ {
+ this->bXsctUnsupported = TRUE;
+ }
- #if GLIB_CHECK_VERSION(2, 73, 0)
- pRegex = g_regex_new (".*virtual.*", G_REGEX_CASELESS, G_REGEX_MATCH_DEFAULT, &pError);
- #else
- pRegex = g_regex_new (".*virtual.*", G_REGEX_CASELESS, (GRegexMatchFlags) 0, &pError);
- #endif
+ g_regex_unref (pRegex);
+ }
+ else
+ {
+ g_warning ("PANIC: Failed to compile regex: %s", pError->message);
+ g_error_free (pError);
+ }
- if (!pError)
- {
- #if GLIB_CHECK_VERSION(2, 73, 0)
- gboolean bMatch = g_regex_match (pRegex, pOutputInfo->name, G_REGEX_MATCH_DEFAULT, NULL);
- #else
- gboolean bMatch = g_regex_match (pRegex, pOutputInfo->name, (GRegexMatchFlags) 0, NULL);
- #endif
+ XRRFreeOutputInfo (pOutputInfo);
+ XRRFreeScreenResources (pResources);
+ XCloseDisplay (pDisplay);
- if (bMatch)
- {
- this->bVirtualX = TRUE;
+ #ifdef RDA_ENABLED
+ gboolean bRemote = rda_session_is_remote ();
+ this->bXsctUnsupported = this->bXsctUnsupported || bRemote;
+ #endif
+ }
}
-
- g_regex_unref (pRegex);
}
- else
- {
- g_error ("PANIC: Failed to compile regex: %s", pError->message);
- g_error_free (pError);
- XRRFreeOutputInfo (pOutputInfo);
- XRRFreeScreenResources (pResources);
- XCloseDisplay (pDisplay);
-
- return;
- }
-
- XRRFreeOutputInfo (pOutputInfo);
- XRRFreeScreenResources (pResources);
- XCloseDisplay (pDisplay);
-
- #ifdef RDA_ENABLED
- gboolean bRemote = rda_session_is_remote ();
- this->bVirtualX = this->bVirtualX || bRemote;
- #endif
+ //~Check if we are in a virtual environment
}
#endif
const char *sUserName = g_get_user_name();
@@ -162,9 +167,8 @@ public:
}
else
{
- g_error("No schema could be found");
+ g_error ("Panic: No com.lomiri.touch.system schema could be found");
}
-
}
else {
@@ -177,7 +181,7 @@ public:
}
else
{
- g_error("No schema could be found");
+ g_error ("Panic: No org.ayatana.indicator.display schema could be found");
}
#ifdef COLOR_TEMP_ENABLED
@@ -216,11 +220,11 @@ public:
if (pSchema != NULL)
{
g_settings_schema_unref (pSchema);
- pThemeSettings = g_settings_new (sSchema);
+ this->pThemeSettings = g_settings_new (sSchema);
}
else
{
- g_error("No %s schema could be found", sSchema);
+ g_warning ("Panic: No %s schema could be found", sSchema);
}
pSchema = g_settings_schema_source_lookup (pSource, sCursorSchema, TRUE);
@@ -228,11 +232,11 @@ public:
if (pSchema != NULL)
{
g_settings_schema_unref (pSchema);
- pCursorSettings = g_settings_new (sCursorSchema);
+ this->pCursorSettings = g_settings_new (sCursorSchema);
}
else
{
- g_error("No %s schema could be found", sCursorSchema);
+ g_warning ("Panic: No %s schema could be found", sCursorSchema);
}
pSchema = g_settings_schema_source_lookup (pSource, sMetacitySchema, TRUE);
@@ -240,11 +244,11 @@ public:
if (pSchema != NULL)
{
g_settings_schema_unref (pSchema);
- pMetacitySettings = g_settings_new (sMetacitySchema);
+ this->pMetacitySettings = g_settings_new (sMetacitySchema);
}
else
{
- g_error("No %s schema could be found", sMetacitySchema);
+ g_warning ("Panic: No %s schema could be found", sMetacitySchema);
}
if (this->bTest)
@@ -265,7 +269,7 @@ public:
if (bColorScheme)
{
- pColorSchemeSettings = g_settings_new (sSchema);
+ this->pColorSchemeSettings = g_settings_new (sSchema);
}
else
{
@@ -274,7 +278,7 @@ public:
}
else
{
- g_error("No %s schema could be found", sSchema);
+ g_warning ("Panic: No %s schema could be found", sSchema);
}
}
else
@@ -320,7 +324,7 @@ public:
gboolean bVisible = !this->bGreeter;
#ifdef COLOR_TEMP_ENABLED
- bVisible = bVisible || !this->bVirtualX;
+ bVisible = bVisible || !this->bXsctUnsupported;
#endif
update_desktop_header(bVisible);
@@ -368,25 +372,10 @@ public:
g_free (sLastTheme);
}
- if (pThemeSettings)
- {
- g_clear_object (&pThemeSettings);
- }
-
- if (pCursorSettings)
- {
- g_clear_object (&pCursorSettings);
- }
-
- if (pMetacitySettings)
- {
- g_clear_object (&pMetacitySettings);
- }
-
- if (pColorSchemeSettings)
- {
- g_clear_object (&pColorSchemeSettings);
- }
+ g_clear_object (&pThemeSettings);
+ g_clear_object (&pCursorSettings);
+ g_clear_object (&pMetacitySettings);
+ g_clear_object (&pColorSchemeSettings);
if (this->pAccountsServiceConnection)
{
@@ -424,7 +413,7 @@ private:
static void getAccountsService (DisplayIndicator::Impl *pImpl, gint nUid)
{
- if (!pImpl->bVirtualX)
+ if (!pImpl->bXsctUnsupported)
{
pImpl->bReadingAccountsService = TRUE;
gchar *sPath = g_strdup_printf ("/org/freedesktop/Accounts/User%i", nUid);
@@ -545,7 +534,7 @@ private:
guint nProfile = 0;
gdouble fBrightness = 0.0;
- if (!pImpl->bVirtualX)
+ if (!pImpl->bXsctUnsupported)
{
g_settings_get (pImpl->m_settings, "color-temp-profile", "q", &nProfile);
fBrightness = g_settings_get_double (pImpl->m_settings, "brightness");
@@ -566,7 +555,7 @@ private:
gint64 nNow = g_get_real_time ();
gdouble fElevation = solar_elevation((gdouble) nNow / 1000000.0, pImpl->fLatitude, pImpl->fLongitude);
- if (!pImpl->bVirtualX)
+ if (!pImpl->bXsctUnsupported)
{
if (nProfile == 0)
{
@@ -624,7 +613,7 @@ private:
}
}
- if (!pImpl->bVirtualX)
+ if (!pImpl->bXsctUnsupported)
{
if (pImpl->fLastBrightness != fBrightness || pImpl->nLasColorTemp != nTemperature)
{
@@ -640,44 +629,47 @@ private:
if (!bSuccess)
{
- g_error ("The call to '%s' failed: %s", sCommand, pError->message);
+ g_warning ("Panic: The call to '%s' failed: %s", sCommand, pError->message);
g_error_free (pError);
}
+ else
+ {
+ pImpl->fLastBrightness = fBrightness;
+ pImpl->nLasColorTemp = nTemperature;
+ gint nUid = 0;
- pImpl->fLastBrightness = fBrightness;
- pImpl->nLasColorTemp = nTemperature;
- g_free (sCommand);
- gint nUid = 0;
+ if (!pImpl->bGreeter)
+ {
+ nUid = geteuid ();
+ }
+ else if (pImpl->sUser)
+ {
+ const struct passwd *pPasswd = getpwnam (pImpl->sUser);
- if (!pImpl->bGreeter)
- {
- nUid = geteuid ();
- }
- else if (pImpl->sUser)
- {
- const struct passwd *pPasswd = getpwnam (pImpl->sUser);
+ if (pPasswd)
+ {
+ nUid = pPasswd->pw_uid;
+ }
+ }
- if (pPasswd)
+ if (nUid)
{
- nUid = pPasswd->pw_uid;
+ gchar *sPath = g_strdup_printf ("/org/freedesktop/Accounts/User%i", nUid);
+ GDBusProxy *pProxy = g_dbus_proxy_new_sync (pImpl->pAccountsServiceConnection, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.Accounts", sPath, "org.freedesktop.DBus.Properties", NULL, NULL);
+ g_free (sPath);
+ GVariant *pBrightnessValue = g_variant_new ("d", pImpl->fLastBrightness);
+ GVariant *pBrightnessParams = g_variant_new ("(ssv)", "org.ayatana.indicator.display.AccountsService", "brightness", pBrightnessValue);
+ g_dbus_proxy_call (pProxy, "Set", pBrightnessParams, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
+ GVariant *pColorTempValue = g_variant_new ("q", pImpl->nLasColorTemp);
+ GVariant *pColorTempParams = g_variant_new ("(ssv)", "org.ayatana.indicator.display.AccountsService", "color-temp", pColorTempValue);
+ g_dbus_proxy_call (pProxy, "Set", pColorTempParams, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
+ GVariant *pProfileValue = g_variant_new ("q", nProfile);
+ GVariant *pProfileParams = g_variant_new ("(ssv)", "org.ayatana.indicator.display.AccountsService", "color-temp-profile", pProfileValue);
+ g_dbus_proxy_call (pProxy, "Set", pProfileParams, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
}
}
- if (nUid)
- {
- gchar *sPath = g_strdup_printf ("/org/freedesktop/Accounts/User%i", nUid);
- GDBusProxy *pProxy = g_dbus_proxy_new_sync (pImpl->pAccountsServiceConnection, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.Accounts", sPath, "org.freedesktop.DBus.Properties", NULL, NULL);
- g_free (sPath);
- GVariant *pBrightnessValue = g_variant_new ("d", pImpl->fLastBrightness);
- GVariant *pBrightnessParams = g_variant_new ("(ssv)", "org.ayatana.indicator.display.AccountsService", "brightness", pBrightnessValue);
- g_dbus_proxy_call (pProxy, "Set", pBrightnessParams, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
- GVariant *pColorTempValue = g_variant_new ("q", pImpl->nLasColorTemp);
- GVariant *pColorTempParams = g_variant_new ("(ssv)", "org.ayatana.indicator.display.AccountsService", "color-temp", pColorTempValue);
- g_dbus_proxy_call (pProxy, "Set", pColorTempParams, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
- GVariant *pProfileValue = g_variant_new ("q", nProfile);
- GVariant *pProfileParams = g_variant_new ("(ssv)", "org.ayatana.indicator.display.AccountsService", "color-temp-profile", pProfileValue);
- g_dbus_proxy_call (pProxy, "Set", pProfileParams, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
- }
+ g_free (sCommand);
}
}
@@ -706,7 +698,11 @@ private:
{
g_debug ("Changing theme to %s", sTheme);
- g_settings_set_string (pImpl->pThemeSettings, "gtk-theme", sTheme);
+ if (pImpl->pThemeSettings)
+ {
+ g_settings_set_string (pImpl->pThemeSettings, "gtk-theme", sTheme);
+ }
+
gchar *sThemePath = g_strdup_printf ("/usr/share/themes/%s/index.theme", sTheme);
gboolean bThemePath = g_file_test (sThemePath, G_FILE_TEST_EXISTS);
@@ -737,7 +733,12 @@ private:
if (bMatch)
{
gchar *sIconTheme = g_match_info_fetch (pMatchInfo, 1);
- g_settings_set_string (pImpl->pThemeSettings, "icon-theme", sIconTheme);
+
+ if (pImpl->pThemeSettings)
+ {
+ g_settings_set_string (pImpl->pThemeSettings, "icon-theme", sIconTheme);
+ }
+
g_free (sIconTheme);
}
else
@@ -750,7 +751,7 @@ private:
}
else
{
- g_error ("PANIC: Failed to compile regex: %s", pError->message);
+ g_warning ("Panic: Failed to compile regex: %s", pError->message);
g_error_free (pError);
}
@@ -773,7 +774,12 @@ private:
if (bMatch)
{
gchar *sMetacityTheme = g_match_info_fetch (pMatchInfo, 1);
- g_settings_set_string (pImpl->pMetacitySettings, "theme", sMetacityTheme);
+
+ if (pImpl->pMetacitySettings)
+ {
+ g_settings_set_string (pImpl->pMetacitySettings, "theme", sMetacityTheme);
+ }
+
g_free (sMetacityTheme);
}
else
@@ -786,7 +792,7 @@ private:
}
else
{
- g_error ("PANIC: Failed to compile regex: %s", pError->message);
+ g_warning ("Panic: Failed to compile regex: %s", pError->message);
g_error_free (pError);
}
@@ -809,7 +815,12 @@ private:
if (bMatch)
{
gchar *sCursorTheme = g_match_info_fetch (pMatchInfo, 1);
- g_settings_set_string (pImpl->pCursorSettings, "cursor-theme", sTheme);
+
+ if (pImpl->pCursorSettings)
+ {
+ g_settings_set_string (pImpl->pCursorSettings, "cursor-theme", sTheme);
+ }
+
g_free (sCursorTheme);
}
else
@@ -822,7 +833,7 @@ private:
}
else
{
- g_error ("PANIC: Failed to compile regex: %s", pError->message);
+ g_warning ("Panic: Failed to compile regex: %s", pError->message);
g_error_free (pError);
}
@@ -830,7 +841,7 @@ private:
}
else
{
- g_error ("PANIC: Failed to get index.theme contents: %s", pError->message);
+ g_warning ("Panic: Failed to get index.theme contents: %s", pError->message);
g_error_free (pError);
}
}
@@ -978,7 +989,7 @@ private:
#ifdef COLOR_TEMP_ENABLED
if (ayatana_common_utils_is_lomiri() == FALSE)
{
- if (!this->bVirtualX)
+ if (!this->bXsctUnsupported)
{
pVariantType = g_variant_type_new ("d");
guint nTemperature = 0;
@@ -1104,7 +1115,7 @@ private:
#ifdef COLOR_TEMP_ENABLED
section = g_menu_new ();
- if (!this->bVirtualX)
+ if (!this->bXsctUnsupported)
{
GIcon *pIconMin = g_themed_icon_new_with_default_fallbacks ("ayatana-indicator-display-brightness-low");
GIcon *pIconMax = g_themed_icon_new_with_default_fallbacks ("ayatana-indicator-display-brightness-high");
@@ -1253,7 +1264,7 @@ private:
GSList *lUsers = NULL;
gboolean bReadingAccountsService = FALSE;
GDBusConnection *pAccountsServiceConnection = NULL;
- gboolean bVirtualX = FALSE;
+ gboolean bXsctUnsupported = FALSE;
#endif
};