I try to write kiosk web browser and run it automaticly after system boot. It's simple GTK2+ application, with WebKit used as browser.
It starts from ~/.xinitrc:
exec /home/kiosk-user/bin/browser 'http://localhost/'
Source code browser.c:
#include <stdio.h>
#include <signal.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <webkit/webkit.h>
int main( int argc, char* argv[] ) {
WebKitWebView* web_view;
GtkWidget* window;
GtkWidget* scrollable_content;
if( argc < 2 ) {
fprintf( stderr, "The first argument have to be URI" );
return 1;
}
gchar* uri = argv[1];
gtk_init( &argc, &argv );
gint
screen_width = gdk_screen_width(),
screen_height = gdk_screen_height();
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
scrollable_content = gtk_scrolled_window_new( NULL, NULL );
gtk_window_set_default_size( GTK_WINDOW( window ), screen_width, screen_height );
web_view = WEBKIT_WEB_VIEW( webkit_web_view_new() );
gtk_container_add( GTK_CONTAINER( scrollable_content ), GTK_WIDGET( web_view ) );
gtk_container_add( GTK_CONTAINER( window ), scrollable_content );
GdkCursor* cursor = gdk_cursor_new( GDK_ARROW );
gdk_window_set_cursor( window->window, cursor );
webkit_web_view_load_uri( web_view, uri );
gtk_widget_show_all( window );
gtk_main();
return 0;
}
The problem is cursor, it's not showing on application start, until I will click somewhere. When it will appear, it looks good on text input, links etc. but when I move from that kind of element, it changes appeariance to GDK_X_CURSOR(screenshot) instead of default arrow. Running it from desktop manager displays cursor properly.
On web page cursor is default.
Testing on: Virtual Machine => Debian GNU/Linux 8.1 (jessie)
Thank you in advance for your help and sorry if my English is not good enough.
You can find solution here. Just put xsetroot -cursor_name left_ptr in your ~/.xinitrc.
Related
I have downloaded the last version of espeak-ng from github, and did ./autogen.sh ./configure make make install.
so I wrote a test program as you can see below:
#include <string.h>
#include <vector>
#include </usr/local/include/espeak-ng/speak_lib.h>
int samplerate; // determined by espeak, will be in Hertz (Hz)
const int buflength = 200; // passed to espeak, in milliseconds (ms)
std::vector<short> sounddata;
int SynthCallback(short *wav, int numsamples, espeak_EVENT *events) {
if (wav == NULL)
return 1; // NULL means done.
/* process your samples here, let's just gather them */
sounddata.insert(sounddata.end(), wav, wav + numsamples);
return 0; // 0 continues synthesis, 1 aborts
}
int main(int argc, char* argv[] ) {
char text[] = {"my name is espeak"};
samplerate = espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, buflength, NULL, 0);
espeak_SetSynthCallback(&SynthCallback);
espeak_SetVoiceByName("en");
unsigned int flags=espeakCHARS_AUTO | espeakENDPAUSE;
size_t size = strlen(text);
espeak_Synth(text, size + 1, 0, POS_CHARACTER, 0, flags, NULL, NULL);
espeak_Synchronize();
/* in theory sounddata holds your samples now... */
return 0;
}
And compiled it by this command without any errors:
g++ -W -o speaks espeak.cpp -lespeak-ng
But when I try to run the executable by ./speaks , I get this error message:
./speaks: error while loading shared libraries: libespeak-ng.so.1: cannot open shared object file: No such file or directory
What's the problem?
I know libespeak-ng.so.1 is here: /usr/local/lib/libespeak-ng.so.1
I solved the problem by adding these two lines to my `/etc/environment' file:
LD_LIBRARY_PATH=/usr/local/lib
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
On Ubuntu 18.04 this is caused by setting the wrong path for the library.
You can fix it by:
sudo ln -s /usr/local/lib/libespeak-ng.so.1 /usr/lib/libespeak-ng.so.1
I am using PCL library to visualize a single .ply model. How can I print the Frames per Second (FPS) number shown on the bottom left of the window?
Here is my simple code. We only need to add something like cout<<print(current_fps);
#include <iostream>
//#include <unistd.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_cloud.h>
#include <pcl/console/parse.h>
#include <pcl/common/transforms.h>
#include <pcl/visualization/pcl_visualizer.h>
// Main function
int main(int argc, char **argv)
{
// Fetch point cloud filename in arguments | Works with PLY files
std::vector<int> filenames;
filenames = pcl::console::parse_file_extension_argument(argc, argv, ".ply");
// Load file | Works with PLY files
pcl::PointCloud<pcl::PointXYZRGB>::Ptr source_cloud (new pcl::PointCloud<pcl::PointXYZRGB>());
pcl::io::loadPLYFile(argv[filenames[0]], *source_cloud);
// Visualization
printf("\n Point cloud colors :\n"
" \t white \t = \t original point cloud \n");
pcl::visualization::PCLVisualizer viewer(" Point Cloud Datsets Visualizer");
viewer.setBackgroundColor(0.05, 0.05, 0.05, 0); // Set background to a dark grey
// Define R,G,B colors for the point cloud
pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(source_cloud);
// We add the point cloud to the viewer and pass the color handler
viewer.addPointCloud(source_cloud, rgb, "original_cloud");
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "original_cloud");
//******************************
std::vector<Point, Eigen::aligned_allocator<Point>> points = source_cloud->points;
//******************************
while (!viewer.wasStopped()) { // Display the visualizer until the 'q' key is pressed
viewer.spinOnce();
}
return 0;
} // End main()
You can use getFPS(). The issue was fixed in
https://github.com/PointCloudLibrary/pcl/pull/1974
Then you can do something like
std::cout<<viewer.getFPS();
Which will give you a floating point value with the current rendering framerate.
If I put the WNDCLASSEX wcex variable definition out of main function (as global variable) the class will be registered successfully
#include <windows.h>
WNDCLASSEX wcex;
int main()
{
wcex.cbSize = sizeof ( WNDCLASSEX );
wcex.lpszClassName = "Success" ;
if ( !RegisterClassEx ( &wcex ) )
{
MessageBox ( NULL, "Failed to register window class.", "Error", MB_OK );
}
}
But If I put it inside the main function, It will not be registered
#include <windows.h>
int main()
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof ( WNDCLASSEX );
wcex.lpszClassName = "Success" ;
if ( !RegisterClassEx ( &wcex ) )
{
MessageBox ( NULL, "Failed to register window class.", "Error", MB_OK );
}
}
I can't figure out the reason, kindly help in this issue.
Thanks in advance.
Objects with static storage duration are zero-initialized1). Your second example is semantically different in that wcex (automatic storage duration) holds random values. To match the semantics, use WNDCLASSEX wcex = { 0 }; instead.
1) Assuming you are using a C++ compiler. The rules for C are different.
I have just begun programming for KDE, the problem I face is I don't know what exactly should be the pro file for a KDE project, I have an idea for cmake though
I also tried in pro file:
LIBS += -lkdeui
I still get problem KApplication not found
Code main.cpp:
#include <cstdlib>
#include <KApplication>
#include <KAboutData>
#include <KCmdLineArgs>
#include <KMessageBox>
#include <KLocale>
int main (int argc, char *argv[])
{
KAboutData aboutData("tutorial1",0,ki18n("Tutorial 1"),"1.0",ki18n("Displays a KMessageBox popup"),KAboutData::License_GPL,ki18n("(c) 2007"),ki18n("Some text..."),"http://example.com/","submit#bugs.kde.org");
KCmdLineArgs::init( argc, argv, &aboutData );
KApplication app;
KGuiItem yesButton( i18n( "Hello" ), QString(),
i18n( "This is a tooltip" ),
i18n( "This is a WhatsThis help text." ) );
return
KMessageBox ::questionYesNo
(0, i18n( "Hello World" ), i18n( "Hello" ), yesButton )
== KMessageBox ::Yes? EXIT_SUCCESS: EXIT_FAILURE;
}
and tutorial.pro file is:
TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp
LIBS += -lkdeui
You need to install development files for kde libraries, these are missing. I don't know which Linux distro you are using (if any) but, for example, in Debian the required package is called kdelibs5-dev.
You will probably also need to specify the include path for these development files after installing the package. Like INCLUDEPATH += /usr/include/KDE
I'm looking for a programatic way to find the powerpc cpu type on Linux. Performing some google searches associated an answer suggesting the mfpvr instruction I found that this is available in the ELF AUX header, and sure enough I can obtain the POWER5 string for the machine I'm running on with the following:
#include <stdio.h>
#include <elf.h>
int main( int argc, char **argv, char **envp )
{
/* walk past all env pointers */
while ( *envp++ != NULL )
;
/* and find ELF auxiliary vectors (if this was an ELF binary) */
#if 0
Elf32_auxv_t * auxv = (Elf32_auxv_t *) envp ;
#else
Elf64_auxv_t * auxv = (Elf64_auxv_t *) envp ;
#endif
char * platform = NULL ;
for ( ; auxv->a_type != AT_NULL ; auxv++ )
{
if ( auxv->a_type == AT_PLATFORM )
{
platform = (char *)auxv->a_un.a_val ;
break;
}
}
if ( platform )
{
printf( "%s\n", platform ) ;
}
return 0 ;
}
In the shared library context where I want to use this info I have no access to envp. Is there an alternate programatic method to find the beginning of the ELF AUX header?
You can get if from /proc/self/auxv file
According to man proc /proc/self/auxv is available since kernel level 2.6.0-test7.
Another option - get some (existing) environment variable - let say HOME,
or PATH, or whatever. Please note that you'll get it's ADDRESS. From here you can go back and find previous env variable, then one before it, etc. After that you can likewise skip all argv arguments. And then you get to the last AUXV entry. Some steps back - and you should be able find your AT_PLATFORM.
EDIT: It looks like glibc now provides a programatic method to get at this info:
glibc-headers-2.17-106: /usr/include/sys/auxv.h : getauxinfo()
Example:
#include <sys/auxv.h>
#include <stdio.h>
int main()
{
unsigned long v = getauxval( AT_PLATFORM ) ;
printf( "%s\n", (char *)v ) ;
return 0 ;
}