Changeset 285bc9a for global.c


Ignore:
Timestamp:
Apr 28, 2010, 2:27:58 PM (14 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.7, release-1.8, release-1.9
Children:
f9f88f3
Parents:
1f3a423
git-author:
David Benjamin <davidben@mit.edu> (04/28/10 13:12:12)
git-committer:
David Benjamin <davidben@mit.edu> (04/28/10 14:27:58)
Message:
Refactor the ioctl and size work into a separate function
File:
1 edited

Legend:

Unmodified
Added
Removed
  • global.c

    r1f3a423 r285bc9a  
    467467}
    468468
     469/*
     470 * Compute the size of the terminal. Try a ioctl, fallback to other stuff on
     471 * fail.
     472 */
     473static void _owl_global_get_size(int *lines, int *cols) {
     474  struct winsize size;
     475  /* get the new size */
     476  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
     477  if (size.ws_row) {
     478    *lines = size.ws_row;
     479  } else {
     480    *lines = LINES;
     481  }
     482
     483  if (size.ws_col) {
     484    *cols = size.ws_col;
     485  } else {
     486    *cols = COLS;
     487  }
     488}
     489
    469490void owl_global_resize(owl_global *g, int x, int y) {
    470491  /* resize the screen.  If x or y is 0 use the terminal size */
    471   struct winsize size;
    472    
    473492  if (!g->resizepending) return;
    474493  g->resizepending = 0;
     
    478497  }
    479498
    480   /* get the new size */
    481   ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
    482   if (x==0) {
    483     if (size.ws_row) {
    484       g->lines=size.ws_row;
    485     } else {
    486       g->lines=LINES;
    487     }
    488   } else {
    489       g->lines=x;
    490   }
    491 
    492   if (y==0) {
    493     if (size.ws_col) {
    494       g->cols=size.ws_col;
    495     } else {
    496       g->cols=COLS;
    497     }
    498   } else {
    499     g->cols=y;
     499  _owl_global_get_size(&g->lines, &g->cols);
     500  if (x != 0) {
     501    g->lines = x;
     502  }
     503  if (y != 0) {
     504    g->cols = y;
    500505  }
    501506
Note: See TracChangeset for help on using the changeset viewer.