zsh-workers
 help / color / mirror / code / Atom feed
* Changes to xrandr completion
@ 2013-01-05 19:14 Kovacsics Robert
  2013-01-05 20:15 ` Christian Neukirchen
  2013-01-15 18:50 ` gi1242+zsh
  0 siblings, 2 replies; 4+ messages in thread
From: Kovacsics Robert @ 2013-01-05 19:14 UTC (permalink / raw)
  To: zsh-workers


[-- Attachment #1.1: Type: text/plain, Size: 120 bytes --]

Hi!
I would like to add the changes in the patch file for a smarter xrandr
completion.
Thank you,
Robert Kovacsics

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: zsh_xrandr_completion.patch --]
[-- Type: text/x-patch, Size: 573 bytes --]

--- a/zsh-5.0.2/Completion/X/Command/_xrandr	2011-01-08 20:24:47.000000000 +0000
+++ b/zsh-5.0.2/Completion/X/Command/_xrandr	2013-01-05 19:09:53.564221743 +0000
@@ -4,8 +4,8 @@
 local outputs modes expl
 
 # User configurable. TODO -- styles?
-outputs=(LVDS1 TV1 VGA1)
-modes=(1280x800 1024x768 800x600 640x480)
+outputs=($(xrandr|sed -ne 's/^\([^[[:space:]]\+]*\) connected .*$/\1/p'))
+modes=($(xrandr|sed -ne 's/^[[:space:]]\+\([[:digit:]]\+x[[:digit:]]\+\).*$/\1/p'|sort -nr|uniq))
 
 _arguments \
   '(-d -display)'{-d,-display}':X display:_x_display' \

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Changes to xrandr completion
  2013-01-05 19:14 Changes to xrandr completion Kovacsics Robert
@ 2013-01-05 20:15 ` Christian Neukirchen
  2013-01-15 18:50 ` gi1242+zsh
  1 sibling, 0 replies; 4+ messages in thread
From: Christian Neukirchen @ 2013-01-05 20:15 UTC (permalink / raw)
  To: zsh-workers

Kovacsics Robert <kovirobi@gmail.com> writes:

> Hi!
> I would like to add the changes in the patch file for a smarter xrandr
> completion.
> Thank you,
> Robert Kovacsics
>
> --- a/zsh-5.0.2/Completion/X/Command/_xrandr	2011-01-08 20:24:47.000000000 +0000
> +++ b/zsh-5.0.2/Completion/X/Command/_xrandr	2013-01-05 19:09:53.564221743 +0000
> @@ -4,8 +4,8 @@
>  local outputs modes expl
>  
>  # User configurable. TODO -- styles?
> -outputs=(LVDS1 TV1 VGA1)
> -modes=(1280x800 1024x768 800x600 640x480)
> +outputs=($(xrandr|sed -ne 's/^\([^[[:space:]]\+]*\) connected .*$/\1/p'))
> +modes=($(xrandr|sed -ne 's/^[[:space:]]\+\([[:digit:]]\+x[[:digit:]]\+\).*$/\1/p'|sort -nr|uniq))
>  
>  _arguments \
>    '(-d -display)'{-d,-display}':X display:_x_display' \

Hah, I wanted to do something similar.  I'd propose to make it a
"zstyle -e" by default.

Also, you can use
${(uo)${(M)${(f)"$(xrandr)"}:#* connected*}%% *}
and
${(Mun)$(xrandr):#[0-9]##x[0-9]##}

-- 
Christian Neukirchen  <chneukirchen@gmail.com>  http://chneukirchen.org


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Changes to xrandr completion
  2013-01-05 19:14 Changes to xrandr completion Kovacsics Robert
  2013-01-05 20:15 ` Christian Neukirchen
@ 2013-01-15 18:50 ` gi1242+zsh
  2013-01-18 11:26   ` Oliver Kiddle
  1 sibling, 1 reply; 4+ messages in thread
From: gi1242+zsh @ 2013-01-15 18:50 UTC (permalink / raw)
  To: Kovacsics Robert; +Cc: zsh-workers

On Sat, Jan 05, 2013 at 07:14:45PM +0000, Kovacsics Robert wrote:

>  # User configurable. TODO -- styles?
> -outputs=(LVDS1 TV1 VGA1)
> -modes=(1280x800 1024x768 800x600 640x480)
> +outputs=($(xrandr|sed -ne 's/^\([^[[:space:]]\+]*\) connected .*$/\1/p'))
> +modes=($(xrandr|sed -ne 's/^[[:space:]]\+\([[:digit:]]\+x[[:digit:]]\+\).*$/\1/p'|sort -nr|uniq))

I'd recommend against this! On some (buggy) systems running xrandr polls
the displays / checks for connected displays, and sometimes blanks the
screen. (It sometimes takes time too).

On nVidia hardware I'm not sure what will happen.

Any chance you would consider an opt-in version by which xrandr is not
invoked, unless the user has an zstyle option set?

GI

-- 
I thought I had a back-up, but she refused to type it in again.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Changes to xrandr completion
  2013-01-15 18:50 ` gi1242+zsh
@ 2013-01-18 11:26   ` Oliver Kiddle
  0 siblings, 0 replies; 4+ messages in thread
From: Oliver Kiddle @ 2013-01-18 11:26 UTC (permalink / raw)
  To: zsh-workers

On 15 Jan, gi1242+zsh@gmail.com wrote:
> I'd recommend against this! On some (buggy) systems running xrandr polls
> the displays / checks for connected displays, and sometimes blanks the
> screen. (It sometimes takes time too).
> 
> On nVidia hardware I'm not sure what will happen.
> 
> Any chance you would consider an opt-in version by which xrandr is not
> invoked, unless the user has an zstyle option set?

It doesn't seem to matter on my nVidia hardware. At the very least the
function should use _call_program which does make it possible to disable
it. It's also better to only run the command when it actually is needed.
The patch below does this and also takes Christian Neukirchen's nested
zsh expansions instead of the mix of sed, sort and uniq.

Oliver

Index: Completion/X/Command/_xrandr
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/X/Command/_xrandr,v
retrieving revision 1.4
diff -u -r1.4 _xrandr
--- Completion/X/Command/_xrandr	5 Jan 2013 20:46:46 -0000	1.4
+++ Completion/X/Command/_xrandr	18 Jan 2013 11:19:05 -0000
@@ -1,13 +1,9 @@
 #compdef xrandr
-local context state line
-typeset -A opt_args
-local outputs modes expl
 
-# User configurable. TODO -- styles?
-outputs=($(xrandr|sed -ne 's/^\([^[[:space:]]\+]*\) connected .*$/\1/p'))
-modes=($(xrandr|sed -ne 's/^[[:space:]]\+\([[:digit:]]\+x[[:digit:]]\+\).*$/\1/p'|sort -nr|uniq))
+local curcontext="$curcontext" state line expl
+typeset -A opt_args
 
-_arguments \
+_arguments -C \
   '(-d -display)'{-d,-display}':X display:_x_display' \
   '-help[display help]' \
   '(-o --orientation)'{-o,--orientation}':rotation:(normal inverted left right 0 1 2 3)' \
@@ -25,18 +21,18 @@
   '--fb:size:' \
   '--fbmm:size:' \
   '--dpi:dpi:' \
-  "*--output:output to reconfigure:($outputs)" \
+  "*--output:output to reconfigure:->outputs" \
   '*--auto' \
-  "*--mode:mode:($modes)" \
+  "*--mode:mode:->modes" \
   '*--preferred' \
   '*--pos:position:' \
   '*--reflect:axes:(normal x y xy)' \
   '*--rotate:rotation:(normal inverted left right)' \
-  "*--left-of:relative position to:($outputs)" \
-  "*--right-of:relative position to:($outputs)" \
-  "*--above:relative position to:($outputs)" \
-  "*--below:relative position to:($outputs)" \
-  "*--same-as:relative position to:($outputs)" \
+  "*--left-of:relative position to:->outputs" \
+  "*--right-of:relative position to:->outputs" \
+  "*--above:relative position to:->outputs" \
+  "*--below:relative position to:->outputs" \
+  "*--same-as:relative position to:->outputs" \
   '*--set:property:(Backlight scaling\ mode):value:->value' \
   '*--scale:output scaling:' \
   '*--transform:transformation matrix:' \
@@ -48,15 +44,25 @@
   '--noprimary' \
   '*--newmode:name: :clock MHz: :hdisp: :hsync-start: :hsync-end: :htotal: :vdisp: :vsync-start: :vsync-end: :vtotal:' \
   '*--rmmode:Mode name:' \
-  "*--addmode:output:($outputs):name:" \
-  "*--delmode:output:($outputs):name:" \
+  "*--addmode:output:->outputs:name" \
+  "*--delmode:output:->outputs:name" \
   && return 0
 
-if [[ $state == value ]]; then
+case $state in
+  value)
     case $words[CURRENT-1] in
-	(scaling* mode)
-	    _description value expl "output property 'scaling mode'"
-	    compadd "$@" "$expl[@]" None Full Center Full\ aspect && return 0
-	    ;;
+      (scaling* mode)
+	_description value expl "output property 'scaling mode'"
+	compadd "$@" "$expl[@]" None Full Center Full\ aspect && return 0
+      ;;
     esac
-fi
+  ;;
+  outputs)
+    _wanted outputs expl output compadd \
+        ${(uo)${(M)${(f)"$(_call_program outputs xrandr)"}:#* connected*}%% *} && return 0
+  ;;
+  modes)
+    _wanted modes expl mode compadd \
+        ${(Mun)$(_call_program modes xrandr):#[0-9]##x[0-9]##} && return 0
+  ;;
+esac


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-01-18 11:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-05 19:14 Changes to xrandr completion Kovacsics Robert
2013-01-05 20:15 ` Christian Neukirchen
2013-01-15 18:50 ` gi1242+zsh
2013-01-18 11:26   ` Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).