NCURSES doesn't show scrollbars in elementryOS terminal - c

I've been using NCURSES library for my assignment, but there is one big problem with it.
I can't make it to show the scrollbars on the terminal window. I've tried anything I found here but none of them seems to work.
I found this code portion in StackExhcange but even this doesn't show schrollbars.
#include <ncurses.h>
int main(void)
{
int i = 0;
initscr();
scrollok(stdscr,TRUE);
while(i<500) {
printw("%3d - lots and lots of lines flowing down the terminal\n", i);
++i;
refresh();
}
getchar();
endwin();
return 0;
}
Is it a problem with elementaryOS because I've heard it's been modified.

Two possibilities:
The terminal description is probably using the xterm alternate screen feature. Some terminals don't display scrollbars when using the alternate screen because scrolling is disabled. For instance, VTE, which is the real terminal you're using by default has (hardcoded) behavior in this mode to translate your scrolling into up/down cursor keys.
OP expects curses applications to display scrollbars. They don't, unless the application simulates scrollbars.
For example, dialog does the latter. Here's an example:

Related

Windows API: Programmatically moving the Windows IME Input box possible?

Question
On Windows, if a program does not use one of the native APIs to produce a GUI, then Windows IME shows a tiny Textbox in the upper left corner to input IME strings, as is the case with Japanese.
Can this textbox be moved programmatically via the Windows API? I just want it moved roughly where the text input happens, so it's not so jarring having to look in the upper left corner all the time. Can someone point me in the right direction, what to read where to search?
Details
I have an OpenGL Program with a simple Immediate-Mode GUI Toolkit on top. As such this program does not interface with the OS's GUI capabilities in any meaningful way to provide OS native behaviour or accessibility functions. For my use-case, similar to many video games, this is fine. If I have textboxes inside the program however, inputting text via Windows or Google IME is an awful experience and I would like to improve it. I am not looking to integrate with Windows any more that this, just moving the IME Textbox roughly to the correct position of the "in program" textbox. It is compiled with MinGW64 and I already used Win32 API functions like changing the program's window and taskbar icon. Is this a possibility via the Win32 api?
The following code works in moving the IME position from default to current cursor position:
if (msg.message == WM_IME_STARTCOMPOSITION) { // msg is windows message
HIMC imc = ImmGetContext(msg.hwnd);
COMPOSITIONFORM cf;
cf.dwStyle = CFS_FORCE_POSITION;
POINT ptPos;
bool ret = GetCursorPos(&ptPos);
if (ret)
{
cf.ptCurrentPos.x = ptPos.x;
cf.ptCurrentPos.y = ptPos.y;
}
ImmSetCompositionWindow(imc, &cf);
ImmReleaseContext(msg.hwnd, imc);
}
WM_IME_STARTCOMPOSITION is a message type which windows sends to application when it starts IME. In your application when you peek or process windows messages try to catch for WM_IME_STARTCOMPOSITION and then force set the IME composition window position.

Make a layer in terminal

I'm trying to make a simple autocompletion tool for my program, and i would it look like as this picture : https://github-camo.global.ssl.fastly.net/ac6492f955c9d8027b6f691e1e3df6052fa16599/687474703a2f2f6e6f736d696c65666163652e72752f696d616765732f63636f6465322e706e67
There are termcaps who can help me to make this ? As a little "te" "ti" capabilities ?
Thank you.
Generally, you cannot get the screen contents, because some people view the notion of an escape sequence which can return the screen contents as a security problem.
The xterm ti/te termcap capabilities do not return the information on the screen. Instead, they tell xterm to switch between the normal and alternate screen buffers. But those cover the entire screen -- not a portion of it as your example suggests. Also, these sequences are sent by any conventional application at the beginning and end of "full-screen" mode -- so your application is likely already using the alternate screen.
Instead, your application has to keep track of what it puts on the screen, so that it can repaint after the popup window goes away. That is something that ncurses, for example, is designed to do.

Ncurses: Refreshing a non-overlapping window refreshes the whole screen. How to avoid this?

I am hacking together a ncurses application which uses 5 windows:
statusbar window - 1 X COLS right at the bottom of the screen.
titlebar window - 1 X COLS right at the top of the screen.
3 content windows - LINES - 2 X COLS, inbetween the statusbar and titlebar.
Note that there are 3 content windows, which entirely overlap each other. I am manually deciding which is to be redrawn. The titlebar and statusbar windows do not overlap any other window.
One use case is for the user to choose a file to upload to a network daemon using a menu in one of the content windows. Upon selecting a file, the statusbar acts as a crude progressbar, drawing some hashes to indicate how far the file has been uploaded.
What this boils down to is using:
wclear(status);
mvwprintw(status, ...);
wrefresh(status);
This works, but for some reason causes the entire screen to be redrawn, causing a horrible flickery mess. Having read the manual, I can not see why this should be the case; as long as the statusbar does not overlap any other windows, redrawing the statusbar should not cause a whole screen redraw?
Am I correct, or have I misunderstood? Is there a way to prevent this?
The code is here:
https://github.com/vext01/hgd/blob/master/nchgdc.c#L812
Note, the code is vastly unfinished and lacks polish =)
My ncurses implementation is that of OpenBSD.
From the wclear man page:
The clear and wclear routines are like erase and werase, but they also
call clearok, so that the screen is cleared completely on the next call
to wrefresh for that window and repainted from scratch.

How do we simulate a mouse click with Xlib / C?

I want to find C / Xorg code to 'enter' a left mouse button click. I'd expect a single line of code but the only things I've found written in C are about two dozen lines long and they don't work anyway :( It seems it can be done in Windows, but I'm in Linux.
The reason for the question is that I've written a utility that lets me move my mouse pointer between several screens using the keyboard. The only problem is that if I move to a location where window abc used to be but another window xyz has been loaded on top of that same location, the mouse pointer moves to xyz just fine, but xyz doesn't have focus -- until I left click the mouse. So, I want to build the 'click' into my code.
The code I tried that didn't work was based on XSendEvent().
Yes, I've more or less come to understand. Anyway it seems this is the way:
{
#include <X11/extensions/XTest.h>
XTestFakeButtonEvent(display, 1, True, CurrentTime);
XTestFakeButtonEvent(display, 1, False, CurrentTime);
XFlush(display);
}
... and add " -lXtst " to the LDFLAGS line in the Makefile.
Xlib seems to be so bloody difficult. I've had advice to use other libraries, I wish I knew how to go about changing over.
Thanks R.
Why not just directly raise/focus the window rather than trying to make a fake click event? That should be a lot more reliable and work with all window managers, even non-click-to-focus ones.
xdotool is the easy way of doing this. It's a command line tool. You can use it in simple scripts. For example:
#!/bin/sh
xdotool mousemove x y
xdotool click 1

Mouse movement events in NCurses

I wonder if there is such a thing as mouse movement events in NCurses, and if there is a way to catch them. Following the Interfacing with the mouse (from the NCurses programming HOWTO) it seems that by enabling the REPORT_MOUSE_POSITION bit in the call to mousemask, one can indeed catch mouse movement events.
So, I tried that and it does not seem to work. I have something like this:
int ch, count=0;
mmask_t old;
initscr ();
noecho ();
cbreak ();
mousemask (ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, &old);
keypad (stdscr, TRUE);
while ((ch = getchar ()) != 'q')
{
count++;
if (ch == KEY_MOUSE)
{
MEVENT event;
assert (getmouse (&event) == OK);
mvprintw (0, 0, "Mouse Event!\n");
}
mvprintw (1, 1, "Event number %4d",count);
}
...
I expected that as I'll move my mouse cursor, I'll see the event counter increasing. But it didn't. I also tried moving it while mouse button 1 is down to see if generates "drag" events, and it also didn't do anything. The question is, if it's simply a problem of my terminal emulator? Or maybe I'm misunderstanding what NCurses considers as mouse movement events? All the other mouse events were received (and I can operate programs in the console that use the mouse).
I tried gnome-terminal, xterm, and some other stuff. I also tried a textual environment (without X) by going to the tty's of my linux machine (Fedora 15, Ctrl+Alt+F2) and that did not work.
Finally, assuming I do get this right and those events should be reported, what is the bstate field of a MEVENT for a mouse movement evenet?
Many thanks in advance!
You need:
a terminal which supports mouse event reporting;
$TERM pointing to a terminfo entry which has an appropriate XM entry to initialise the terminal correctly.
xterm at least satisfies (1); for (2), it's likely that you'll need to set a different value for TERM.
Try:
TERM=xterm-1002 to get a position event when the cursor moves to a different cell while a button is being held down; or
TERM=xterm-1003 to always get a position event whenever the cursor moves to a different cell, even if no button is pressed.
The resulting events have the REPORT_MOUSE_POSITION bit set on the bstate field.
(The "PORTABILITY" section of the curs_mouse(3x) man page describes the terminal initialisation, and the "Mouse Tracking" section of the Xterm Control Sequences documentation describes the relevant "private mode" extensions.)
The code that you've given above needs to use getch(), not getchar(); and needs a refresh() inside the loop! Other than that, it works for me with xterm when using one of the appropriate TERM settings.

Resources