Add a scrollbar on Ncurses or make it like "more" - c++

Basically I am writing a client program which receives response and logs from server, the client is also able to send request to server for different information. I used curses and output looks pretty good. It looks like VI, output at the top and user on Client end enter command at the bottom. Only thing is I am not able to scroll back.. My boss told me to make it like "more command in linux" and I want to stick with my solution and add a scroll bar on the side for output window...
I was thinking Server sends logs randomly and it's nearly impossible (or too hard) to make it look like more...

If you maintain a list or array of lines in your client and ask ncurses to paint a range of lines as a sliding window, you can slide your window up and down in response to ^F ^B ^U ^D ^Y ^E commands, which just repaints the screen with different indexes.
I would skip trying to draw a scrollbar though: It would look out of place on a Linux system. Not even mc has scrollbars. Just show a content summary in the bottom line, similar to vim's Top, Bot, All, N% when :set ruler is turned on, that'll feel most at home.

I'm not entirely sure if you are asking about how to implement scrollback or how to draw a scrollbar with ncurses. My guess is the second.
Assuming your ncurses is compiled with Unicode support (remember to set the environment correctly when initializing ncurses, look into "setlang"), you can use following characters:
Unicode:
▲ - U+25B2 BLACK UP-POINTING TRIANGLE
▼ - U+25BC BLACK DOWN-POINTING TRIANGLE
▮ - U+25AE BLACK VERTICAL RECTANGLE
ASCII:
176 - ░ Light shaded block
177 - ▒ Medium shaded block
178 - ▓ Dark shaded block
219 - █ Block block
Writing the code to display the dark block at the right place should be quite straightforward.
If I understood your question wrong, my excuses.

Another possibility is to re-write your client as an IRC bot or an IM client. Users send messages either to the client directly or to a specific channel, and the bot performs the action and sends back any necessary replies.
The beauty is you get to skip all the user interface stuff yourself -- scroll back and history is handled via irssi or xchat or some other client. Users can run the client they like the most.
Logging can be handled via a central mechanism, published to the world, or given to specific managers / administrators as needs dictate.
The downside is that you have to maintain and run an IRC server or XMPP server. If you're already using them elsewhere in the organization, and it is appropriate to use them for this, the leverage might be worth it. If you're not already using one, the savings in the client might not be worth the expense of maintaining yet another service.
A team I was part of in the past loved having an IRC interface to BuildBot to report check-ins, build success, build failures, test success, test failures, for our continuous integration build and test setup.

Related

X11 - Blank out the screen

I am currently using a remote software to access a computer of mine. The problem is now: I dont want anyone to see what I am doing, so I am trying to write a little tool or script that will blank out the screen.
The software is accessing the picture data using the MIT-SHM extension of X11, so I seek a possiblity to keep X11 rendering the data into the SHM, but simply not forward it to the Monitor (as if the monitor is turned off). Is there any way? As a last resort I would use XVFB, but I would rather not...
P.S.: I am seeking a programmatic attempt. Either via BASH script or C/C++.
x11vnc has options like -clientdpms, -forcedpms.
What they essentially do is - to call dpms commands to blank out display, every time there is a mouse/keyboard action. So, the monitor is unblanked & blanked again. This is not really visible to eyes, because of the hysteresis of the monitor.
NOW, if you have access to that proprietary software's code, you can add a code to blank using dpms commands, after every kbd/mouse event.
Alternately, you can use a dirty hack to keep x11vnc -forcedpms -forever -allow 127.0.0.1 -clip 1x1+0+0 running in the background.

Intercept another window's output

I have the project to develop an application that would allow a computer to 'send' a window to another computer.
In order to do that, I need, of course, to capture the concerned window's output from my program.
Google searches leaded me to no relevant result, neither with libX11 nor libxcb.
I also tried to record screenshots with xwd and import, but as they are quite slow, I'm getting up to 3.5 fps
Any help on how I could do that will be welcome (either using libX11, libxcb, or something else)
By the way, I attempt to use c++ for this program
Thanks for reading,
Edit:
The fps test was made without sending files. It was just like "I took screenshots for 5 minutes, and I got 900 pictures"
I think you will need to record screenshots and compress them before sending over network to make things faster. Also, you would need to decrease the quality of the screenshots (user configurable) to make it faster.
Plus there are different techniques to send only the changes (diff of screenshots) to the other computer.

Black frames when using easyrtc with socket.io

we use EasyRTC for sending image captures from iPad (we create screenshots "manually" and send them via socket.io) to web browser. On the server we have EasyRTC v.1.0.12 and Socket.IO v.0.9.16. It's hard to say what happened (i've just joined the project and encountered this issue. PM says that it was ok some time ago) but recently we started to notice that some frames are blacked-out. We are debugging this issue for few days and we're running out of ideas. We are not sure where the problem is.
We now that we send correct images from the device. We noticed that it happens only when the image is different from previous one (but not always... it's easier to observe it on the weaker internet connection). When the image is "repeated" (i mean it looks the same but from iPad perspective we create it as new instance) everything is fine.
In attachment you can find info from Chrome network debugger. As you can see in thumbnails or images are ok. These with Size/Content from cache are ok but there with Size 0 and Content > 0 are ones which gives black screens when we want to draw them on the canvas.
Any idea what we're doing wrong? How to debug it? It seems that images are somehow downloaded later than we try to draw them?
Our server is on AWS.
You are trying to send the images up as base 64 encoded jpegs. Basically big text strings. The first thing you should be asking yourself is: is the text string I'm sending up getting to the server, or is it getting truncated? Check the length of the string being sent versus the length of the string being sent, and then check the start and ends of the string.
Finally we found the solution which is pretty easy. It turned out that we was trying to draw an image before it was fully loaded. So what we did was to move drawing code to image.onLoad method and now it works as expected.
img.src = "data:image/png;base64, <img content>";
img.onload = function(){
canvas.drawImage(img);
}

Why upon explorer window closing several GetClipboardData are launched?

I m developping a little soft to notify users when they are pasting content in unauthorized applications, i hook the GetClipboardData to do so. Nearly everything is working fine but when i copy content from Word for example, i click on InternetExplorer, i open an explorer window and close it, some GetClipboardData are launched from explorer. Can someone help me to understand that behavior ?
Thanks in advance
Regards
It is common to receive unexpected clipboard events from certain applications, mostly from Microsoft, when you do things like closing windows or doing anything that makes the application stop and think: "hey, maybe I left some crap on the clipboard, I'd better clean it up, maybe re-post it as plain text without the OLE stuff, maybe I already did that, but I can't remember, so I'll do it again." It's a sort of OCD that they build into just about everthing. Sometimes you get a pop-up saying "you've placed a large amount of data on the clipboard, would you like to make it available for other applications" when you quit a program. That's the same thing. Basically, they've put a bunch of formats on the clipboard that would require "delayed rendering" to be pasteable. And now the app is worried about leaving invalid data on the clipboard, so it has to re-post the data without the fancy formats.
You'll also get this if you copy a cell from Excel, and then un-highlight that cell.
If you get a clipboard event when STARTING an app, it's likely an add-in hooking into the clipboard chain, or perhaps committing the worst sin of all: copy/pasting its icon into a toolbar.

Grabbing events on specific keys with X11 on Linux

I'm writing a program in C++ to implement the keyboard backlight feature from OS X on MacBook Pro's running a Linux distro. So far, it turns the backlight on, on boot and if no keyboard and mouse events are registered for 20 seconds, it will turn it back off, and of course turn it on yet again when an event is registered. Next thing I need the program to do, is to capture keypresses on the keyboard-backlight-up/down keys, but I'm not sure how to approach this.
I am currently using XScreenSaverQueryInfo to get the idle time of keyboard and mouse events, so a method using X11 API would be okay. I have done a lot of googling but havent found a way that I felt sure about going with. The problem I'm seeing with lots of the methods I found, is that they use keycode to identify the key, but I dont think that would be a viable solution since the program should work for any keyboard-layout available.
Any idea of a method and API I should go with? What would work the best?
Regards,
The normal way to do this is with XGrabKey(). It uses keycodes, but you wouldn't hardcode the keycode, you'd get it with XKeysymToKeycode(). To be more correct you'd also want to redo the grab when you get a MappingNotify (XMappingEvent). (Note, MappingNotify, not MapNotify.) If there isn't a keysym for these keys - there probably isn't on old X versions, but hopefully newer X.org versions have one - then you just have to hardwire the keycode. Which won't be very robust or portable but probably works for everyone on Linux with the same hardware model.
Be prepared that key grabs are global, so if you try to XGrabKey() and something else has already grabbed that key, you'll get an X error - by default that exits the program. Another quirk of XGrabKey() is that it grabs the key with a precise modifier set. For example, to handle both with and without NumLock, you need to grab twice. See Global Hotkey with X11/Xlib
In a normal Linux setup (if you wanted to get a feature like this into upstream projects), the desktop environments don't want lots of separate apps fighting over the key grabs and getting errors. So there will be some central coordination points, such as the window manager or a special daemon might do all the keybindings and forward commands to other processes as needed. So you would probably want to look at patching the same upstream code that handles other special keys like this, if you were trying to get your feature integrated into distributions by default.
Another thing to be aware of is the Xkb API, which is a lot more complicated. There is some brain-bending way to grab keys with Xkb but I don't know of any advantage to going that route.
If you haven't done that yet, familiarize yourself with xev. Start it, give it the focus, and press the keys, to see what's happening.