LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-17-2019, 03:50 PM   #1
removed001
Member
 
Registered: Nov 2011
Location: Germany
Distribution: Puppy Linux (my own builds)
Posts: 116

Rep: Reputation: 35
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.
 
Old 07-17-2019, 04:27 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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.
 
Old 07-17-2019, 10:07 PM   #3
removed001
Member
 
Registered: Nov 2011
Location: Germany
Distribution: Puppy Linux (my own builds)
Posts: 116

Original Poster
Rep: Reputation: 35
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.
 
Old 07-18-2019, 07:15 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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.

Last edited by BW-userx; 07-18-2019 at 07:37 AM.
 
Old 07-18-2019, 02:10 PM   #5
removed001
Member
 
Registered: Nov 2011
Location: Germany
Distribution: Puppy Linux (my own builds)
Posts: 116

Original Poster
Rep: Reputation: 35
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...
 
Old 07-18-2019, 02:23 PM   #6
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by RSH View Post
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/

Last edited by BW-userx; 07-18-2019 at 02:25 PM.
 
Old 07-18-2019, 03:22 PM   #7
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,138

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
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
 
2 members found this post helpful.
Old 07-31-2019, 10:06 PM   #8
removed001
Member
 
Registered: Nov 2011
Location: Germany
Distribution: Puppy Linux (my own builds)
Posts: 116

Original Poster
Rep: Reputation: 35
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
future of programming, programming jobs, programming languages? detr Programming 17 08-01-2016 03:46 PM
which programming language is used to do tcp/ip programming?? gajaykrishnan Linux - Networking 9 12-21-2012 05:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration