Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: HOWTO: Conky Multi-Desktop Configuration.

  1. #1
    Join Date
    Apr 2007
    Beans
    195

    HOWTO: Conky Multi-Desktop Configuration.

    I'm doing this just for the sake of doing it. One place to find the "Latest" solution on this issue. Unburying it so I can find it easily, and easily get results from people who may want to do some experimenting of their own.

    MULTI-WORKSPACE CONKY!

    A Preface: This is a bit of code I developed, inspired by someone's question about Compiz. I don't use it myself, but I did get a buzz out of the inspiration and it has become a, relatively untested, possible future way to solve the "I don't have enough room for all the data I want in Conky" problem many of us have.

    To be clear, this is a way to get Conky to display different data, or display differently, on different workspaces in Linux. It has not been fully tested for every window manager, but I know it works in XFCE4.

    There are two methods currently known: Compiz and Standard. I will describe the standard, and show the code for it. Then, I will do Compiz as a special case. When push comes to shove, they're the same.

    Standard Method: 4 Workspaces as example.

    In Conky there are three Objects that look at your workspace. ${desktop}, ${desktop_name}, and ${desktop_number}, which may be variations on the same thing. It really depends on your window manager. Gnome, KDE, XFCE4, Enlightenment, and yes Compiz, all call a workspace a specific thing in the code. Note: I will eventually update the specific requirement for each of these when, one day, someone with each of those window managers eventually tests the code and tells me what works. For now, I will use ${desktop} as the standard term. When you, the reader, go to try this it may be different for you.

    Currently known:
    XFCE4 = ${desktop}
    Compiz = Special Case, explained below.
    Gnome,Fluxbox = ${desktop}==, Gnome and Fluxbox both, when tested, spit out errors if only one = is used. In fact, the double equal is pretty standard.
    KDE = Unknown
    Enlightenment = Unknown
    Other = Unknown

    The goal here is to make Conky decide what workspace is currently being shown, and change how it looks accordingly. So, you are going to want to know how to use an ${if_match} statement. Which is really very simple. When I get to the example of how to decide what workspace, it will be formatted like so:

    Code:
    ${if_match (Condition)}
    <Do Something>
    ${else}
    <Do Something Else>
    ${endif}
    It is important to note three things for if_match statements. One is that the (Condition) won't be in brackets, it will be a conky object, probably something that changes. It will compare what it has changed to, so it will have an equal/greater than/less than/etc. statement after the Conky Object. Two is that <Do Something/Else>, much like the (Condition), only means you're going to put all of the code you want in use in place of <Do Something/Else> and not that you need the greater than or less than signs. It's just a place holder. And finally that you can have as many if_match statements as you want, nested inside eachother depending on what you're trying to compare, as long as you put an equal number of ${endif} objects at the very end of the structure. And you'll see that in the workspaces example code. And now that you understand the Conky object to compare the workspace, and the if_match structure, you can make the two work together to see what Conky should display based on your workspace.

    Which is this: How to compare your workspace to display specific items in Conky.

    Code:
    ${if_match ${desktop}=1}
    <Insert All Code You Wish On Desktop 1, As You Want It.>
    ${else}${if_match ${desktop}=2}
    <Insert All Code You Wish On Desktop 2, As You Want It, If you don't want anything, leave this empty.>
    ${else}${if_match ${desktop}=3}
    <Insert All Code You Wish On Desktop 3, As You Want It, If you don't want anything, leave this empty.>
    ${else}${if_match ${desktop}=4}
    <Insert All Code You Wish On Desktop 4, As You Want It, If you don't want anything, leave this empty.>
    ${else}
    ${endif}${endif}${endif}${endif}
    Simple, isn't it? Here's where it isn't. You need to write an entire Conky for each of those desktops. Or, at the very minimum, everything that goes under the TEXT object. This will make it a very long text file, and you may want to make a comment (# at the start of a line to Comment in Conky) to give you a visual cue as to which section is for what workspace. Also, as time goes on and I get the chance to get some test results in, the ${desktop} variable may have to be replaced with one of the other two variables (${desktop_name} or ${desktop_number}) in order for the structure to work for you. In the case of ${desktop_name} it will be replaced with the title or name of that workspace in quotes. Example:

    Code:
    ${desktop_name}="main"}
    When you don't want Conky to display on a particular desktop/workspace, then simply leave the if_match statement in place, and leave the <Everything You Want> part empty. Empty, as in without that comment.

    There will be consequences to this. As testing goes on, there may be certain window managers that display the outline of Conky, but leave it blank when you have no data inside. This will be due to the minimum_size environment variable being the same across all desktops/workspaces. If/when we discover a way around this, making Conky smarter, I will inform you how here.

    Compiz: The special case, and why it was the inspiration.

    Compiz is special. So many Linux users know this. It's all pretty and cool and stuff. It's 3D and makes that cube thingy that spins, and all that transparency and... okay I don't use Compiz at all. I don't particularly like it. But I did find something out about it when a user (jwcalla, whose problem is the inspiration, thus deserves credit.) came to this thread with a problem. Using Compiz, how do you get the different desktop/workspace areas to display different data? So, in fact Compiz is the first case we had to try any of this code, and has yet another reason to call it "Special", in this case being that it was the original.

    And then we discovered something in the troubleshooting. When he ran a command (wmctrl) to show how the desktop was being displayed, we were all shown something very unique about the Compiz window manager. It doesn't have workspaces or desktops. It has one desktop image, which it gets by taking the number of workspaces you want, and multiplying that by the horizontal resolution you picked for the monitor. So, instead of 4 workspaces, each, say, 1920x1080, it was one giant workspace that was 7680x1080. And then it takes that, and wraps it around a 3D object (the Cube you see in so many screenshots) like a tiled mural. This is why Compiz calls them Viewports. It's just one narrow view of the mural.

    So, how do you make Conky choose from that? Well, each pseudo-workspace, AKA each side of the cube, AKA Viewport, actually exists at a certain X co-ordinate on the tiled mural. "Huh?" Yeah, I know. But wmctrl (you should probably have it on your system, but I can't guarantee it.) has a display readout in a command prompt. When run using Compiz, the X and Y co-ordinate is shown. I don't have the program myself, but to run the general readout, you type this in a terminal:

    Code:
    wmctrl -d
    This is important, because this gives us something that has data in the command prompt to Compare to. To get that data, we're going to, and this is my favourite way to say it, grep/awk/sed the hell out of it to narrow down only that spot where we care about the number. So, we need this command for Conky. And you'll see it again in the example:

    Code:
     wmctrl -d | grep 'VP:' | awk '{print $2}' | sed 's/,0//'
    Quick explanation: the | tells the command prompt "before you report what that did, do this." The grep is a search program for command line interfaces that takes what a program spits out, and looks through it for a search string. awk is a program that reports back a specific result from something you tell it. sed is stream editor, which takes everything you've been asking the command line and edits or formats it into something you want.

    In this case, what this command call is doing is as follows:

    wmctrl: desktop report, search for something called 'VP:', report back the second thing you find after you've found 'VP:', take that thing and delete everything that looks like ',0', because I don't need it for what I'm doing.

    Guess what. You just reduced about 5 lines of data about your desktop as it currently is in Compiz, including it's current horizontal position on the big mural, down to just a single number for you to compare. Huzzah! You just located the number that represents the Viewport you're on!

    How is this useful: It's a number. You can compare to it. if_match likes that. And using the ${execi} object, you can tell Conky to do this.

    Getting To The Point!

    For every viewport you have, it will have a number. Multiply that number by your Monitor's horizontal resolution (in this example, 1920 of 1920x1080) and that will be the number you compare the statement to in Conky. Also in this example, the ${execi} object, which means execute this command, at this interval, is being run every 60 seconds. Yes, this will mean, it quite possibly could take a delay of a few seconds for Conky to know you're on a different Viewport.

    Here's the desktop comparison for Compiz:
    Code:
    ${if_match ${execi 60 wmctrl -d | grep 'VP:' | awk '{print $2}' | sed 's/,0//'} == 1920}
    (Insert All Code Below The TEXT section that you want on the first viewport.)
    ${else}${if_match ${execi 60 wmctrl -d | grep 'VP:' | awk '{print $2}' | sed 's/,0//'} == 3840}
    (Insert All Code Below The TEXT section that you want on the second viewport.)
    ${else}${if_match ${execi 60 wmctrl -d | grep 'VP:' | awk '{print $2}' | sed 's/,0//'} == 5760}
    (Insert All Code Below The TEXT section that you want on the third viewport.)
    ${else}${if_match ${execi 60 wmctrl -d | grep 'VP:' | awk '{print $2}' | sed 's/,0//'} == 7680}
    (Insert All Code Below The TEXT section that you want on the fourth viewport.)
    ${else}Out Of Viewports (Or copy/paste more of these.)${endif}${endif}${endif}${endif}
    As with the standard version, make as many if_match statements as you have viewports, as long as you have the same number of ${endif} objects.

    That is the current state of the multi-workspace code as I have it. I am very much looking for people to test it and get back to me on what they may have had to do to get it to work on their window manager.
    Last edited by 42dorian; January 16th, 2012 at 05:02 AM.

  2. #2
    Join Date
    Apr 2007
    Beans
    195

    Re: HOWTO: Conky Multi-Desktop Configuration.

    This is a place-holder post that will eventually discuss the implementation of LUA within the Multi-Desktop setup. When I have time, this post will be a special supplement Howto for using LUA within the Multi-Desktop code. For now, it's just a place holder.

    For now though, from what I know of LUA (Admittedly not nearly enough to call myself anything other than an Amateur.) I can say that you can use the same structure in LUA as you do in Conky for this setup. Though, this time you definitely need to know whether you're comparing a number, or a name. I will use a number as an example, but there will have to be a special format for comparing text. For now, The code for LUA is as follows:

    Code:
    desknum= tonumber(conky_parse(${desktop})
    if desknum == 1 then
    <LUA Code for desktop 1, depending on what it is.>
    else if desknum == 2 then
    <LUA Code for desktop 2, depending on what it is.>
    else if desknum == 3 then
    <LUA Code for desktop 3, depending on what it is.>
    else if desknum == 4 then
    <LUA Code for desktop 4, depending on what it is.>
    else
    end
    Admittedly this seems like it's just the exact same thing as before. Funny enough, it is. There are going to be a few variations on this, perhaps a slightly different requirement depending on the way you've got your LUA script set up. Some methods of coding are more accepting of this simple structure, and others may spit out errors if you use it. Further testing and examples will still be needed to answer every version.

    A note on this: I'm still looking for a LUA consultant to help me hammer out a better explanation with examples.
    Last edited by 42dorian; July 7th, 2011 at 09:58 PM.

  3. #3
    Join Date
    Oct 2008
    Beans
    3,509

    Re: HOWTO: Conky Multi-Desktop Configuration.

    I am using compiz with 4 viewports ...ie 2 horizontal and 2 vertical
    and this is my wmctrl output for unity 11.10.

    Code:
    glen@Oneiric:~$ wmctrl -d
    0  * DG: 3360x2100  VP: 0,0  WA: 50,24 1630x1026  N/A
    glen@Oneiric:~$ wmctrl -d | grep 'VP:' | awk '{print $2}' | sed 's/,0//'
    *
    glen@Oneiric:~$

    This is with 4 horizontal and 1 vertical
    Code:
    glen@Oneiric:~$ wmctrl -d
    0  * DG: 6720x1050  VP: 0,0  WA: 50,24 1630x1026  N/A
    glen@Oneiric:~$ wmctrl -d | grep 'VP:' | awk '{print $2}' | sed 's/,0//'
    *
    glen@Oneiric:~$
    Same result on my 10.04 install.

  4. #4
    Join Date
    Apr 2007
    Beans
    195

    Re: HOWTO: Conky Multi-Desktop Configuration.

    ...Very interesting... I'll have to get back to you there.

    This is with vertical and horizontal viewports...

    Looks like the grep is at fault there. For reasons unknown, it's not executing the grep. It's just grabbing the awk and the sed.

    Try this instead:

    Code:
    wmctrl -d | awk '{print $6}' | sed 's/,0//'
    And if that does/doesn't work we can figure the two different versions from there. (Vertical and Horizontal configurations.)

  5. #5
    Join Date
    Oct 2008
    Beans
    3,509

    Re: HOWTO: Conky Multi-Desktop Configuration.

    This is the output for the 4 viewports
    1-2
    3-4

    Code:
    glen@Oneiric:~$ wmctrl -d | awk '{print $6}'
    0,0
    glen@Oneiric:~$ wmctrl -d | awk '{print $6}'
    1680,0
    glen@Oneiric:~$ wmctrl -d | awk '{print $6}'
    0,1050
    glen@Oneiric:~$ wmctrl -d | awk '{print $6}'
    1680,1050

    and this is with 4 horizontal
    1 2 3 4
    Code:
    glen@Oneiric:~$ wmctrl -d | awk '{print $6}'
    0,0
    glen@Oneiric:~$ wmctrl -d | awk '{print $6}'
    1680,0
    glen@Oneiric:~$ wmctrl -d | awk '{print $6}'
    3360,0
    glen@Oneiric:~$ wmctrl -d | awk '{print $6}'
    5040,0
    Last edited by stinkeye; January 13th, 2012 at 05:57 AM.

  6. #6
    Join Date
    Apr 2007
    Beans
    195

    Re: HOWTO: Conky Multi-Desktop Configuration.

    Yes. It's very easy to get that going then. Nested if statements. I'll get to that code later and explain further. I'm in between some things for now. I'll just update this post when I get free again.

    Thank you stinkeye! Now, hopefully some others will come along to test KDE and a few other window managers for this too.

    You're Compiz with Ubuntu Unity, correct?

  7. #7
    Join Date
    Oct 2008
    Beans
    3,509

    Re: HOWTO: Conky Multi-Desktop Configuration.

    Quote Originally Posted by 42dorian View Post
    Yes. It's very easy to get that going then. Nested if statements. I'll get to that code later and explain further. I'm in between some things for now. I'll just update this post when I get free again.

    Thank you stinkeye! Now, hopefully some others will come along to test KDE and a few other window managers for this too.

    You're Compiz with Ubuntu Unity, correct?
    Yes using Unity/compiz 11.10.
    This was very useful.
    There used to be a plugin for older versions of compiz to display your desktop number.
    I can now achieve this using conky and the wmctrl command.
    As I only use two desktops it was fairly easy by adding...
    Code:
    ${if_match ${exec wmctrl -d | awk '{print $6}' | sed 's/,0//'} == 1680}${color}DESK 2${else}DESK 1${endif}
    Attached Images Attached Images

  8. #8
    Join Date
    Aug 2011
    Beans
    Hidden!

    Re: HOWTO: Conky Multi-Desktop Configuration.

    ${desktop} returns numbers (1, 2, 3, 4, etc.) when using Fluxbox in Ubuntu 11.04.
    So your standard method works with one modification in Fluxbox.
    You need to use ${desktop}==1 instead of ${desktop}=1.
    == is the normal comparison operator in programing languages because = is used for assignment operations, so this makes sense.

    It is also consistent with the conky documentation for ${if_match}.
    Code:
    Evaluates the given boolean expression, printing everything between $if_match and 
    the matching $endif depending on whether the evaluation returns true or not. Valid
    expressions consist of a left side, an operator and a right side. Left and right sides are
    being parsed for contained text objects before evaluation. Recognised left and right side
    types are:
    
    
    • double - Argument consists of only digits and a single dot.
    • long - Argument consists of only digits.
    • string - Argument is enclosed in quotation marks (")
    Valid operands are: '>', '<', '>=','<=', '==','!='.
    Here is the code I used for a test.
    Code:
    ${if_match ${desktop}==1}
    Workspace 1!
    ${else}${if_match ${desktop}==2}
    Workspace 2!
    ${else}${if_match ${desktop}==3}
    Workspace 3!
    ${else}${if_match ${desktop}==4}
    Workspace 4!
    ${else}
    ${endif}${endif}${endif}${endif}

  9. #9
    Join Date
    Oct 2009
    Location
    Under a rock
    Beans
    Hidden!

    Re: HOWTO: Conky Multi-Desktop Configuration.

    had an idea, realised it wouldn't work
    Last edited by mrpeachy; January 16th, 2012 at 04:02 AM.

  10. #10
    Join Date
    Oct 2009
    Location
    Under a rock
    Beans
    Hidden!

    Re: HOWTO: Conky Multi-Desktop Configuration.

    getting different lua displays on different conkies...
    i think having one humongous script containing multiple setups based on if's is not necessary...
    (unless you were just using a single script and only wanting to feed the script different settings, but then you would have to go script by script to get the if's in the right place)

    the first thing that comes to mind would be along these lines

    Code:
    lua_load script1
    lua_load script2
    lua_load script3
    
    TEXT
    if_match 1
    ${lua main_function1}
    else if_match 2
    ${lua main_function2}
    else if_match 3
    ${lua main_function3}
    endif endif endif
    i dont ever use more than one screen, so i havnt tested this
    Last edited by mrpeachy; January 16th, 2012 at 03:48 AM.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •