Setting terminal size through c?

This is a discussion on Setting terminal size through c? within the C Programming forums, part of the General Programming Boards category; Originally Posted by Ravi Raj I am using this code: Code: void term_size(int *rows, int *cols) { struct winsize ws ...

  1. #16
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by Ravi Raj View Post
    I am using this code:

    Code:
    void
    term_size(int *rows, int *cols)
    {
        struct winsize ws = {*rows, *cols, 0, 0};
        int fd;
    
        /* Open the controlling terminal. */
        fd = open("/dev/tty", O_RDWR);
        if (fd < 0)
            exit(1);
    
        /* Get window size of terminal. */ 
        if (ioctl(fd, TIOCSWINSZ, &ws) < 0)
            exit(1);
    
        //*rows = ws.ws_row;
        //*cols = ws.ws_col;
    
        close(fd);    
    }
    In this case you would need to initialize your struct with *rows, *cols before you call ioctl(). But, it should not affect the actual Gnome window itself, but the used area inside. Have you looked for a Gnome api to see if there are something there that let's you do what you want?
    Last edited by Subsonics; 05-22-2012 at 09:28 AM. Reason: Changed the constant to TIOCSWINSZ

  2. #17
    Registered User Ravi Raj's Avatar
    Join Date
    May 2012
    Location
    INDIA
    Posts
    43
    Ok,

    Let me see first. Thanks for your quick reply Subsonics,

    I will let you all know, if I get proper solution.

  3. #18
    Registered User
    Join Date
    May 2010
    Posts
    2,697
    I really don't understand why you are trying to change the size of the terminal inside the terminal. Normally you would change the terminal before you run your program. Also what "terminal" are you actually trying to use? There are several "terminal" programs available in Linux, for example xterm, Gnome terminal, etc. See this link for more examples. Most of these terminal emulators have ways to set their size when called, check the documentation for the actual emulator you are using.

    Jim

  4. #19
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    @Ravi Raj:

    I may be confused, the changes would set your window size. I think you actually intended to get the size. Nevermind, I changed the constant to TIOCSWINSZ, which would then set the size to *rows, *cols.

  5. #20
    Registered User Ravi Raj's Avatar
    Join Date
    May 2012
    Location
    INDIA
    Posts
    43
    Quote Originally Posted by jimblumberg View Post
    I really don't understand why you are trying to change the size of the terminal inside the terminal. Normally you would change the terminal before you run your program. Also what "terminal" are you actually trying to use? There are several "terminal" programs available in Linux, for example xterm, Gnome terminal, etc. See this link for more examples. Most of these terminal emulators have ways to set their size when called, check the documentation for the actual emulator you are using.

    Jim
    Jim,
    Please read my earlier replies,

    I had already told that I want to change the size of gnome-terminal.

  6. #21
    Registered User
    Join Date
    May 2010
    Posts
    2,697
    Then why can't you change the size of the terminal before you run your program? If the terminal is being launched by another app, what app? You should be able to force the terminal to a certain size by using the geometry modifier:
    Code:
    gnome-terminal --geometry=80x15
    Jim

  7. #22
    Registered User Ravi Raj's Avatar
    Join Date
    May 2012
    Location
    INDIA
    Posts
    43
    Thanks Jim,

    That solved my problem.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to tell ncurses program terminal size
    By apawamajawa in forum Linux Programming
    Replies: 1
    Last Post: 07-20-2011, 02:04 AM
  2. Getting screen size - unix/linux terminal
    By enok in forum C++ Programming
    Replies: 3
    Last Post: 11-21-2009, 03:56 AM
  3. terminal window size
    By eight8ball in forum C Programming
    Replies: 5
    Last Post: 01-08-2009, 07:48 AM
  4. Setting Console Size
    By twomers in forum C++ Programming
    Replies: 4
    Last Post: 08-20-2006, 03:24 PM
  5. Setting the font size
    By Exile in forum Linux Programming
    Replies: 3
    Last Post: 02-21-2005, 05:38 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21