Recent

Author Topic: How do Linux applications determine which interface icons to use?  (Read 4350 times)

A

  • Guest
Hello,

A few days ago, my computer broke. I have only just gotten it back up and running again. I was using Debian and now, I have a new distribution installed. Applications such as LibreOffice use different interface icons in the MenuStrip and the MenuItems depending on what distribution is being used (I think). In Debian, they were using GTK icons, in Linux Mint, they are using Linux Mint icons.

How are these applications determining which icon-sets to use? Is it done automatically somehow, or is it done programmatically  like this ( rough pseudo-code):

Code: Pascal  [Select][+][-]
  1. If Desktop.Environment = Cinnamon Then
  2. IconSet := "Linux Mint" Else
  3. IconSet := "GTK+";

Also, what resolution of icon is typically used in MenuItems?

Thanks for your help!


taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How do Linux applications determine which interface icons to use?
« Reply #1 on: December 31, 2017, 04:27:54 pm »
most of the linux destros follow this https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html  and I think there are a couple of function too that return an image for an icon name search the desktop specifications for more info.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

zeljko

  • Hero Member
  • *****
  • Posts: 1812
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How do Linux applications determine which interface icons to use?
« Reply #2 on: December 31, 2017, 06:16:56 pm »
Hello,

A few days ago, my computer broke. I have only just gotten it back up and running again. I was using Debian and now, I have a new distribution installed. Applications such as LibreOffice use different interface icons in the MenuStrip and the MenuItems depending on what distribution is being used (I think). In Debian, they were using GTK icons, in Linux Mint, they are using Linux Mint icons.

How are these applications determining which icon-sets to use? Is it done automatically somehow, or is it done programmatically  like this ( rough pseudo-code):

Code: Pascal  [Select][+][-]
  1. If Desktop.Environment = Cinnamon Then
  2. IconSet := "Linux Mint" Else
  3. IconSet := "GTK+";

Also, what resolution of icon is typically used in MenuItems?

Thanks for your help!

Maybe you should read env for XDG_* entries eg XDG_CURRENT_DESKTOP to get info what is running, and then jump into $HOME/.config and see what theme is setted up. Every desktop environment have it's own settings so, you must do some research and write some code that will work correct on major DE.


A

  • Guest
Re: How do Linux applications determine which interface icons to use?
« Reply #3 on: January 03, 2018, 10:57:02 pm »
Thanks for your help everyone,

However, I'm still having difficulties interpreting the webpage into what I can do to add this feature to my project.

I'm not in a hurry, so I'll probably leave it off for a while.

:)

A

  • Guest
Re: How do Linux applications determine which interface icons to use?
« Reply #4 on: January 04, 2018, 01:20:21 am »
Anyone looking at this in the future, I know where to find a solution; Lazarus's libraries are open source, and many of its components rely on system icon sets (e.g. ButtonPanel has system iconography preset). You can review the component's source code and extract the relevant code from there. Unfortunately I took a break 2 days after I started learning and have just come back to Lazarus, so I can't understand it yet, but I'm sure you can!

Hope this helped! :D

A

  • Guest
Re: How do Linux applications determine which interface icons to use?
« Reply #5 on: January 05, 2018, 11:59:20 pm »
Hello everybody,

I've been trawling through the source code for all of my unit's dependencies, and I've found a chunk of code that looks super relevant to what I'm trying to do - set the system stock image (save, save as, undo, redo, copy, paste bitmaps, etc.) as my button image.

Correct me if I'm wrong, but this is what this code does:

Code: Pascal  [Select][+][-]
  1. function GetButtonIcon(idButton: Integer): TCustomBitmap;
  2. var
  3.   BitmapHandle, MaskHandle: HBitmap;
  4. begin
  5.   if ThemeServices.GetStockImage(idButton, BitmapHandle, MaskHandle) then
  6.   begin
  7.     Result := TBitmap.Create;
  8.     Result.Handle := BitmapHandle;
  9.     if MaskHandle <> 0 then
  10.       Result.MaskHandle := MaskHandle;
  11.   end
  12.   else
  13.     Result := GetDefaultButtonIcon(idButton);
  14. end;
^ From the source of "Buttons" within unit dependencies ([View] -> [Unit Dependencies] -> [find the appropriate source file]).

Does anybody know what this code does and why it's there. How do I force my button to 'get' the stock image depending on OS/Desktop Environment?

Obviously I don't want you to write a crap tonne of code for me, but is it simple to use this code to 'get' the stock image for my buttons on form create?

Thanks so much for your help!

A

  • Guest
Re: How do Linux applications determine which interface icons to use?
« Reply #6 on: January 06, 2018, 06:36:57 pm »
I suppose a more channelled question would be: How can I call this function on FormCreate to put bitmaps on the buttons?

Thanks.

 

TinyPortal © 2005-2018