LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C-Programming Question (https://www.linuxquestions.org/questions/programming-9/c-programming-question-4175657578/)

removed001 07-17-2019 03:50 PM

C-Programming Question
 
Hi.

I have some little experience in C-Programming. I know how to have a program (its icon) sitting in sys-tray and offering a menu when clicked.

But now I need to have a program sitting in sys-tray waiting for a keyboard short-cut and calling a function if the key was stroked - nothing else.

Any code examples for this issue?

Thanks in advance.

BW-userx 07-17-2019 04:27 PM

I have no idea other than

has focus (icon)
loop
on key-press event.
if match
trigger app.

can it be done, ???? donno..

Otherwise it'd have to be a big loop that has to have access to the desktop to capture keystrokes. You might be able to just give a keyboard SC for whatever desktop you're using the command to fire off an app. that'd be what I'd do. and forget about programming anything to do with that icon doing it.

removed001 07-17-2019 10:07 PM

Hi.

Yes, that's exactly what I want: a loop until the keyboard short-cut was pressed.

I think it has to be added either to this function

Code:

// Create Tray Icon
static GtkStatusIcon *create_tray_icon()
{
        tray_icon = gtk_status_icon_new();
        g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_menu_left), NULL);
        g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu_right), NULL);
        a_pixbuf=gdk_pixbuf_new_from_file("/usr/share/pixmaps/restore.png",&gerror);
        gtk_status_icon_set_from_pixbuf(tray_icon,a_pixbuf);
        gtk_status_icon_set_tooltip(tray_icon, _("Desktop Refresher"));
        gtk_status_icon_set_visible(tray_icon, TRUE);
        return tray_icon;
}

or probably to this function

Code:

// Main Program
int main(int argc, char **argv)
{
        gtk_init(&argc, &argv);
        setlocale( LC_ALL, "" );
        bindtextdomain( "refresh_my_desktop", "/usr/share/locale" );
        textdomain( "refresh_my_desktop" );
        tray_icon = create_tray_icon();
        gtk_main();
        return 0;
}

I know I could implement this also into the window manager (openbox, jwm etc.), but I don't want to. I want to have a binary sitting in the system tray waiting for my keyboard short-cut.

BW-userx 07-18-2019 07:15 AM

I want to have a binary sitting in the system tray waiting for my keyboard short-cut.
that logic itself is in error. binaries do not sit on the system tray, they are kept elsewhere within the system, for one.

two the system is not written as such to operate as such.
The icon button is used as a mechanism to call a binary or script to preform an action.

you do understand the concept of , "has focus" and how that is obtained? Mostly by a mouse cursor, and if a mouse cursor is needed to be used to gain focus on an object, say an icon that if pressed starts an application, then having to move this cursor over top of the icon to gain focus by using ones hand, what is to stop them from just clicking the mouse button to start the application? Instead of moving the mouse cursor over top of the icon then removing ones hand from that mouse unto the keyboard then hitting the keys required to start the app?

Why not just click the icon instead?

I do hope you see what I am getting at here.

Actually sit there and (re)think out the steps required to preform the operation. Frist to start an app that the icon belongs to using a mouse, and then a keyboard.

I am not trying to discourage you from programming, just trying to nudge you over some to applying a little more logical thought to it while you're programming.

look into events - ie HasFocus event if you still find yourself needing to go down that road. I do not know the exact function call. but yeah... search.. GTK and keyboard shortcuts.


The object has to have focus in order to talk to it. Unless it is hard coded to preform an action within itself.

what you are asking to do. You would still have to go through the desktop to remove focus on whatever has focus then put that onto your button.

this requires finding out what has focus first. then removing it. how does one find out what has focus?

you would need to ask the desktop manager what has focus then request to remove that focus from the object that has it and give it to that button.

think about, and find out what actions need to be preform in order to obtain a line of communication with your desktop using a keyboard.

removed001 07-18-2019 02:10 PM

Quote:

that logic itself is in error.binaries do not sit on the system tray, they are kept elsewhere within the system, for one.
Darn, this is kind of "hair splitting" (literally tranlsated from "Haare spalten") and not really of any kind of help!

Quote:

Why not just click the icon instead?

I do hope you see what I am getting at here.

Actually sit there and (re)think out the steps required to preform the operation. Frist to start an app that the icon belongs to using a mouse, and then a keyboard.
Ok, probably I should have mentioned what I want to achieve.

My problem is to NOT to find the mouse cursor on the screen after a long period of not using it. So I want to hit a keyboard short-cut to make the mouse "visible" for my poor eye-light. Therefor I have a small bash program that pops up on the position of the mouse offering a ca. 48 pixel sized GUI to click simply out of the way after finding the mouse cursor.

So, I just CAN'T use the mouse to click that ICON of the binary in the system tray.

I hope it's fully explained now.

Sorry for any confusion...

BW-userx 07-18-2019 02:23 PM

Quote:

Originally Posted by RSH (Post 6016393)
Darn, this is kind of "hair splitting" (literally tranlsated from "Haare spalten") and not really of any kind of help!


Ok, probably I should have mentioned what I want to achieve.

My problem is to NOT to find the mouse cursor on the screen after a long period of not using it. So I want to hit a keyboard short-cut to make the mouse "visible" for my poor eye-light. Therefor I have a small bash program that pops up on the position of the mouse offering a ca. 48 pixel sized GUI to click simply out of the way after finding the mouse cursor,

So, I just CAN'T use the mouse to click that ICON of the binary in the system tray.

I hope it's fully explained now.

Sorry for any confusion...

so you've already have a script/program that when executed shows you where the mouse cursor is. I'd still attach that to the keyboard itself via the desktop shortcut menu.

because of the limitations or design of an application has to have focus in order for it to do what it needs to do within a windowed environment, to my knowledge.

The window manager keeps track of what has focus. It can be keyboard, or mouse driven. If keyboard driven then it is the desktop that takes care of it, mouse driven then it is through the mouse cursor, but still the desktop keeps track of the mouse position.


here are two links that deal with this issue of showing mouse cursor.

https://askubuntu.com/questions/5378...e-mouse-cursor

https://www.ihaveapc.com/2013/01/qui...x-mint-ubuntu/

smallpond 07-18-2019 03:22 PM

Rather than spin in a loop burning CPU cyles, register for X-Windows events and process them to get the one you want.

https://www.ict.griffith.edu.au/anth...t_handling.txt

removed001 07-31-2019 10:06 PM

Thanks @all.

For now I'm using another mouse cursor type which is some bigger and I changed my wallpapers. Probably I decide to include this into the window managers .xml files.


All times are GMT -5. The time now is 10:32 PM.