Skip to content

Commit

Permalink
Merge pull request #34 from dkondor/backport_appid
Browse files Browse the repository at this point in the history
Backport some fixes
  • Loading branch information
dkondor authored Sep 21, 2024
2 parents 805818b + 4bc47b3 commit 35c8f73
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 71 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include ("${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/GNUInstallDirs.cmake")
########### project ###############

project ("cairo-dock")
set (VERSION "3.5.0") # no dash, only numbers, dots and maybe alpha/beta/rc, e.g.: 3.3.1 or 3.3.99.alpha1
set (VERSION "3.5.1") # no dash, only numbers, dots and maybe alpha/beta/rc, e.g.: 3.3.1 or 3.3.99.alpha1

add_definitions (-std=c99 -Wall -Wextra -Werror-implicit-function-declaration) # -Wextra -Wwrite-strings -Wuninitialized -Werror-implicit-function-declaration -Wstrict-prototypes -Wreturn-type -Wparentheses -Warray-bounds)
if (NOT DEFINED CMAKE_BUILD_TYPE)
Expand Down
30 changes: 21 additions & 9 deletions Help/src/applet-tips-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static void _cairo_dock_get_next_tip (CDTipsData *pTips)
{
pTips->iNumTipKey ++; // skip the current expander to go to the current label, which will be skipped in the first iteration.
const gchar *cGroupName = pTips->pGroupList[pTips->iNumTipGroup];
gboolean bOk;
gboolean bOk = FALSE;
do
{
pTips->iNumTipKey ++;
Expand Down Expand Up @@ -77,8 +77,13 @@ static void _cairo_dock_get_next_tip (CDTipsData *pTips)
// check if the key is an expander widget.
const gchar *cKeyName = pTips->pKeyList[pTips->iNumTipKey];
gchar *cKeyComment = g_key_file_get_comment (pTips->pKeyFile, cGroupName, cKeyName, NULL);
bOk = (cKeyComment && *cKeyComment == CAIRO_DOCK_WIDGET_EXPANDER); // whether it's an expander.
g_free (cKeyComment);
if (cKeyComment)
{
gchar *tmp = cKeyComment;
while (*tmp == '\t' || *tmp == '\n' || *tmp == ' ') ++tmp;
bOk = (*tmp == CAIRO_DOCK_WIDGET_EXPANDER); // whether it's an expander.
g_free (cKeyComment);
}
} while (!bOk);
}

Expand All @@ -87,7 +92,7 @@ static void _cairo_dock_get_previous_tip (CDTipsData *pTips)
pTips->iNumTipKey --;

const gchar *cGroupName = pTips->pGroupList[pTips->iNumTipGroup];
gboolean bOk;
gboolean bOk = FALSE;
do
{
pTips->iNumTipKey --;
Expand Down Expand Up @@ -125,7 +130,13 @@ static void _cairo_dock_get_previous_tip (CDTipsData *pTips)
// check if the key is an expander widget.
const gchar *cKeyName = pTips->pKeyList[pTips->iNumTipKey];
gchar *cKeyComment = g_key_file_get_comment (pTips->pKeyFile, cGroupName, cKeyName, NULL);
bOk = (cKeyComment && *cKeyComment == CAIRO_DOCK_WIDGET_EXPANDER); // whether it's an expander.
if (cKeyComment)
{
gchar *tmp = cKeyComment;
while (*tmp == '\t' || *tmp == '\n' || *tmp == ' ') ++tmp;
bOk = (*tmp == CAIRO_DOCK_WIDGET_EXPANDER); // whether it's an expander.
g_free (cKeyComment);
}
} while (!bOk);
}

Expand Down Expand Up @@ -276,10 +287,6 @@ void cairo_dock_show_tips (void)
pTips->iNumTipGroup = iNumTipGroup;
pTips->iNumTipKey = iNumTipKey;

// update to the next tip.
if (myData.iLastTipGroup >= 0 && myData.iLastTipKey >= 0) // a previous tip exist => take the next one;
_cairo_dock_get_next_tip (pTips);

// build a list of the available groups.
GtkWidget *pInteractiveWidget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
GtkWidget *pComboBox = gtk_combo_box_text_new ();
Expand All @@ -290,6 +297,11 @@ void cairo_dock_show_tips (void)
}
gtk_combo_box_set_active (GTK_COMBO_BOX (pComboBox), pTips->iNumTipGroup);
pTips->pCategoryCombo = pComboBox;

// update to the next tip.
if (myData.iLastTipGroup >= 0 && myData.iLastTipKey >= 0) // a previous tip exist => take the next one;
_cairo_dock_get_next_tip (pTips);

static gpointer data_combo[2];
data_combo[0] = pTips; // the 2nd data is the dialog, we'll set it after we make it.
g_signal_connect (G_OBJECT (pComboBox), "changed", G_CALLBACK(_on_tips_category_changed), data_combo);
Expand Down
13 changes: 1 addition & 12 deletions data/desktop-manager/gnome-session-3.36/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,4 @@ After=gnome-flashback.target
BindsTo=gnome-session.target
After=gnome-session.target

Requires=indicators-pre.target

# here we list the indicators that we want to load
Wants=indicator-application.service
Wants=indicator-bluetooth.service
Wants=indicator-datetime.service
Wants=indicator-keyboard.service
Wants=indicator-messages.service
Wants=indicator-power.service
Wants=indicator-printers.service
Wants=indicator-session.service
Wants=indicator-sound.service
Wants=ayatana-indicators.target
13 changes: 1 addition & 12 deletions data/desktop-manager/gnome-session-3.36/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,4 @@ After=gnome-flashback.target
BindsTo=gnome-session.target
After=gnome-session.target

Requires=indicators-pre.target

# here we list the indicators that we want to load
Wants=indicator-application.service
Wants=indicator-bluetooth.service
Wants=indicator-datetime.service
Wants=indicator-keyboard.service
Wants=indicator-messages.service
Wants=indicator-power.service
Wants=indicator-printers.service
Wants=indicator-session.service
Wants=indicator-sound.service
Wants=ayatana-indicators.target
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ Order=6.25

Icon Type=0
Type=Application
Origin=/usr/share/applications/gcalctool.desktop;kcalc.desktop;galculator.desktop
Origin=/usr/share/applications/gnome-calculator.desktop;kcalc.desktop
2 changes: 1 addition & 1 deletion data/themes/default-theme-panel/launchers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
install(FILES
01container.desktop
01firefox.desktop
01gcalctool.desktop
01gnome-calculator.desktop
01libreoffice-calc.desktop
01libreoffice-impress.desktop
01libreoffice-writer.desktop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ Order=4

Icon Type=0
Type=Application
Origin=/usr/share/applications/gcalctool.desktop;kcalc.desktop;galculator.desktop
Origin=/usr/share/applications/gnome-calculator.desktop;kcalc.desktop
2 changes: 1 addition & 1 deletion data/themes/default-theme/launchers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

install(FILES
01firefox.desktop
01gcalctool.desktop
01gnome-calculator.desktop
01gimp.desktop
01gnome-terminal.desktop
01ooo-writer.desktop
Expand Down
2 changes: 1 addition & 1 deletion src/cairo-dock-user-menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ static void _cairo_dock_set_custom_appli_icon (G_GNUC_UNUSED GtkMenuItem *pMenuI
} // apres la boucle, i = nbre d'elements, j = l'element qui a ete enleve.
if (j != -1) // un element a ete enleve.
{
cd_warning ("The class '%s' was explicitely set up to use the X icon, we'll change this behavior automatically.", icon->cClass);
cd_warning ("The class '%s' was explicitly set up to use the X icon, we'll change this behavior automatically.", icon->cClass);
if (j < i - 1) // ce n'est pas le dernier
{
pExceptions[j] = pExceptions[i-1];
Expand Down
1 change: 1 addition & 0 deletions src/gldit/cairo-dock-applications-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ static void init_object (GldiObject *obj, gpointer attr)

icon->cName = g_strdup (actor->cName ? actor->cName : actor->cClass);
icon->cClass = g_strdup (actor->cClass); // we'll register the class during the loading of the icon, since it can take some time, and we don't really need the class params right now.
icon->cWmClass = g_strdup (actor->cWmClass);

icon->iface.load_image = _load_appli;
icon->iface.action_on_drag_hover = _show_appli_for_drop;
Expand Down
3 changes: 2 additions & 1 deletion src/gldit/cairo-dock-class-icon-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ static void init_object (GldiObject *obj, gpointer attr)
pIcon->iface.load_image = _load_image;
pIcon->iGroup = pSameClassIcon->iGroup;

pIcon->cName = g_strdup (pSameClassIcon->cClass);
const gchar *cClassName = cairo_dock_get_class_name(pSameClassIcon->cClass);
pIcon->cName = g_strdup (cClassName ? cClassName : pSameClassIcon->cClass);
pIcon->cCommand = g_strdup (pSameClassIcon->cCommand);
pIcon->pMimeTypes = g_strdupv (pSameClassIcon->pMimeTypes);
pIcon->cClass = g_strdup (pSameClassIcon->cClass);
Expand Down
74 changes: 53 additions & 21 deletions src/gldit/cairo-dock-class-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,25 @@ const CairoDockImageBuffer *cairo_dock_get_class_image_buffer (const gchar *cCla
}


static gboolean _check_desktop_file_exists(GString *sDesktopFilePath, const gchar *cFileName, const char *prefix)
{
// TODO: use XDG_DATA_DIRS instead of hard-coded values!
if (prefix) g_string_printf (sDesktopFilePath, "/usr/share/applications/%s%s", prefix, cFileName);
else g_string_printf (sDesktopFilePath, "/usr/share/applications/%s", cFileName);
if (g_file_test (sDesktopFilePath->str, G_FILE_TEST_EXISTS)) return TRUE;

if(prefix) g_string_printf (sDesktopFilePath, "/usr/local/share/applications/%s%s", prefix, cFileName);
else g_string_printf (sDesktopFilePath, "/usr/local/share/applications/%s", cFileName);
if (g_file_test (sDesktopFilePath->str, G_FILE_TEST_EXISTS)) return TRUE;

if(prefix) g_string_printf (sDesktopFilePath, "%s/.local/share/applications/%s%s", g_getenv ("HOME"), prefix, cFileName);
else g_string_printf (sDesktopFilePath, "%s/.local/share/applications/%s", g_getenv ("HOME"), cFileName);
if (g_file_test (sDesktopFilePath->str, G_FILE_TEST_EXISTS)) return TRUE;

return FALSE;
}


static gchar *_search_desktop_file (const gchar *cDesktopFile) // file, path or even class
{
if (cDesktopFile == NULL)
Expand All @@ -1611,29 +1630,38 @@ static gchar *_search_desktop_file (const gchar *cDesktopFile) // file, path or
cDesktopFileName = g_strdup_printf ("%s.desktop", cDesktopFile);

const gchar *cFileName = (cDesktopFileName ? cDesktopFileName : cDesktopFile);
gboolean bFound = TRUE;
gboolean bFound;
GString *sDesktopFilePath = g_string_new ("");
g_string_printf (sDesktopFilePath, "/usr/share/applications/%s", cFileName);
if (! g_file_test (sDesktopFilePath->str, G_FILE_TEST_EXISTS))
gchar *cFileNameLower = NULL;

bFound = _check_desktop_file_exists (sDesktopFilePath, cFileName, NULL);

if (! bFound)
{
g_string_printf (sDesktopFilePath, "/usr/share/applications/%c%s", g_ascii_toupper (*cFileName), cFileName+1); // handle stupid cases like Thunar.desktop
if (! g_file_test (sDesktopFilePath->str, G_FILE_TEST_EXISTS))
cFileNameLower = g_ascii_strdown (cFileName, -1);
bFound = _check_desktop_file_exists (sDesktopFilePath, cFileNameLower, NULL);
}
if (! bFound)
{
const char *prefices[] = {"org.gnome.", "org.kde.", "org.freedesktop.", "xfce4/", "kde4/", NULL};
int i, j;
for (i = 0; i < 3; i++)
{
g_string_printf (sDesktopFilePath, "/usr/share/applications/xfce4/%s", cFileName);
if (! g_file_test (sDesktopFilePath->str, G_FILE_TEST_EXISTS))
/* note: third iteration is to handle very stupid cases such as
* org.gnome.Evince.desktop with app-id == "evince" (happens for
* version 42.3 that is on Ubuntu 22.04) */
if (i == 2) cFileNameLower[0] = g_ascii_toupper (cFileNameLower[0]);
const gchar *tmp = i ? cFileNameLower : cFileName;
for (j = 0; prefices[j]; j++)
{
g_string_printf (sDesktopFilePath, "/usr/share/applications/kde4/%s", cFileName);
if (! g_file_test (sDesktopFilePath->str, G_FILE_TEST_EXISTS))
{
g_string_printf (sDesktopFilePath, "%s/.local/share/applications/%s", g_getenv ("HOME"), cFileName);
if (! g_file_test (sDesktopFilePath->str, G_FILE_TEST_EXISTS))
{
bFound = FALSE;
}
}
bFound = _check_desktop_file_exists (sDesktopFilePath, tmp, prefices[j]);
if (bFound) break;
}
if (bFound) break;
}
}

g_free (cFileNameLower);
g_free (cDesktopFileName);

gchar *cResult;
Expand Down Expand Up @@ -1772,13 +1800,15 @@ gchar *cairo_dock_guess_class (const gchar *cCommand, const gchar *cStartupWMCla
g_free (cDefaultClass);
}
else
{
cResult = g_ascii_strdown (cStartupWMClass, -1);
gchar *str = strchr (cResult, '.'); // we remove all .xxx otherwise we can't detect the lack of extension when looking for an icon (openoffice.org) or it's a problem when looking for an icon (jbrout.py).
if (str != NULL)
*str = '\0';

if (cResult)
{
// remove some suffices that can be problematic: .exe, .py (note: cResult is already lowercase here)
if (g_str_has_suffix (cResult, ".exe")) cResult[strlen (cResult) - 4] = 0;
else if (g_str_has_suffix (cResult, ".py")) cResult[strlen (cResult) - 3] = 0;
cairo_dock_remove_version_from_string (cResult);
}
cairo_dock_remove_version_from_string (cResult);
cd_debug (" -> '%s'", cResult);

return cResult;
Expand Down Expand Up @@ -1865,6 +1895,8 @@ gchar *cairo_dock_register_class_full (const gchar *cDesktopFile, const gchar *c

//\__________________ search the desktop file's path.
gchar *cDesktopFilePath = _search_desktop_file (cDesktopFile?cDesktopFile:cClass);
if (cDesktopFilePath == NULL && cWmClass != NULL)
cDesktopFilePath = _search_desktop_file (cWmClass);
if (cDesktopFilePath == NULL) // couldn't find the .desktop
{
if (cClass != NULL) // make a class anyway to store the few info we have.
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/cairo-dock-X-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ static gboolean _cairo_dock_unstack_Xevents (G_GNUC_UNUSED gpointer data)
if (xactor->bIgnored) // was ignored, simply recreate it
{
// remove it from the table, so that the XEvent loop detects it again
g_hash_table_remove (s_hXWindowTable, &Xid); // remove it explicitely, because the 'unref' might not free it
g_hash_table_remove (s_hXWindowTable, &Xid); // remove it explicitly, because the 'unref' might not free it
xactor->iLastCheckTime = -1;
_delete_actor (xactor); // unref it since we don't need it anymore
}
Expand Down
8 changes: 3 additions & 5 deletions src/implementations/cairo-dock-X-utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -1165,11 +1165,9 @@ gchar *cairo_dock_get_xwindow_class (Window Xid, gchar **cWMClass)
cClass = g_ascii_strdown (pClassHint->res_class, -1); // down case because some apps change the case depending of their windows...
}

if (g_str_has_suffix (cClass, ".exe")) cClass[strlen (cClass) - 4] = 0;
else if (g_str_has_suffix (cClass, ".py")) cClass[strlen (cClass) - 3] = 0;
cairo_dock_remove_version_from_string (cClass); // we remore number of version (e.g. Openoffice.org-3.1)

gchar *str = strchr (cClass, '.'); // we remove all .xxx otherwise we can't detect the lack of extension when looking for an icon (openoffice.org) or it's a problem when looking for an icon (jbrout.py).
if (str != NULL)
*str = '\0';
cd_debug ("got an application with class '%s'", cClass);

XFree (pClassHint->res_name);
Expand Down Expand Up @@ -1581,7 +1579,7 @@ cairo_surface_t *cairo_dock_create_surface_from_xpixmap (Pixmap Xid, int iWidth,
GdkPixbuf *pPixbuf = cairo_dock_get_pixbuf_from_pixmap (Xid, TRUE);
if (pPixbuf == NULL)
{
cd_warning ("No thumbnail available.\nEither the WM doesn't support this functionnality, or the window was minimized when the dock has been launched.");
cd_warning ("No thumbnail available.\nEither the WM doesn't support this explicitly, or the window was minimized when the dock has been launched.");
return NULL;
}

Expand Down
5 changes: 1 addition & 4 deletions tests/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

#exe = 'galculator' # name of a program that can be launched several times, and is usually not running
#wmclass = 'galculator' # its class
#desktop_file = 'fedora-galculator.desktop' # its desktop file
exe = 'gnome-calculator' # name of a program that can be launched several times, and is usually not running
wmclass = 'gnome-calculator' # its class
desktop_file = 'gcalctool.desktop' # its desktop file
desktop_file = 'gnome-calculator.desktop' # its desktop file

exe1 = 'gnome-session-properties' # a program that doesn't have a launcher yet
wmclass1 = 'gnome-session-properties' # its class
Expand Down

0 comments on commit 35c8f73

Please sign in to comment.