select-layout command and some key bindings.

This commit is contained in:
Nicholas Marriott 2009-05-16 11:48:47 +00:00
parent 03af7c99b5
commit 1001902143
7 changed files with 138 additions and 7 deletions

View File

@ -1,5 +1,7 @@
16 May 2009
* select-layout command and a few default key bindings (M-0, M-1, M-2, M-9) to
select layouts.
* Recreate server socket on SIGUSR1, per SF feature request 2792533.
14 May 2009
@ -1261,7 +1263,7 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
$Id: CHANGES,v 1.289 2009-05-16 10:02:51 nicm Exp $
$Id: CHANGES,v 1.290 2009-05-16 11:48:47 nicm Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms

3
TODO
View File

@ -79,7 +79,6 @@
- attach should have a flag to create session if it doesn't exist
- layout/split stuff:
horiz split command, and similar resizing commands as for vert split
select-layout command
make manual layout a bit less of a hack and make it handle a grid
should the layout be a window option???
more layouts
@ -89,4 +88,4 @@
- document clear-history
- document paste in status line
- document SIGUSR1 behaviour
- document select-layout

86
cmd-select-layout.c Normal file
View File

@ -0,0 +1,86 @@
/* $Id: cmd-select-layout.c,v 1.1 2009-05-16 11:48:47 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include "tmux.h"
/*
* Switch window to selected layout.
*/
void cmd_select_layout_init(struct cmd *, int);
int cmd_select_layout_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_select_layout_entry = {
"select-layout", "selectl",
CMD_TARGET_WINDOW_USAGE " layout-name",
CMD_ARG1,
cmd_select_layout_init,
cmd_target_parse,
cmd_select_layout_exec,
cmd_target_send,
cmd_target_recv,
cmd_target_free,
cmd_target_print
};
void
cmd_select_layout_init(struct cmd *self, int key)
{
struct cmd_target_data *data;
cmd_target_init(self, key);
data = self->data;
switch (key) {
case KEYC_ADDESC('0'):
data->arg = xstrdup("manual");
break;
case KEYC_ADDESC('1'):
data->arg = xstrdup("even-horizontal");
break;
case KEYC_ADDESC('2'):
data->arg = xstrdup("even-vertical");
break;
case KEYC_ADDESC('9'):
data->arg = xstrdup("active-only");
break;
}
}
int
cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct winlink *wl;
int layout;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return (-1);
if ((layout = layout_lookup(data->arg)) == -1) {
ctx->error(ctx, "unknown or ambiguous layout: %s", data->arg);
return (-1);
}
if (layout_select(wl->window, layout) == 0)
ctx->info(ctx, "layout now: %s", layout_name(wl->window));
return (0);
}

3
cmd.c
View File

@ -1,4 +1,4 @@
/* $Id: cmd.c,v 1.94 2009-05-14 16:56:23 nicm Exp $ */
/* $Id: cmd.c,v 1.95 2009-05-16 11:48:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -72,6 +72,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_rotate_window_entry,
&cmd_save_buffer_entry,
&cmd_scroll_mode_entry,
&cmd_select_layout_entry,
&cmd_select_pane_entry,
&cmd_select_prompt_entry,
&cmd_select_window_entry,

View File

@ -1,4 +1,4 @@
/* $Id: key-bindings.c,v 1.71 2009-05-13 22:10:39 nicm Exp $ */
/* $Id: key-bindings.c,v 1.72 2009-05-16 11:48:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -119,6 +119,11 @@ key_bindings_init(void)
{ '{', 0, &cmd_swap_pane_entry },
{ '}', 0, &cmd_swap_pane_entry },
{ '\002', 0, &cmd_send_prefix_entry },
{ KEYC_ADDESC('0'), 0, &cmd_select_layout_entry },
{ KEYC_ADDESC('1'), 0, &cmd_select_layout_entry },
{ KEYC_ADDESC('2'), 0, &cmd_select_layout_entry },
{ KEYC_ADDESC('9'), 0, &cmd_select_layout_entry },
{ KEYC_ADDCTL(KEYC_DOWN), 1, &cmd_resize_pane_entry },
{ KEYC_PPAGE, 0, &cmd_scroll_mode_entry },
{ KEYC_ADDESC('n'), 0, &cmd_next_window_entry },
{ KEYC_ADDESC('p'), 0, &cmd_previous_window_entry },

View File

@ -1,4 +1,4 @@
/* $Id: layout.c,v 1.6 2009-05-04 17:58:27 nicm Exp $ */
/* $Id: layout.c,v 1.7 2009-05-16 11:48:47 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -18,6 +18,8 @@
#include <sys/types.h>
#include <string.h>
#include "tmux.h"
/*
@ -48,6 +50,39 @@ layout_name(struct window *w)
return (layouts[w->layout].name);
}
int
layout_lookup(const char *name)
{
u_int i;
int matched = -1;
for (i = 0; i < nitems(layouts); i++) {
if (strncmp(layouts[i].name, name, strlen(name)) == 0) {
if (matched != -1) /* ambiguous */
return (-1);
matched = i;
}
}
return (matched);
}
int
layout_select(struct window *w, u_int layout)
{
if (layout > nitems(layouts) - 1 || layout == w->layout)
return (-1);
w->layout = layout;
if (w->layout == 0) {
/* XXX Special-case manual. */
window_fit_panes(w);
window_update_panes(w);
}
layout_refresh(w, 0);
return (0);
}
void
layout_next(struct window *w)
{

5
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.317 2009-05-16 10:02:51 nicm Exp $ */
/* $Id: tmux.h,v 1.318 2009-05-16 11:48:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -1249,6 +1249,7 @@ extern const struct cmd_entry cmd_respawn_window_entry;
extern const struct cmd_entry cmd_rotate_window_entry;
extern const struct cmd_entry cmd_save_buffer_entry;
extern const struct cmd_entry cmd_scroll_mode_entry;
extern const struct cmd_entry cmd_select_layout_entry;
extern const struct cmd_entry cmd_select_pane_entry;
extern const struct cmd_entry cmd_select_prompt_entry;
extern const struct cmd_entry cmd_select_window_entry;
@ -1568,7 +1569,9 @@ void window_pane_mouse(struct window_pane *,
/* layout.c */
const char * layout_name(struct window *);
int layout_lookup(const char *);
void layout_refresh(struct window *, int);
int layout_select(struct window *, u_int);
void layout_next(struct window *);
void layout_previous(struct window *);