#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Unhappy Ncurses window placement


    Hey Devshed. I'm having an issue with getting a window to display on the rightmost side of the screen using ncurses. I just can't wrap my head around how, maybe it's a sleep thing. I got as far as using getmaxyx to determine the size of the stdscr(terminal width/height) but I just can't figure out how to get it over to where it needs to be, it ends up everywhere but there. Here's the function:

    Code:
     void eventfeed(void)
    {
        int maxy, maxx, halfy, halfx, nmaxy, nmaxx;
    
        getmaxyx(stdscr,maxy,maxx);
    
        halfx = maxx >> 1;
    
        refresh();
        WINDOW *feed;
        feed = newwin(maxy, 25, 0, halfx);
    
        box(feed, 0, 0);
        wrefresh(feed);
    }
    Which get's it close, but I need it on the edge of the screen. I know how to bind the window to the maximum height but I just can't get it over to the farthest right side. This is written in C.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    886
    Does the screen have an odd character width?

    Think about what happens when you divide an odd number by two and consider that you are using a fixed number of columns in your newwin() call.
    I no longer wish to be associated with this site.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by jwdonahue
    Does the screen have an odd character width?

    Think about what happens when you divide an odd number by two and consider that you are using a fixed number of columns in your newwin() call.
    I played around with some division but I think the bitwise(>>) is where I'm either making or breaking what I'm trying to do. It's kind of mysterious but on the tip of my tongue at the same time. I feel like it's there but I'm not seeing it/coming to the conclusion.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    886
    The width of the screen is in maxx yes? You set halfx equal to maxx/2, that's what the right shift does, it divides by two. So that is where you put the left edge of your window. Then you specify a fixed width of 25 columns for the size of the window! Depending on the value of maxx, that width might get you half way to the right edge of the console window or might take you past it. If you want to go right to the edge you have consider the fact that the parent window might not be exactly 50 columns wide, it might be 80 or maybe even 81.

    (80 >> 1) == (81 >> 1) == 40

    So the available columns to the edge of the parent window is 40 on an 80 character parent window and 41 on an 81 character parent window. You have to calculate the distance from halfx to the edge of the window. You can't just assume that halfx + 25 == maxx.
    Last edited by jwdonahue; April 14th, 2013 at 02:30 PM. Reason: Removed extra then and fixed typo.
    I no longer wish to be associated with this site.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    After a weeks worth of a headache, the answer to this was the max x coordinate minus the window size. In my case, window size was 25, in turn the drawn window overshot the standard screen by 25, you can try bitshifting to some degree of success but it depends on what you're trying to accomplish. I needed a very specific sized window with specific placement. So, I had to take a step back and find a second obvious approach. Here's the function as it stands now:

    Code:
     void eventfeed(void)
    {
        int maxy, maxx, newx;
    
        getmaxyx(stdscr, maxy, maxx);
    
        newx = maxx - 25;
    
        refresh();
        WINDOW *feed;
        feed = newwin(0, 25, 0, newx);
    
        box(feed, 0, 0);
        wrefresh(feed);
    }
    :cadrunk:

    @jwdonahue Thank you, I'd probably still be tossing up trigonometry and loopy division if you hadn't come along with your straight-forward advice.

    Lesson learned here.

IMN logo majestic logo threadwatch logo seochat tools logo