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: Thu, 19 Jun 2014 19:52:14 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0


Thanks for your feedback, I fixed most things, below is the current version

On 06/19/2014 07:25 PM, Jeff Abrahamson wrote:

Can you use a function pointer for your compare function so that you don't need to have the pre-processing block?
This sounds scary :-|
Well, let's see if i'll manage

#define MATCH                    0x0000
#define MATCH_PREFIX             0x0001
#define MATCH_IGNORECASE         0x0002

//not yet implemented
#define MATCH_BACKWARDS          0x0004

#define MATCH_PREFER_NOTSELECTED 0x0008

#define MAX_WINDOW_NAME_LENGTH   0x0fff

#include <ctype.h>

rp_window *
find_window_name_ (char *name, int match_type)
{
  int compare_length, i;
  if (MATCH_PREFIX & match_type)
    {
      compare_length = strlen(name);
    }
  else
    {
    compare_length = MAX_WINDOW_NAME_LENGTH;
    }
  if(MATCH_IGNORECASE & match_type)
    {
    for(i=0; i<strlen(name); i++)
        name[i] = toupper (name[i]);
    }

  rp_window_elem *cur;
  char *curname = NULL;
  int current_win_number = 0;
  rp_window *w = current_window();
  if (w)
    current_win_number = w->number;

  int may_return = 1;
  if (MATCH_PREFER_NOTSELECTED & match_type)
      may_return = 0;

  rp_window *first_match = NULL;

  list_for_each_entry (cur, &rp_current_group->mapped_windows, node)
    {
      strcpy(curname, window_name(cur->win));
      if(MATCH_IGNORECASE & match_type)
        for(i=0; i<strlen(curname); i++)
            curname[i] = toupper (curname[i]);
      if (!strncmp (name, curname, compare_length))
        {
          if (may_return)
            {
              return cur->win;
            }
          else
            {
              if(cur->win->number == current_win_number)
                may_return = 1;
              if(!first_match)
                first_match = cur->win;
            }
        }
    }
  /* didn't find it */
  return NULL;
}




reply via email to

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