Xfce Forum

Sub domains
 

You are not logged in.

#1 2016-09-18 16:50:04

Jerry3904
Member
Registered: 2013-11-09
Posts: 583

maintain order of panel elements when changing orientation

We release MX Linux with a default orientation of the panel in taskbar mode. Some users want the traditional orientation, however, and we have an MX Tool to make that switch. But, as one reviewer noted, that only produces a default panel in horizontal orientation with traditional elements in traditional places, not the user's modified panel. We went with that because the order in vertical orientation is from bottom to top, but when changed to horizontal mode it reads from right to left (e.g., whisker menu is at the bottom in vertical mode, at right end in horizontal mode).

Now that we are in development for MX-16, we would like to improve this behavior. I know that we can excerpt and reverse the plugin-ids with this command:

sed -e '1,/<property name="plugin-ids" type="array">/d' -e '/<\/property>/, $d' /home/$USER/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml |tac

On the laptop I am using at the moment, for instance, this is the original:

<?xml version="1.0" encoding="UTF-8"?>

<channel name="xfce4-panel" version="1.0">
  <property name="configver" type="int" value="2"/>
  <property name="panels" type="array">
    <value type="int" value="1"/>
    <property name="panel-1" type="empty">
      <property name="position" type="string" value="p=6;x=0;y=0"/>
      <property name="length" type="uint" value="100"/>
      <property name="position-locked" type="bool" value="true"/>
      <property name="size" type="uint" value="44"/>
      <property name="plugin-ids" type="array">
        <value type="int" value="12"/>
        <value type="int" value="8"/>
        <value type="int" value="1"/>
        <value type="int" value="3"/>
        <value type="int" value="15"/>
        <value type="int" value="16"/>
        <value type="int" value="7"/>
        <value type="int" value="5"/>
        <value type="int" value="2"/>
        <value type="int" value="6"/>
        <value type="int" value="4"/>
        <value type="int" value="10"/>
        <value type="int" value="20"/>
      </property> ...

And this is the result of running the sed/tac command:

jb@mx1:~
$ sed -e '1,/<property name="plugin-ids" type="array">/d' -e '/<\/property>/, $d' /home/$USER/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml |tac
        <value type="int" value="20"/>
        <value type="int" value="10"/>
        <value type="int" value="4"/>
        <value type="int" value="6"/>
        <value type="int" value="2"/>
        <value type="int" value="5"/>
        <value type="int" value="7"/>
        <value type="int" value="16"/>
        <value type="int" value="15"/>
        <value type="int" value="3"/>
        <value type="int" value="1"/>
        <value type="int" value="8"/>
        <value type="int" value="12"/>
jb@mx1:~

So far, so good. What I can't figure out yet is what code I need now to replace the original lines--which vary in number from user to user--with that reversed output. Though this is technically a coding question, the base problem is common to all Xfce users, so I thought it reasonable to post the question here.

Any help would be appreciated.

Last edited by Jerry3904 (2016-09-18 16:50:43)


MX-17 (based on Debian Stable) with Xfce 4.12.

Offline

#2 2016-09-18 20:47:54

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 4,075

Re: maintain order of panel elements when changing orientation

I've been looking at this Jerry. You can use xfconf-query to do this without editing the xml files (which in some cases can be problematic because these settings are saved in memory and usually written out to the xml files on log out). xfconf-query doesn't have built-in array management utilities, so you need to use some bash-foo. Here are my notes, I hope it helps:

# get the list of panel ids
xfconf-query -c xfce4-panel -p /panels/panel-1/plugin-ids | grep -v "Value" | grep -v ^$

# save the list of panel ids into an array
mapfile -t ids < <(xfconf-query -c xfce4-panel -p /panels/panel-1/plugin-ids | grep -v "Value" | grep -v ^$)

# output the array elements
echo ${ids[*]}

# get the number of elements in an array
echo ${#ids[@]}

# loop the elements of the array
for ((x=0; x<${#ids[@]}; x++)); do echo ${ids[x]}; done

# loop the elements of the array in reverse order (which we want so to be able to reverse the order of the plugins)
for ((x=${#ids[@]}; x>0; x--)); do echo ${ids[x-1]}; done

# set up the begining part of the xfconf-query exec string
exestr="xfconf-query -c xfce4-panel -p /panels/panel-1/plugin-ids"

# echo the contents of exestr so far
echo $exestr

# loop in reverse adding the elements to the string
for ((x=${#ids[@]}; x>0; x--)); do exestr="$exestr -s ${ids[x-1]}" ; done

# echo the contents of exestr
echo $exestr

# execute the string which in turn executes xfconf-query and changes the values
eval "$exestr"

# restart xfce4-panel for the change to take effect
xfce4-panel -r

A couple of things to note:
1. Its hard-coded to panel-1 and it only works for panel 1. If the user creates and uses another panel (or has multiple panels), you'll have to extend it.
2. On my system, this reverses the order of the panel plugins on panel-1. I hope this understanding is correct.

Last edited by ToZ (2016-09-19 15:21:01)


How To Ask For Help           Xfce FAQ                            Xfce Release Information
The Xfce Community          Xfce Tips and Tricks

Offline

#3 2016-09-18 21:41:59

Jerry3904
Member
Registered: 2013-11-09
Posts: 583

Re: maintain order of panel elements when changing orientation

Thanks! It usually happens that just about the time I think I have made progress, somebody tells me I have taken the wrong road.

I will take a look at this in the coming week and post back. What would be great is if the result could be sent upstream and eventually become an item on the panel dialogue box, because I doubt that I am the only user in the world who comes on this problem!


MX-17 (based on Debian Stable) with Xfce 4.12.

Offline

#4 2016-09-19 15:09:41

Jerry3904
Member
Registered: 2013-11-09
Posts: 583

Re: maintain order of panel elements when changing orientation

Initial feedback: seems to work well. One of our coders made some modifications that he thinks will extend the reversal to all panels present:

#!/bin/bash

for panel in $(xfconf-query -c xfce4-panel -p /panels | grep ^[0-9])
  do
    mapfile -t ids < <(xfconf-query -c xfce4-panel -p /panels/panel-"$panel"/plugin-ids | grep -v "Value" | grep -v ^$)
    exestr="xfconf-query -c xfce4-panel -p /panels/panel-"$panel"/plugin-ids"
    for ((x=${#ids[@]}; x>0; x--)); do exestr="$exestr -s ${ids[x-1]}" ; done
    eval "$exestr"
    xfce4-panel -r
  done

What do you think?


MX-17 (based on Debian Stable) with Xfce 4.12.

Offline

#5 2016-09-19 15:26:45

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 4,075

Re: maintain order of panel elements when changing orientation

Looks good.
One issue though, on my system I get a "No running instance of xfce4-panel was found" error message even though the script works. I think it might have something to do with the xfconf-query command and the sfce4-panel restart so close to each other. Adding a small pause ("sleep .5s") between the eval and the xfce4-panel commands solved the issue.


How To Ask For Help           Xfce FAQ                            Xfce Release Information
The Xfce Community          Xfce Tips and Tricks

Offline

#6 2016-09-19 16:09:25

Jerry3904
Member
Registered: 2013-11-09
Posts: 583

Re: maintain order of panel elements when changing orientation

Thanks, again.


MX-17 (based on Debian Stable) with Xfce 4.12.

Offline

#7 2016-11-13 16:41:12

Jerry3904
Member
Registered: 2013-11-09
Posts: 583

Re: maintain order of panel elements when changing orientation

OK, we have that running nicely on MX-16 B1, and present the new user with the option in the Welcome screen.

A B1 user has asked in the feedback forum why it rotates to the top and not the bottom, where users traditionally expect to see it--or, as on snarky user said: "where God intended it to be." We're entertaining the idea of changing so the rotation ends up with the panel on the bottom, but having trouble seeing how to get the geometry right. If I run a diff on "horizup" and "horizdown" versions of the xml file, the only difference is the value change for p in the position line from 6 to 8.

Any thoughts on this?


MX-17 (based on Debian Stable) with Xfce 4.12.

Offline

#8 2016-11-13 20:09:02

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 4,075

Re: maintain order of panel elements when changing orientation

This thread lists the meanings of the position numbers. These are stored in the "/panels/panel-X/position" key. You should be able to read and re-write that key value to change the position of the panel. If the panel is located in one of the corners and is full length, then only the p value is used, so it would be simple to set "p=6;x=0;y=0" for upper left corner or "p=8;x=0;y=0" for bottom left corner.


How To Ask For Help           Xfce FAQ                            Xfce Release Information
The Xfce Community          Xfce Tips and Tricks

Offline

#9 2016-11-13 20:17:56

Jerry3904
Member
Registered: 2013-11-09
Posts: 583

Re: maintain order of panel elements when changing orientation

Thanks again! We have now a toggle set up (top-bottom), so we're getting very close.


MX-17 (based on Debian Stable) with Xfce 4.12.

Offline

Board footer

Powered by FluxBB