How to activate most recently focused app window in xfce4/xfwm4?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I use my function keys for specific applications (F1 chrome, F2 terminal, etc). I have a script bound to a shortcut key to activate the right application, and that works, but it doesn't activate the most-recently-focused window. The script lists windows with wmctrl -lx which seems to list windows by reverse-creation order. Is there any way to ask for or keep track of the order specific windows are activated so I can script "activate the most recent terminal window"?



Alternately, it seems if I was able to get the window stack order maintained by xfwm4 (which it uses when you cycle through windows), that seems like it would solve my problem as well but I don't see a command line interface to get at that window stack order.







share|improve this question

























    up vote
    0
    down vote

    favorite












    I use my function keys for specific applications (F1 chrome, F2 terminal, etc). I have a script bound to a shortcut key to activate the right application, and that works, but it doesn't activate the most-recently-focused window. The script lists windows with wmctrl -lx which seems to list windows by reverse-creation order. Is there any way to ask for or keep track of the order specific windows are activated so I can script "activate the most recent terminal window"?



    Alternately, it seems if I was able to get the window stack order maintained by xfwm4 (which it uses when you cycle through windows), that seems like it would solve my problem as well but I don't see a command line interface to get at that window stack order.







    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I use my function keys for specific applications (F1 chrome, F2 terminal, etc). I have a script bound to a shortcut key to activate the right application, and that works, but it doesn't activate the most-recently-focused window. The script lists windows with wmctrl -lx which seems to list windows by reverse-creation order. Is there any way to ask for or keep track of the order specific windows are activated so I can script "activate the most recent terminal window"?



      Alternately, it seems if I was able to get the window stack order maintained by xfwm4 (which it uses when you cycle through windows), that seems like it would solve my problem as well but I don't see a command line interface to get at that window stack order.







      share|improve this question













      I use my function keys for specific applications (F1 chrome, F2 terminal, etc). I have a script bound to a shortcut key to activate the right application, and that works, but it doesn't activate the most-recently-focused window. The script lists windows with wmctrl -lx which seems to list windows by reverse-creation order. Is there any way to ask for or keep track of the order specific windows are activated so I can script "activate the most recent terminal window"?



      Alternately, it seems if I was able to get the window stack order maintained by xfwm4 (which it uses when you cycle through windows), that seems like it would solve my problem as well but I don't see a command line interface to get at that window stack order.









      share|improve this question












      share|improve this question




      share|improve this question








      edited Apr 21 at 2:56
























      asked Apr 20 at 22:49









      Peter Lyons

      1741210




      1741210




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          In a script, you could use wmctrl, xprop and awk to use the activation time that is maintained by the window manager. (See e.g. wm-spec 1.5). E.g., use a (multi-line) command line like the following:



          W=$(wmctrl -l | 
          awk '$ ~ "Terminal" print $1;' | while read x ; do
          echo "$x $(xprop -id $(xprop -id $x
          | awk '$1 ~ /_NET_WM_USER_TIME/ print $NF'
          )
          | awk 'print $NF'
          )" ;
          done | awk '$2>t i=$1; t=$2 END print i'
          )


          In words:



          1. pass the wmctrl list through a filtering to select the window ids of the named application ("Terminal" in the example above); then

          2. pass this through (innermost) xprop to get a (pretend) window id for the last usage time, and

          3. using another (outer) xprop to get that timestamp , which is the (single) property of the "pretend window" of the _NET_WM_USER_TIME_WINDOW of the original window; then

          4. pass all the resulting id and timestamp lines through an awk filter that reports the id with the greatest timestamp.





          share|improve this answer





















          • This almost works but it seems some of my windows report _NET_WM_USER_TIME: not found.. Any idea why some windows have this but others don't?
            – Peter Lyons
            Apr 21 at 2:44










          • No idea, really. Maybe "compositing"? Particular application(s) that evade(s) (some) window management?
            – Ralph Rönnquist
            Apr 21 at 2:57











          • Maybe some windows hold the timestamp directly, without having the _NET_WM_USER_TIME_WINDOW property? The step 2-3 filtering doesn't handle that well.
            – Ralph Rönnquist
            Apr 21 at 3:00











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f439037%2fhow-to-activate-most-recently-focused-app-window-in-xfce4-xfwm4%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          In a script, you could use wmctrl, xprop and awk to use the activation time that is maintained by the window manager. (See e.g. wm-spec 1.5). E.g., use a (multi-line) command line like the following:



          W=$(wmctrl -l | 
          awk '$ ~ "Terminal" print $1;' | while read x ; do
          echo "$x $(xprop -id $(xprop -id $x
          | awk '$1 ~ /_NET_WM_USER_TIME/ print $NF'
          )
          | awk 'print $NF'
          )" ;
          done | awk '$2>t i=$1; t=$2 END print i'
          )


          In words:



          1. pass the wmctrl list through a filtering to select the window ids of the named application ("Terminal" in the example above); then

          2. pass this through (innermost) xprop to get a (pretend) window id for the last usage time, and

          3. using another (outer) xprop to get that timestamp , which is the (single) property of the "pretend window" of the _NET_WM_USER_TIME_WINDOW of the original window; then

          4. pass all the resulting id and timestamp lines through an awk filter that reports the id with the greatest timestamp.





          share|improve this answer





















          • This almost works but it seems some of my windows report _NET_WM_USER_TIME: not found.. Any idea why some windows have this but others don't?
            – Peter Lyons
            Apr 21 at 2:44










          • No idea, really. Maybe "compositing"? Particular application(s) that evade(s) (some) window management?
            – Ralph Rönnquist
            Apr 21 at 2:57











          • Maybe some windows hold the timestamp directly, without having the _NET_WM_USER_TIME_WINDOW property? The step 2-3 filtering doesn't handle that well.
            – Ralph Rönnquist
            Apr 21 at 3:00















          up vote
          1
          down vote













          In a script, you could use wmctrl, xprop and awk to use the activation time that is maintained by the window manager. (See e.g. wm-spec 1.5). E.g., use a (multi-line) command line like the following:



          W=$(wmctrl -l | 
          awk '$ ~ "Terminal" print $1;' | while read x ; do
          echo "$x $(xprop -id $(xprop -id $x
          | awk '$1 ~ /_NET_WM_USER_TIME/ print $NF'
          )
          | awk 'print $NF'
          )" ;
          done | awk '$2>t i=$1; t=$2 END print i'
          )


          In words:



          1. pass the wmctrl list through a filtering to select the window ids of the named application ("Terminal" in the example above); then

          2. pass this through (innermost) xprop to get a (pretend) window id for the last usage time, and

          3. using another (outer) xprop to get that timestamp , which is the (single) property of the "pretend window" of the _NET_WM_USER_TIME_WINDOW of the original window; then

          4. pass all the resulting id and timestamp lines through an awk filter that reports the id with the greatest timestamp.





          share|improve this answer





















          • This almost works but it seems some of my windows report _NET_WM_USER_TIME: not found.. Any idea why some windows have this but others don't?
            – Peter Lyons
            Apr 21 at 2:44










          • No idea, really. Maybe "compositing"? Particular application(s) that evade(s) (some) window management?
            – Ralph Rönnquist
            Apr 21 at 2:57











          • Maybe some windows hold the timestamp directly, without having the _NET_WM_USER_TIME_WINDOW property? The step 2-3 filtering doesn't handle that well.
            – Ralph Rönnquist
            Apr 21 at 3:00













          up vote
          1
          down vote










          up vote
          1
          down vote









          In a script, you could use wmctrl, xprop and awk to use the activation time that is maintained by the window manager. (See e.g. wm-spec 1.5). E.g., use a (multi-line) command line like the following:



          W=$(wmctrl -l | 
          awk '$ ~ "Terminal" print $1;' | while read x ; do
          echo "$x $(xprop -id $(xprop -id $x
          | awk '$1 ~ /_NET_WM_USER_TIME/ print $NF'
          )
          | awk 'print $NF'
          )" ;
          done | awk '$2>t i=$1; t=$2 END print i'
          )


          In words:



          1. pass the wmctrl list through a filtering to select the window ids of the named application ("Terminal" in the example above); then

          2. pass this through (innermost) xprop to get a (pretend) window id for the last usage time, and

          3. using another (outer) xprop to get that timestamp , which is the (single) property of the "pretend window" of the _NET_WM_USER_TIME_WINDOW of the original window; then

          4. pass all the resulting id and timestamp lines through an awk filter that reports the id with the greatest timestamp.





          share|improve this answer













          In a script, you could use wmctrl, xprop and awk to use the activation time that is maintained by the window manager. (See e.g. wm-spec 1.5). E.g., use a (multi-line) command line like the following:



          W=$(wmctrl -l | 
          awk '$ ~ "Terminal" print $1;' | while read x ; do
          echo "$x $(xprop -id $(xprop -id $x
          | awk '$1 ~ /_NET_WM_USER_TIME/ print $NF'
          )
          | awk 'print $NF'
          )" ;
          done | awk '$2>t i=$1; t=$2 END print i'
          )


          In words:



          1. pass the wmctrl list through a filtering to select the window ids of the named application ("Terminal" in the example above); then

          2. pass this through (innermost) xprop to get a (pretend) window id for the last usage time, and

          3. using another (outer) xprop to get that timestamp , which is the (single) property of the "pretend window" of the _NET_WM_USER_TIME_WINDOW of the original window; then

          4. pass all the resulting id and timestamp lines through an awk filter that reports the id with the greatest timestamp.






          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Apr 21 at 1:31









          Ralph Rönnquist

          2,36738




          2,36738











          • This almost works but it seems some of my windows report _NET_WM_USER_TIME: not found.. Any idea why some windows have this but others don't?
            – Peter Lyons
            Apr 21 at 2:44










          • No idea, really. Maybe "compositing"? Particular application(s) that evade(s) (some) window management?
            – Ralph Rönnquist
            Apr 21 at 2:57











          • Maybe some windows hold the timestamp directly, without having the _NET_WM_USER_TIME_WINDOW property? The step 2-3 filtering doesn't handle that well.
            – Ralph Rönnquist
            Apr 21 at 3:00

















          • This almost works but it seems some of my windows report _NET_WM_USER_TIME: not found.. Any idea why some windows have this but others don't?
            – Peter Lyons
            Apr 21 at 2:44










          • No idea, really. Maybe "compositing"? Particular application(s) that evade(s) (some) window management?
            – Ralph Rönnquist
            Apr 21 at 2:57











          • Maybe some windows hold the timestamp directly, without having the _NET_WM_USER_TIME_WINDOW property? The step 2-3 filtering doesn't handle that well.
            – Ralph Rönnquist
            Apr 21 at 3:00
















          This almost works but it seems some of my windows report _NET_WM_USER_TIME: not found.. Any idea why some windows have this but others don't?
          – Peter Lyons
          Apr 21 at 2:44




          This almost works but it seems some of my windows report _NET_WM_USER_TIME: not found.. Any idea why some windows have this but others don't?
          – Peter Lyons
          Apr 21 at 2:44












          No idea, really. Maybe "compositing"? Particular application(s) that evade(s) (some) window management?
          – Ralph Rönnquist
          Apr 21 at 2:57





          No idea, really. Maybe "compositing"? Particular application(s) that evade(s) (some) window management?
          – Ralph Rönnquist
          Apr 21 at 2:57













          Maybe some windows hold the timestamp directly, without having the _NET_WM_USER_TIME_WINDOW property? The step 2-3 filtering doesn't handle that well.
          – Ralph Rönnquist
          Apr 21 at 3:00





          Maybe some windows hold the timestamp directly, without having the _NET_WM_USER_TIME_WINDOW property? The step 2-3 filtering doesn't handle that well.
          – Ralph Rönnquist
          Apr 21 at 3:00













           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f439037%2fhow-to-activate-most-recently-focused-app-window-in-xfce4-xfwm4%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)