ratpoison-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RP] select patch


From: Johannes Altmanninger
Subject: Re: [RP] select patch
Date: Fri, 20 Jun 2014 14:17:01 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

Hi Jeff,
Thanks for you patience.
The function pointer seems to work in a test program, but I get this warning:

gcc -o test test.c
test.c: In function ‘main’:
test.c:9:45: warning: initialization from incompatible pointer type
   compare_window_name_function my_compare = strncmp;
                                             ^
Meanwhile, I have done the following
I have commented out the read_window() function since it is not used anywhere, and it calls find_window_name(), which works a bit different now.
cmd_select works now as expected:
    first it tries to find an exact match
    then a case-insensitive match
    then a prefix match
    and finally a case-insensitive prefix match
Then the first match is selected.
I have added the "selectstyle" setting that can be set to "simple" or "cycle"
If it is on "cycle", the program looks for a matching window as described above,
but if the window is the same as the currently selected it tries to find another one within the current match_level
  (so if you have 2 windows named "Foo" and "foobar", then "select foo" will only match "Foo")

I have attached the current diff, it works now as expected.
I have defined the MATCH constants in window.h since find_window_name() is the only thing using them, should they be put elsewhere? (they look a bit odd)

Now I am gonna try to refactor find_window_name() . How can I get rid of the warning above?

On 06/20/2014 12:56 PM, Jeff Abrahamson wrote:
Hi, Johannes.

Using char curname[MAX_WINDOW_NAME_LENGTH] is easiest.  This is called stack allocation, and has the advantage that it is automatically cleaned up when the scope exits.

A function pointer is just a variable to which you assign a pointer.  Using typedefs helps immensely to get it right.  I think you're close, but I'd need to check with a compiler to make sure I haven't myself made a syntax error.  Something like

typedef int (*compare_window_name_function)(char *name1, char *name2, int length);
compare_window_name_function my_compare = strcmp;

if((*my_compare)(a_name, another_name, 10)) { printf("yeah!\n"); }

(I haven't compiled that, it's probably slightly wrong.)


Jeff Abrahamson
+33 6 24 40 01 57   <-- brièvement indisponible le 4 juillet
+44 7920 594 255    <-- will change 18 July

http://jeff.purple.com/
http://blog.purple.com/jeff/


Attachment: select.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]